about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/methods/or_fun_call.rs4
-rw-r--r--tests/ui/or_fun_call.fixed6
-rw-r--r--tests/ui/or_fun_call.rs2
-rw-r--r--tests/ui/or_fun_call.stderr14
4 files changed, 22 insertions, 4 deletions
diff --git a/clippy_lints/src/methods/or_fun_call.rs b/clippy_lints/src/methods/or_fun_call.rs
index 2139466ce74..6ce7dd3d4d0 100644
--- a/clippy_lints/src/methods/or_fun_call.rs
+++ b/clippy_lints/src/methods/or_fun_call.rs
@@ -136,7 +136,7 @@ pub(super) fn check<'tcx>(
         fun_span: Option<Span>,
     ) -> bool {
         // (path, fn_has_argument, methods, suffix)
-        const KNOW_TYPES: [(Symbol, bool, &[Symbol], &str); 5] = [
+        const KNOW_TYPES: [(Symbol, bool, &[Symbol], &str); 7] = [
             (sym::BTreeEntry, false, &[sym::or_insert], "with"),
             (sym::HashMapEntry, false, &[sym::or_insert], "with"),
             (
@@ -146,7 +146,9 @@ pub(super) fn check<'tcx>(
                 "else",
             ),
             (sym::Option, false, &[sym::get_or_insert], "with"),
+            (sym::Option, true, &[sym::and], "then"),
             (sym::Result, true, &[sym::map_or, sym::or, sym::unwrap_or], "else"),
+            (sym::Result, true, &[sym::and], "then"),
         ];
 
         if KNOW_TYPES.iter().any(|k| k.2.contains(&name))
diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed
index bb46ce04466..bcd2602edb6 100644
--- a/tests/ui/or_fun_call.fixed
+++ b/tests/ui/or_fun_call.fixed
@@ -445,7 +445,8 @@ fn test_option_and() {
         Some(99)
     }
     let mut x = Some(42_u8);
-    let _ = x.and(g());
+    let _ = x.and_then(|_| g());
+    //~^ or_fun_call
 }
 
 fn test_result_and() {
@@ -454,7 +455,8 @@ fn test_result_and() {
         Ok(99)
     }
     let mut x: Result<u8, ()> = Ok(42);
-    let _ = x.and(g());
+    let _ = x.and_then(|_| g());
+    //~^ or_fun_call
 }
 
 fn main() {}
diff --git a/tests/ui/or_fun_call.rs b/tests/ui/or_fun_call.rs
index 68ef244a019..8d1202ebf91 100644
--- a/tests/ui/or_fun_call.rs
+++ b/tests/ui/or_fun_call.rs
@@ -446,6 +446,7 @@ fn test_option_and() {
     }
     let mut x = Some(42_u8);
     let _ = x.and(g());
+    //~^ or_fun_call
 }
 
 fn test_result_and() {
@@ -455,6 +456,7 @@ fn test_result_and() {
     }
     let mut x: Result<u8, ()> = Ok(42);
     let _ = x.and(g());
+    //~^ or_fun_call
 }
 
 fn main() {}
diff --git a/tests/ui/or_fun_call.stderr b/tests/ui/or_fun_call.stderr
index 0f159fe8bff..585ee2d0e19 100644
--- a/tests/ui/or_fun_call.stderr
+++ b/tests/ui/or_fun_call.stderr
@@ -264,5 +264,17 @@ error: function call inside of `get_or_insert`
 LL |     let _ = x.get_or_insert(g());
    |               ^^^^^^^^^^^^^^^^^^ help: try: `get_or_insert_with(g)`
 
-error: aborting due to 41 previous errors
+error: function call inside of `and`
+  --> tests/ui/or_fun_call.rs:448:15
+   |
+LL |     let _ = x.and(g());
+   |               ^^^^^^^^ help: try: `and_then(|_| g())`
+
+error: function call inside of `and`
+  --> tests/ui/or_fun_call.rs:458:15
+   |
+LL |     let _ = x.and(g());
+   |               ^^^^^^^^ help: try: `and_then(|_| g())`
+
+error: aborting due to 43 previous errors