test: add method chain test
This commit is contained in:
parent
895de1f13e
commit
20c352a4f6
@ -26,6 +26,10 @@ fn main() {
|
||||
let result: Result<&str, &str> = Err("Error");
|
||||
let _ = result.unwrap_or("fallback"); // should trigger lint
|
||||
|
||||
// as part of a method chain
|
||||
let option: Option<&str> = None;
|
||||
let _ = option.map(|v| v).unwrap_or("fallback").to_string().chars(); // should trigger lint
|
||||
|
||||
// Not Option/Result
|
||||
let instance = SomeStruct {};
|
||||
let _ = instance.or(Some(SomeStruct {})).unwrap(); // should not trigger lint
|
||||
|
@ -26,6 +26,10 @@ fn main() {
|
||||
let result: Result<&str, &str> = Err("Error");
|
||||
let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint
|
||||
|
||||
// as part of a method chain
|
||||
let option: Option<&str> = None;
|
||||
let _ = option.map(|v| v).or(Some("fallback")).unwrap().to_string().chars(); // should trigger lint
|
||||
|
||||
// Not Option/Result
|
||||
let instance = SomeStruct {};
|
||||
let _ = instance.or(Some(SomeStruct {})).unwrap(); // should not trigger lint
|
||||
|
@ -12,5 +12,11 @@ error: .or(Ok(…)).unwrap() found
|
||||
LL | let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or("fallback")`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: .or(Some(…)).unwrap() found
|
||||
--> $DIR/or_then_unwrap.rs:31:31
|
||||
|
|
||||
LL | let _ = option.map(|v| v).or(Some("fallback")).unwrap().to_string().chars(); // should trigger lint
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or("fallback")`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user