File tree Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ fn main() {
26
26
let result: Result<&str, &str> = Err("Error");
27
27
let _ = result.unwrap_or("fallback"); // should trigger lint
28
28
29
+ // as part of a method chain
30
+ let option: Option<&str> = None;
31
+ let _ = option.map(|v| v).unwrap_or("fallback").to_string().chars(); // should trigger lint
32
+
29
33
// Not Option/Result
30
34
let instance = SomeStruct {};
31
35
let _ = instance.or(Some(SomeStruct {})).unwrap(); // should not trigger lint
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ fn main() {
26
26
let result: Result < & str , & str > = Err ( "Error" ) ;
27
27
let _ = result. or :: < & str > ( Ok ( "fallback" ) ) . unwrap ( ) ; // should trigger lint
28
28
29
+ // as part of a method chain
30
+ let option: Option < & str > = None ;
31
+ let _ = option. map ( |v| v) . or ( Some ( "fallback" ) ) . unwrap ( ) . to_string ( ) . chars ( ) ; // should trigger lint
32
+
29
33
// Not Option/Result
30
34
let instance = SomeStruct { } ;
31
35
let _ = instance. or ( Some ( SomeStruct { } ) ) . unwrap ( ) ; // should not trigger lint
Original file line number Diff line number Diff line change @@ -12,5 +12,11 @@ error: .or(Ok(…)).unwrap() found
12
12
LL | let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint
13
13
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or("fallback")`
14
14
15
- error: aborting due to 2 previous errors
15
+ error: .or(Some(…)).unwrap() found
16
+ --> $DIR/or_then_unwrap.rs:31:31
17
+ |
18
+ LL | let _ = option.map(|v| v).or(Some("fallback")).unwrap().to_string().chars(); // should trigger lint
19
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or("fallback")`
20
+
21
+ error: aborting due to 3 previous errors
16
22
You can’t perform that action at this time.
0 commit comments