about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2025-04-13 10:10:48 +0200
committerSamuel Tardieu <sam@rfc1149.net>2025-04-15 20:33:01 +0200
commit67d5056f03bb1c8359bd16a2a6d6f26fbcd30e3a (patch)
treec50468567ba488c0d0ed9a4c11bed4b53c0e311c
parentb3d401ecb1a0feaa9921c2ea012624d6350b8000 (diff)
downloadrust-67d5056f03bb1c8359bd16a2a6d6f26fbcd30e3a.tar.gz
rust-67d5056f03bb1c8359bd16a2a6d6f26fbcd30e3a.zip
Add `blocks_in_conditions` edition 2021 specific tests
The borrowing rules in Rust 2024 prevented those tests from compiling.
-rw-r--r--tests/ui/blocks_in_conditions.fixed29
-rw-r--r--tests/ui/blocks_in_conditions.rs29
-rw-r--r--tests/ui/blocks_in_conditions.stderr27
-rw-r--r--tests/ui/blocks_in_conditions_2021.fixed25
-rw-r--r--tests/ui/blocks_in_conditions_2021.rs25
-rw-r--r--tests/ui/blocks_in_conditions_2021.stderr23
6 files changed, 79 insertions, 79 deletions
diff --git a/tests/ui/blocks_in_conditions.fixed b/tests/ui/blocks_in_conditions.fixed
index cd307e803d0..c82276b358e 100644
--- a/tests/ui/blocks_in_conditions.fixed
+++ b/tests/ui/blocks_in_conditions.fixed
@@ -1,12 +1,7 @@
 //@aux-build:proc_macro_attr.rs
 
 #![warn(clippy::blocks_in_conditions)]
-#![allow(
-    unused,
-    clippy::let_and_return,
-    clippy::needless_if,
-    clippy::missing_transmute_annotations
-)]
+#![allow(unused, clippy::needless_if, clippy::missing_transmute_annotations)]
 #![warn(clippy::nonminimal_bool)]
 
 macro_rules! blocky {
@@ -71,28 +66,6 @@ fn block_in_assert() {
     );
 }
 
