]> git.lizzy.rs Git - rust.git/blob - tests/ui/option_option.rs
Add non_octal_unix_permissions lint
[rust.git] / tests / ui / option_option.rs
1 #![deny(clippy::option_option)]
2 #![allow(clippy::unnecessary_wraps)]
3
4 fn input(_: Option<Option<u8>>) {}
5
6 fn output() -> Option<Option<u8>> {
7     None
8 }
9
10 fn output_nested() -> Vec<Option<Option<u8>>> {
11     vec![None]
12 }
13
14 // The lint only generates one warning for this
15 fn output_nested_nested() -> Option<Option<Option<u8>>> {
16     None
17 }
18
19 struct Struct {
20     x: Option<Option<u8>>,
21 }
22
23 impl Struct {
24     fn struct_fn() -> Option<Option<u8>> {
25         None
26     }
27 }
28
29 trait Trait {
30     fn trait_fn() -> Option<Option<u8>>;
31 }
32
33 enum Enum {
34     Tuple(Option<Option<u8>>),
35     Struct { x: Option<Option<u8>> },
36 }
37
38 // The lint allows this
39 type OptionOption = Option<Option<u32>>;
40
41 // The lint allows this
42 fn output_type_alias() -> OptionOption {
43     None
44 }
45
46 // The line allows this
47 impl Trait for Struct {
48     fn trait_fn() -> Option<Option<u8>> {
49         None
50     }
51 }
52
53 fn main() {
54     input(None);
55     output();
56     output_nested();
57
58     // The lint allows this
59     let local: Option<Option<u8>> = None;
60
61     // The lint allows this
62     let expr = Some(Some(true));
63 }
64
65 extern crate serde;
66 mod issue_4298 {
67     use serde::{Deserialize, Deserializer, Serialize};
68     use std::borrow::Cow;
69
70     #[derive(Serialize, Deserialize)]
71     struct Foo<'a> {
72         #[serde(deserialize_with = "func")]
73         #[serde(skip_serializing_if = "Option::is_none")]
74         #[serde(default)]
75         #[serde(borrow)]
76         foo: Option<Option<Cow<'a, str>>>,
77     }
78
79     #[allow(clippy::option_option)]
80     fn func<'a, D>(_: D) -> Result<Option<Option<Cow<'a, str>>>, D::Error>
81     where
82         D: Deserializer<'a>,
83     {
84         Ok(Some(Some(Cow::Borrowed("hi"))))
85     }
86 }