mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-08 09:38:26 +03:00
Add blocks_in_conditions edition 2021 specific tests
The borrowing rules in Rust 2024 prevented those tests from compiling.
This commit is contained in:
@@ -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 $(,)?) => {{
|
||||
|
||||
@@ -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 $(,)?) => {{
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user