test: add method chain test

This commit is contained in:
Max Baumann 2022-03-19 18:17:43 +01:00
parent 895de1f13e
commit 20c352a4f6
No known key found for this signature in database
GPG key ID: 20FA1609B03B1D6D
3 changed files with 15 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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