Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 67d5056

Browse files
committed
Add blocks_in_conditions edition 2021 specific tests
The borrowing rules in Rust 2024 prevented those tests from compiling.
1 parent b3d401e commit 67d5056

6 files changed

+79
-79
lines changed

tests/ui/blocks_in_conditions.fixed

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
//@aux-build:proc_macro_attr.rs
22

33
#![warn(clippy::blocks_in_conditions)]
4-
#![allow(
5-
unused,
6-
clippy::let_and_return,
7-
clippy::needless_if,
8-
clippy::missing_transmute_annotations
9-
)]
4+
#![allow(unused, clippy::needless_if, clippy::missing_transmute_annotations)]
105
#![warn(clippy::nonminimal_bool)]
116

127
macro_rules! blocky {
@@ -71,28 +66,6 @@ fn block_in_assert() {
7166
);
7267
}
7368

74-
// issue #11814
75-
fn block_in_match_expr(num: i32) -> i32 {
76-
let res = {
77-
//~^ 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`
78-
let opt = Some(2);
79-
opt
80-
}; match res {
81-
Some(0) => 1,
82-
Some(n) => num * 2,
83-
None => 0,
84-
};
85-
86-
match unsafe {
87-
let hearty_hearty_hearty = vec![240, 159, 146, 150];
88-
String::from_utf8_unchecked(hearty_hearty_hearty).as_str()
89-
} {
90-
"💖" => 1,
91-
"what" => 2,
92-
_ => 3,
93-
}
94-
}
95-
9669
// issue #12162
9770
macro_rules! timed {
9871
($name:expr, $body:expr $(,)?) => {{

tests/ui/blocks_in_conditions.rs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
//@aux-build:proc_macro_attr.rs
22

33
#![warn(clippy::blocks_in_conditions)]
4-
#![allow(
5-
unused,
6-
clippy::let_and_return,
7-
clippy::needless_if,
8-
clippy::missing_transmute_annotations
9-
)]
4+
#![allow(unused, clippy::needless_if, clippy::missing_transmute_annotations)]
105
#![warn(clippy::nonminimal_bool)]
116

127
macro_rules! blocky {
@@ -71,28 +66,6 @@ fn block_in_assert() {
7166
);
7267
}
7368

74-
// issue #11814
75-
fn block_in_match_expr(num: i32) -> i32 {
76-
match {
77-
//~^ 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`
78-
let opt = Some(2);
79-
opt
80-
} {
81-
Some(0) => 1,
82-
Some(n) => num * 2,
83-
None => 0,
84-
};
85-
86-
match unsafe {
87-
let hearty_hearty_hearty = vec![240, 159, 146, 150];
88-
String::from_utf8_unchecked(hearty_hearty_hearty).as_str()
89-
} {
90-
"💖" => 1,
91-
"what" => 2,
92-
_ => 3,
93-
}
94-
}
95-
9669
// issue #12162
9770
macro_rules! timed {
9871
($name:expr, $body:expr $(,)?) => {{

tests/ui/blocks_in_conditions.stderr

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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`
2-
--> tests/ui/blocks_in_conditions.rs:30:5
2+
--> tests/ui/blocks_in_conditions.rs:25:5
33
|
44
LL | / if {
55
LL | |
@@ -20,38 +20,19 @@ LL ~ }; if res {
2020
|
2121

2222
error: omit braces around single expression condition
23-
--> tests/ui/blocks_in_conditions.rs:42:8
23+
--> tests/ui/blocks_in_conditions.rs:37:8
2424
|
2525
LL | if { true } { 6 } else { 10 }
2626
| ^^^^^^^^ help: try: `true`
2727

2828
error: this boolean expression can be simplified
29-
--> tests/ui/blocks_in_conditions.rs:48:8
29+
--> tests/ui/blocks_in_conditions.rs:43:8
3030
|
3131
LL | if true && x == 3 { 6 } else { 10 }
3232
| ^^^^^^^^^^^^^^ help: try: `x == 3`
3333
|
3434
= note: `-D clippy::nonminimal-bool` implied by `-D warnings`
3535
= help: to override `-D warnings` add `#[allow(clippy::nonminimal_bool)]`
3636

37-
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`
38-
--> tests/ui/blocks_in_conditions.rs:76:5
39-
|
40-
LL | / match {
41-
LL | |
42-
LL | | let opt = Some(2);
43-
LL | | opt
44-
LL | | } {
45-
| |_____^
46-
|
47-
help: try
48-
|
49-
LL ~ let res = {
50-
LL +
51-
LL + let opt = Some(2);
52-
LL + opt
53-
LL ~ }; match res {
54-
|
55-
56-
error: aborting due to 4 previous errors
37+
error: aborting due to 3 previous errors
5738

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@edition: 2021
2+
3+
#![allow(clippy::let_and_return)]
4+
5+
// issue #11814
6+
fn block_in_match_expr(num: i32) -> i32 {
7+
let res = {
8+
//~^ 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`
9+
let opt = Some(2);
10+
opt
11+
}; match res {
12+
Some(0) => 1,
13+
Some(n) => num * 2,
14+
None => 0,
15+
};
16+
17+
match unsafe {
18+
let hearty_hearty_hearty = vec![240, 159, 146, 150];
19+
String::from_utf8_unchecked(hearty_hearty_hearty).as_str()
20+
} {
21+
"💖" => 1,
22+
"what" => 2,
23+
_ => 3,
24+
}
25+
}

tests/ui/blocks_in_conditions_2021.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@edition: 2021
2+
3+
#![allow(clippy::let_and_return)]
4+
5+
// issue #11814
6+
fn block_in_match_expr(num: i32) -> i32 {
7+
match {
8+
//~^ 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`
9+
let opt = Some(2);
10+
opt
11+
} {
12+
Some(0) => 1,
13+
Some(n) => num * 2,
14+
None => 0,
15+
};
16+
17+
match unsafe {
18+
let hearty_hearty_hearty = vec![240, 159, 146, 150];
19+
String::from_utf8_unchecked(hearty_hearty_hearty).as_str()
20+
} {
21+
"💖" => 1,
22+
"what" => 2,
23+
_ => 3,
24+
}
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
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`
2+
--> tests/ui/blocks_in_conditions_2021.rs:7:5
3+
|
4+
LL | / match {
5+
LL | |
6+
LL | | let opt = Some(2);
7+
LL | | opt
8+
LL | | } {
9+
| |_____^
10+
|
11+
= note: `-D clippy::blocks-in-conditions` implied by `-D warnings`
12+
= help: to override `-D warnings` add `#[allow(clippy::blocks_in_conditions)]`
13+
help: try
14+
|
15+
LL ~ let res = {
16+
LL +
17+
LL + let opt = Some(2);
18+
LL + opt
19+
LL ~ }; match res {
20+
|
21+
22+
error: aborting due to 1 previous error
23+

0 commit comments

Comments
 (0)