about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorllogiq <bogusandre@gmail.com>2025-07-06 15:31:13 +0000
committerGitHub <noreply@github.com>2025-07-06 15:31:13 +0000
commitc943f4c0e97e808a7f1577f68361c6e24e6ead5d (patch)
treef1ae63e10ff9f8c981f0483b31bee1c9e17c8a65 /tests
parentcc7b2f57e0b6b134c1881f17c6db83635ad5fe67 (diff)
parenta82c142f3e0be8f88e588a18bf897899d30f179d (diff)
downloadrust-c943f4c0e97e808a7f1577f68361c6e24e6ead5d.tar.gz
rust-c943f4c0e97e808a7f1577f68361c6e24e6ead5d.zip
or_fun_call: also lint `and` method for Option/Result (#15073)
<strike>build on top of rust-lang/rust-clippy#15071</strike>

This also adds ability to lint Option/Result::and method. Yes, this is
not `or` method, but uses the same eager/lazy linting logic. Should i
update lint description to list all checked structs/methods?

changelog: [`or_fun_call`]: lint Option/Result::and
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/or_fun_call.fixed20
-rw-r--r--tests/ui/or_fun_call.rs20
-rw-r--r--tests/ui/or_fun_call.stderr14
3 files changed, 53 insertions, 1 deletions
diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed
index 34f3e046841..bcd2602edb6 100644
--- a/tests/ui/or_fun_call.fixed
+++ b/tests/ui/or_fun_call.fixed
@@ -439,4 +439,24 @@ fn test_option_get_or_insert() {
     //~^ or_fun_call
 }
 
+fn test_option_and() {
+    // assume that this is slow call
+    fn g() -> Option<u8> {
+        Some(99)
+    }
+    let mut x = Some(42_u8);
+    let _ = x.and_then(|_| g());
+    //~^ or_fun_call
+}
+
+fn test_result_and() {
+    // assume that this is slow call
+    fn g() -> Result<u8, ()> {
+        Ok(99)
+    }
+    let mut x: Result<u8, ()> = Ok(42);
+    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 dc57bd6060a..8d1202ebf91 100644
--- a/tests/ui/or_fun_call.rs
+++ b/tests/ui/or_fun_call.rs
@@ -439,4 +439,24 @@ fn test_option_get_or_insert() {
     //~^ or_fun_call
 }
 
+fn test_option_and() {
+    // assume that this is slow call
+    fn g() -> Option<u8> {
+        Some(99)
+    }
+    let mut x = Some(42_u8);
+    let _ = x.and(g());
+    //~^ or_fun_call
+}
+
+fn test_result_and() {
+    // assume that this is slow call
+    fn g() -> Result<u8, ()> {
+        Ok(99)
+    }
+    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