about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authortamaron <tamaron1203@gmail.com>2022-08-11 12:00:46 +0900
committertamaron <tamaron1203@gmail.com>2022-08-11 15:07:39 +0900
commit45084eeefb4edb981ce437c7fee6a07e61ff224b (patch)
tree407d832b48e0e30ab9087885ca0b80c21d82071f /tests
parent459821b1914248180cac691128dd35d945bfde88 (diff)
downloadrust-45084eeefb4edb981ce437c7fee6a07e61ff224b.tar.gz
rust-45084eeefb4edb981ce437c7fee6a07e61ff224b.zip
give up when gurad has side effects
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/needless_match.fixed15
-rw-r--r--tests/ui/needless_match.rs15
2 files changed, 28 insertions, 2 deletions
diff --git a/tests/ui/needless_match.fixed b/tests/ui/needless_match.fixed
index 9d4427f1df2..7e47406798c 100644
--- a/tests/ui/needless_match.fixed
+++ b/tests/ui/needless_match.fixed
@@ -209,7 +209,7 @@ impl Tr for Result<i32, i32> {
 
 mod issue9084 {
     fn wildcard_if() {
-        let some_bool = true;
+        let mut some_bool = true;
         let e = Some(1);
 
         // should lint
@@ -230,6 +230,19 @@ mod issue9084 {
             _ if some_bool => e,
             _ => e,
         };
+
+        // should not lint (guard has side effects)
+        let _ = match e {
+            Some(i) => Some(i),
+            _ if {
+                some_bool = false;
+                some_bool
+            } =>
+            {
+                e
+            },
+            _ => e,
+        };
     }
 }
 
diff --git a/tests/ui/needless_match.rs b/tests/ui/needless_match.rs
index cae850fb059..809c694bf40 100644
--- a/tests/ui/needless_match.rs
+++ b/tests/ui/needless_match.rs
@@ -246,7 +246,7 @@ impl Tr for Result<i32, i32> {
 
 mod issue9084 {
     fn wildcard_if() {
-        let some_bool = true;
+        let mut some_bool = true;
         let e = Some(1);
 
         // should lint
@@ -274,6 +274,19 @@ mod issue9084 {
             _ if some_bool => e,
             _ => e,
         };
+
+        // should not lint (guard has side effects)
+        let _ = match e {
+            Some(i) => Some(i),
+            _ if {
+                some_bool = false;
+                some_bool
+            } =>
+            {
+                e
+            },
+            _ => e,
+        };
     }
 }