]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/option_option.txt
Auto merge of #102529 - colinba:master, r=joshtriplett
[rust.git] / src / tools / clippy / src / docs / option_option.txt
1 ### What it does
2 Checks for use of `Option<Option<_>>` in function signatures and type
3 definitions
4
5 ### Why is this bad?
6 `Option<_>` represents an optional value. `Option<Option<_>>`
7 represents an optional optional value which is logically the same thing as an optional
8 value but has an unneeded extra level of wrapping.
9
10 If you have a case where `Some(Some(_))`, `Some(None)` and `None` are distinct cases,
11 consider a custom `enum` instead, with clear names for each case.
12
13 ### Example
14 ```
15 fn get_data() -> Option<Option<u32>> {
16     None
17 }
18 ```
19
20 Better:
21
22 ```
23 pub enum Contents {
24     Data(Vec<u8>), // Was Some(Some(Vec<u8>))
25     NotYetFetched, // Was Some(None)
26     None,          // Was None
27 }
28
29 fn get_data() -> Contents {
30     Contents::None
31 }
32 ```