]> git.lizzy.rs Git - rust.git/blob - tests/ui/option_option.rs
Merge remote-tracking branch 'upstream/master' into clippy-fix
[rust.git] / tests / ui / option_option.rs
1 #![deny(clippy::option_option)]
2
3 fn input(_: Option<Option<u8>>) {}
4
5 fn output() -> Option<Option<u8>> {
6     None
7 }
8
9 fn output_nested() -> Vec<Option<Option<u8>>> {
10     vec![None]
11 }
12
13 // The lint only generates one warning for this
14 fn output_nested_nested() -> Option<Option<Option<u8>>> {
15     None
16 }
17
18 struct Struct {
19     x: Option<Option<u8>>,
20 }
21
22 impl Struct {
23     fn struct_fn() -> Option<Option<u8>> {
24         None
25     }
26 }
27
28 trait Trait {
29     fn trait_fn() -> Option<Option<u8>>;
30 }
31
32 enum Enum {
33     Tuple(Option<Option<u8>>),
34     Struct { x: Option<Option<u8>> },
35 }
36
37 // The lint allows this
38 type OptionOption = Option<Option<u32>>;
39
40 // The lint allows this
41 fn output_type_alias() -> OptionOption {
42     None
43 }
44
45 // The line allows this
46 impl Trait for Struct {
47     fn trait_fn() -> Option<Option<u8>> {
48         None
49     }
50 }
51
52 fn main() {
53     input(None);
54     output();
55     output_nested();
56
57     // The lint allows this
58     let local: Option<Option<u8>> = None;
59
60     // The lint allows this
61     let expr = Some(Some(true));
62 }