Skip to content

Commit 20c352a

Browse files
committed
test: add method chain test
1 parent 895de1f commit 20c352a

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

tests/ui/or_then_unwrap.fixed

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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

tests/ui/or_then_unwrap.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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

tests/ui/or_then_unwrap.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@ error: .or(Ok(…)).unwrap() found
1212
LL | 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

0 commit comments

Comments
 (0)