]> git.lizzy.rs Git - rust.git/blob - tests/ui/option_option.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / option_option.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 fn input(_: Option<Option<u8>>) {}
11
12 fn output() -> Option<Option<u8>> {
13     None
14 }
15
16 fn output_nested() -> Vec<Option<Option<u8>>> {
17     vec![None]
18 }
19
20 // The lint only generates one warning for this
21 fn output_nested_nested() -> Option<Option<Option<u8>>> {
22     None
23 }
24
25 struct Struct {
26     x: Option<Option<u8>>,
27 }
28
29 impl Struct {
30     fn struct_fn() -> Option<Option<u8>> {
31         None
32     }
33 }
34
35 trait Trait {
36     fn trait_fn() -> Option<Option<u8>>;
37 }
38
39 enum Enum {
40     Tuple(Option<Option<u8>>),
41     Struct { x: Option<Option<u8>> },
42 }
43
44 // The lint allows this
45 type OptionOption = Option<Option<u32>>;
46
47 // The lint allows this
48 fn output_type_alias() -> OptionOption {
49     None
50 }
51
52 // The line allows this
53 impl Trait for Struct {
54     fn trait_fn() -> Option<Option<u8>> {
55         None
56     }
57 }
58
59 fn main() {
60     input(None);
61     output();
62     output_nested();
63
64     // The lint allows this
65     let local: Option<Option<u8>> = None;
66
67     // The lint allows this
68     let expr = Some(Some(true));
69 }