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() {
2626 let result: Result<&str, &str> = Err("Error");
2727 let _ = result.unwrap_or("fallback"); // should trigger lint
2828
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+
2933 // Not Option/Result
3034 let instance = SomeStruct {};
3135 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() {
2626 let result: Result < & str , & str > = Err ( "Error" ) ;
2727 let _ = result. or :: < & str > ( Ok ( "fallback" ) ) . unwrap ( ) ; // should trigger lint
2828
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+
2933 // Not Option/Result
3034 let instance = SomeStruct { } ;
3135 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
1212LL | let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint
1313 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or("fallback")`
1414
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
1622
You can’t perform that action at this time.
0 commit comments