Skip to content

Commit 42796e1

Browse files
committed
Auto merge of #5401 - dtolnay:option, r=Manishearth
Downgrade option_option to pedantic Based on a search of my work codebase (\>500k lines) for `Option<Option<`, it looks like a bunch of reasonable uses to me. The documented motivation for this lint is: > an optional optional value is logically the same thing as an optional value but has an unneeded extra level of wrapping which seems a bit bogus in practice. For example a typical usage would look like: ```rust let mut host: Option<String> = None; let mut port: Option<i32> = None; let mut payload: Option<Option<String>> = None; for each field { match field.name { "host" => host = Some(...), "port" => port = Some(...), "payload" => payload = Some(...), // can be null or string _ => return error, } } let host = host.ok_or(...)?; let port = port.ok_or(...)?; let payload = payload.ok_or(...)?; do_thing(host, port, payload) ``` This lint seems to fit right in with the pedantic group; I don't think linting on occurrences of `Option<Option<T>>` by default is justified. --- changelog: Remove option_option from default set of enabled lints
2 parents 326b220 + f6e8da8 commit 42796e1

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

clippy_lints/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11251125
LintId::of(&types::CAST_SIGN_LOSS),
11261126
LintId::of(&types::INVALID_UPCAST_COMPARISONS),
11271127
LintId::of(&types::LINKEDLIST),
1128+
LintId::of(&types::OPTION_OPTION),
11281129
LintId::of(&unicode::NON_ASCII_LITERAL),
11291130
LintId::of(&unicode::UNICODE_NOT_NFC),
11301131
LintId::of(&unused_self::UNUSED_SELF),
@@ -1375,7 +1376,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13751376
LintId::of(&types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION),
13761377
LintId::of(&types::IMPLICIT_HASHER),
13771378
LintId::of(&types::LET_UNIT_VALUE),
1378-
LintId::of(&types::OPTION_OPTION),
13791379
LintId::of(&types::TYPE_COMPLEXITY),
13801380
LintId::of(&types::UNIT_ARG),
13811381
LintId::of(&types::UNIT_CMP),
@@ -1565,7 +1565,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15651565
LintId::of(&transmute::TRANSMUTE_PTR_TO_REF),
15661566
LintId::of(&types::BORROWED_BOX),
15671567
LintId::of(&types::CHAR_LIT_AS_U8),
1568-
LintId::of(&types::OPTION_OPTION),
15691568
LintId::of(&types::TYPE_COMPLEXITY),
15701569
LintId::of(&types::UNIT_ARG),
15711570
LintId::of(&types::UNNECESSARY_CAST),

clippy_lints/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ declare_clippy_lint! {
108108
/// }
109109
/// ```
110110
pub OPTION_OPTION,
111-
complexity,
111+
pedantic,
112112
"usage of `Option<Option<T>>`"
113113
}
114114

src/lintlist/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
15661566
},
15671567
Lint {
15681568
name: "option_option",
1569-
group: "complexity",
1569+
group: "pedantic",
15701570
desc: "usage of `Option<Option<T>>`",
15711571
deprecation: None,
15721572
module: "types",

tests/ui/option_option.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(clippy::option_option)]
2+
13
fn input(_: Option<Option<u8>>) {}
24

35
fn output() -> Option<Option<u8>> {

tests/ui/option_option.stderr

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,59 @@
11
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
2-
--> $DIR/option_option.rs:1:13
2+
--> $DIR/option_option.rs:3:13
33
|
44
LL | fn input(_: Option<Option<u8>>) {}
55
| ^^^^^^^^^^^^^^^^^^
66
|
7-
= note: `-D clippy::option-option` implied by `-D warnings`
7+
note: the lint level is defined here
8+
--> $DIR/option_option.rs:1:9
9+
|
10+
LL | #![deny(clippy::option_option)]
11+
| ^^^^^^^^^^^^^^^^^^^^^
812

913
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
10-
--> $DIR/option_option.rs:3:16
14+
--> $DIR/option_option.rs:5:16
1115
|
1216
LL | fn output() -> Option<Option<u8>> {
1317
| ^^^^^^^^^^^^^^^^^^
1418

1519
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
16-
--> $DIR/option_option.rs:7:27
20+
--> $DIR/option_option.rs:9:27
1721
|
1822
LL | fn output_nested() -> Vec<Option<Option<u8>>> {
1923
| ^^^^^^^^^^^^^^^^^^
2024

2125
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
22-
--> $DIR/option_option.rs:12:30
26+
--> $DIR/option_option.rs:14:30
2327
|
2428
LL | fn output_nested_nested() -> Option<Option<Option<u8>>> {
2529
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
2630

2731
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
28-
--> $DIR/option_option.rs:17:8
32+
--> $DIR/option_option.rs:19:8
2933
|
3034
LL | x: Option<Option<u8>>,
3135
| ^^^^^^^^^^^^^^^^^^
3236

3337
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
34-
--> $DIR/option_option.rs:21:23
38+
--> $DIR/option_option.rs:23:23
3539
|
3640
LL | fn struct_fn() -> Option<Option<u8>> {
3741
| ^^^^^^^^^^^^^^^^^^
3842

3943
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
40-
--> $DIR/option_option.rs:27:22
44+
--> $DIR/option_option.rs:29:22
4145
|
4246
LL | fn trait_fn() -> Option<Option<u8>>;
4347
| ^^^^^^^^^^^^^^^^^^
4448

4549
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
46-
--> $DIR/option_option.rs:31:11
50+
--> $DIR/option_option.rs:33:11
4751
|
4852
LL | Tuple(Option<Option<u8>>),
4953
| ^^^^^^^^^^^^^^^^^^
5054

5155
error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
52-
--> $DIR/option_option.rs:32:17
56+
--> $DIR/option_option.rs:34:17
5357
|
5458
LL | Struct { x: Option<Option<u8>> },
5559
| ^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)