about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMax Baumann <max@bmn.dev>2022-03-19 18:17:43 +0100
committerMax Baumann <max@bmn.dev>2022-03-19 18:17:43 +0100
commit20c352a4f602d541920fe1745b117fc8b42ca8fc (patch)
tree806f495909c8a46b75ca9a4256a09c29b2102ed0
parent895de1f13e78de456d5ecbdca3c87526c4dbbef2 (diff)
downloadrust-20c352a4f602d541920fe1745b117fc8b42ca8fc.tar.gz
rust-20c352a4f602d541920fe1745b117fc8b42ca8fc.zip
test: add method chain test
-rw-r--r--tests/ui/or_then_unwrap.fixed4
-rw-r--r--tests/ui/or_then_unwrap.rs4
-rw-r--r--tests/ui/or_then_unwrap.stderr8
3 files changed, 15 insertions, 1 deletions
diff --git a/tests/ui/or_then_unwrap.fixed b/tests/ui/or_then_unwrap.fixed
index b1e69ce2d26..27d4b795a5e 100644
--- a/tests/ui/or_then_unwrap.fixed
+++ b/tests/ui/or_then_unwrap.fixed
@@ -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
diff --git a/tests/ui/or_then_unwrap.rs b/tests/ui/or_then_unwrap.rs
index dc66e86be6f..0dab5ae2f1c 100644
--- a/tests/ui/or_then_unwrap.rs
+++ b/tests/ui/or_then_unwrap.rs
@@ -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
diff --git a/tests/ui/or_then_unwrap.stderr b/tests/ui/or_then_unwrap.stderr
index 301a54530cf..6b32634defd 100644
--- a/tests/ui/or_then_unwrap.stderr
+++ b/tests/ui/or_then_unwrap.stderr
@@ -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