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