File tree 1 file changed +20
-2
lines changed 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -99,14 +99,32 @@ declare_clippy_lint! {
99
99
/// represents an optional optional value which is logically the same thing as an optional
100
100
/// value but has an unneeded extra level of wrapping.
101
101
///
102
+ /// If you have a case where `Some(Some(_))`, `Some(None)` and `None` are distinct cases,
103
+ /// consider a custom `enum` instead, with clear names for each case.
104
+ ///
102
105
/// **Known problems:** None.
103
106
///
104
107
/// **Example**
105
- /// ```rust
106
- /// fn x( ) -> Option<Option<u32>> {
108
+ /// ```rust,ignore
109
+ /// fn get_node_data(n: Node ) -> Option<Option<u32>> {
107
110
/// None
108
111
/// }
109
112
/// ```
113
+ ///
114
+ /// Better:
115
+ ///
116
+ /// ```rust,ignore
117
+ /// pub enum Contents {
118
+ /// Data(Vec<u8>), // Was Some(Some(Vec<u8>))
119
+ /// NotYetFetched, // Was Some(None)
120
+ /// None, // Was None
121
+ /// }
122
+ ///
123
+ /// fn get_node_data(n: Node) -> Contents {
124
+ /// Contents::None
125
+ /// }
126
+ /// ```
127
+ ///
110
128
pub OPTION_OPTION ,
111
129
pedantic,
112
130
"usage of `Option<Option<T>>`"
You can’t perform that action at this time.
0 commit comments