-// issue #11814
-fn block_in_match_expr(num: i32) -> i32 {
-    let res = {
-        //~^ ERROR: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
-        let opt = Some(2);
-        opt
-    }; match res {
-        Some(0) => 1,
-        Some(n) => num * 2,
-        None => 0,
-    };
-
-    match unsafe {
-        let hearty_hearty_hearty = vec![240, 159, 146, 150];
-        String::from_utf8_unchecked(hearty_hearty_hearty).as_str()
-    } {
-        "💖" => 1,
-        "what" => 2,
-        _ => 3,
-    }
-}
-
 // issue #12162
 macro_rules! timed {
     ($name:expr, $body:expr $(,)?) => {{
diff --git a/tests/ui/blocks_in_conditions.rs b/tests/ui/blocks_in_conditions.rs
index 6a211c8edfd..6a4a7c62106 100644
--- a/tests/ui/blocks_in_conditions.rs
+++ b/tests/ui/blocks_in_conditions.rs
@@ -1,12 +1,7 @@
 //@aux-build:proc_macro_attr.rs
 
 #![warn(clippy::blocks_in_conditions)]
-#![allow(
-    unused,
-    clippy::let_and_return,
-    clippy::needless_if,
-    clippy::missing_transmute_annotations
-)]
+#![allow(unused, clippy::needless_if, clippy::missing_transmute_annotations)]
 #![warn(clippy::nonminimal_bool)]
 
 macro_rules! blocky {
@@ -71,28 +66,6 @@ fn block_in_assert() {
     );
 }
 
-// issue #11814
-fn block_in_match_expr(num: i32) -> i32 {
-    match {
-        //~^ ERROR: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
-        let opt = Some(2);
-        opt
-    } {
-        Some(0) => 1,
-        Some(n) => num * 2,
-        None => 0,
-    };
-
-    match unsafe {
-        let hearty_hearty_hearty = vec![240, 159, 146, 150];
-        String::from_utf8_unchecked(hearty_hearty_hearty).as_str()
-    } {
-        "💖" => 1,
-        "what" => 2,
-        _ => 3,
-    }
-}
-
 // issue #12162
 macro_rules! timed {
     ($name:expr, $body:expr $(,)?) => {{
diff --git a/tests/ui/blocks_in_conditions.stderr b/tests/ui/blocks_in_conditions.stderr
index da21344a842..e57eca5dcee 100644
--- a/tests/ui/blocks_in_conditions.stderr
+++ b/tests/ui/blocks_in_conditions.stderr
@@ -1,5 +1,5 @@
 error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
-  --> tests/ui/blocks_in_conditions.rs:30:5
+  --> tests/ui/blocks_in_conditions.rs:25:5
    |
 LL | /     if {
 LL | |
@@ -20,13 +20,13 @@ LL ~     }; if res {
    |
 
 error: omit braces around single expression condition
-  --> tests/ui/blocks_in_conditions.rs:42:8
+  --> tests/ui/blocks_in_conditions.rs:37:8
    |
 LL |     if { true } { 6 } else { 10 }
    |        ^^^^^^^^ help: try: `true`
 
 error: this boolean expression can be simplified
-  --> tests/ui/blocks_in_conditions.rs:48:8
+  --> tests/ui/blocks_in_conditions.rs:43:8
    |
 LL |     if true && x == 3 { 6 } else { 10 }
    |        ^^^^^^^^^^^^^^ help: try: `x == 3`
@@ -34,24 +34,5 @@ LL |     if true && x == 3 { 6 } else { 10 }
    = note: `-D clippy::nonminimal-bool` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]`
 
-error: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
-  --> tests/ui/blocks_in_conditions.rs:76:5
-   |
-LL | /     match {
-LL | |
-LL | |         let opt = Some(2);
-LL | |         opt
-LL | |     } {
-   | |_____^
-   |
-help: try
-   |
-LL ~     let res = {
-LL +
-LL +         let opt = Some(2);
-LL +         opt
-LL ~     }; match res {
-   |
-
-error: aborting due to 4 previous errors
+error: aborting due to 3 previous errors
 
diff --git a/tests/ui/blocks_in_conditions_2021.fixed b/tests/ui/blocks_in_conditions_2021.fixed
new file mode 100644
index 00000000000..c7cc643dba6
--- /dev/null
+++ b/tests/ui/blocks_in_conditions_2021.fixed
@@ -0,0 +1,25 @@
+//@edition: 2021
+
+#![allow(clippy::let_and_return)]
+
+// issue #11814
+fn block_in_match_expr(num: i32) -> i32 {
+    let res = {
+        //~^ ERROR: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
+        let opt = Some(2);
+        opt
+    }; match res {
+        Some(0) => 1,
+        Some(n) => num * 2,
+        None => 0,
+    };
+
+    match unsafe {
+        let hearty_hearty_hearty = vec![240, 159, 146, 150];
+        String::from_utf8_unchecked(hearty_hearty_hearty).as_str()
+    } {
+        "💖" => 1,
+        "what" => 2,
+        _ => 3,
+    }
+}
diff --git a/tests/ui/blocks_in_conditions_2021.rs b/tests/ui/blocks_in_conditions_2021.rs
new file mode 100644
index 00000000000..a911237f5f7
--- /dev/null
+++ b/tests/ui/blocks_in_conditions_2021.rs
@@ -0,0 +1,25 @@
+//@edition: 2021
+
+#![allow(clippy::let_and_return)]
+
+// issue #11814
+fn block_in_match_expr(num: i32) -> i32 {
+    match {
+        //~^ ERROR: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
+        let opt = Some(2);
+        opt
+    } {
+        Some(0) => 1,
+        Some(n) => num * 2,
+        None => 0,
+    };
+
+    match unsafe {
+        let hearty_hearty_hearty = vec![240, 159, 146, 150];
+        String::from_utf8_unchecked(hearty_hearty_hearty).as_str()
+    } {
+        "💖" => 1,
+        "what" => 2,
+        _ => 3,
+    }
+}
diff --git a/tests/ui/blocks_in_conditions_2021.stderr b/tests/ui/blocks_in_conditions_2021.stderr
new file mode 100644
index 00000000000..497ee9d679d
--- /dev/null
+++ b/tests/ui/blocks_in_conditions_2021.stderr
@@ -0,0 +1,23 @@
+error: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
+  --> tests/ui/blocks_in_conditions_2021.rs:7:5
+   |
+LL | /     match {
+LL | |
+LL | |         let opt = Some(2);
+LL | |         opt
+LL | |     } {
+   | |_____^
+   |
+   = note: `-D clippy::blocks-in-conditions` implied by `-D warnings`
+   = help: to override `-D warnings` add `#[allow(clippy::blocks_in_conditions)]`
+help: try
+   |
+LL ~     let res = {
+LL +
+LL +         let opt = Some(2);
+LL +         opt
+LL ~     }; match res {
+   |
+
+error: aborting due to 1 previous error
+