forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#7851 - nbdd0121:master, r=flip1995
Fix manual_assert and match_wild_err_arm for `#![no_std]` and Rust 2021 Rust 2015 `std::panic!` has a wrapping block while `core::panic!` and Rust 2021 `std::panic!` does not. See rust-lang#88919 for details. Note that the test won't pass until clippy changes in rust-lang#88860 is synced. --- changelog: Fix [`manual_assert`] and [`match_wild_err_arm`] for `#![no_std]` and Rust 2021. Fixes rust-lang#7723
- Loading branch information
Showing
13 changed files
with
254 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// revisions: edition2018 edition2021 | ||
// [edition2018] edition:2018 | ||
// [edition2021] edition:2021 | ||
// run-rustfix | ||
#![warn(clippy::manual_assert)] | ||
|
||
fn main() { | ||
let a = vec![1, 2, 3]; | ||
let c = Some(2); | ||
if !a.is_empty() | ||
&& a.len() == 3 | ||
&& c != None | ||
&& !a.is_empty() | ||
&& a.len() == 3 | ||
&& !a.is_empty() | ||
&& a.len() == 3 | ||
&& !a.is_empty() | ||
&& a.len() == 3 | ||
{ | ||
panic!("qaqaq{:?}", a); | ||
} | ||
assert!(a.is_empty(), "qaqaq{:?}", a); | ||
assert!(a.is_empty(), "qwqwq"); | ||
if a.len() == 3 { | ||
println!("qwq"); | ||
println!("qwq"); | ||
println!("qwq"); | ||
} | ||
if let Some(b) = c { | ||
panic!("orz {}", b); | ||
} | ||
if a.len() == 3 { | ||
panic!("qaqaq"); | ||
} else { | ||
println!("qwq"); | ||
} | ||
let b = vec![1, 2, 3]; | ||
assert!(!b.is_empty(), "panic1"); | ||
assert!(!(b.is_empty() && a.is_empty()), "panic2"); | ||
assert!(!(a.is_empty() && !b.is_empty()), "panic3"); | ||
assert!(!(b.is_empty() || a.is_empty()), "panic4"); | ||
assert!(!(a.is_empty() || !b.is_empty()), "panic5"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// revisions: edition2018 edition2021 | ||
// [edition2018] edition:2018 | ||
// [edition2021] edition:2021 | ||
// run-rustfix | ||
#![warn(clippy::manual_assert)] | ||
|
||
fn main() { | ||
let a = vec![1, 2, 3]; | ||
let c = Some(2); | ||
if !a.is_empty() | ||
&& a.len() == 3 | ||
&& c != None | ||
&& !a.is_empty() | ||
&& a.len() == 3 | ||
&& !a.is_empty() | ||
&& a.len() == 3 | ||
&& !a.is_empty() | ||
&& a.len() == 3 | ||
{ | ||
panic!("qaqaq{:?}", a); | ||
} | ||
assert!(a.is_empty(), "qaqaq{:?}", a); | ||
assert!(a.is_empty(), "qwqwq"); | ||
if a.len() == 3 { | ||
println!("qwq"); | ||
println!("qwq"); | ||
println!("qwq"); | ||
} | ||
if let Some(b) = c { | ||
panic!("orz {}", b); | ||
} | ||
if a.len() == 3 { | ||
panic!("qaqaq"); | ||
} else { | ||
println!("qwq"); | ||
} | ||
let b = vec![1, 2, 3]; | ||
assert!(!b.is_empty(), "panic1"); | ||
assert!(!(b.is_empty() && a.is_empty()), "panic2"); | ||
assert!(!(a.is_empty() && !b.is_empty()), "panic3"); | ||
assert!(!(b.is_empty() || a.is_empty()), "panic4"); | ||
assert!(!(a.is_empty() || !b.is_empty()), "panic5"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
error: only a `panic!` in `if`-then statement | ||
--> $DIR/manual_assert.rs:22:5 | ||
| | ||
LL | / if !a.is_empty() { | ||
LL | | panic!("qaqaq{:?}", a); | ||
LL | | } | ||
| |_____^ help: try: `assert!(a.is_empty(), "qaqaq{:?}", a);` | ||
| | ||
= note: `-D clippy::manual-assert` implied by `-D warnings` | ||
|
||
error: only a `panic!` in `if`-then statement | ||
--> $DIR/manual_assert.rs:25:5 | ||
| | ||
LL | / if !a.is_empty() { | ||
LL | | panic!("qwqwq"); | ||
LL | | } | ||
| |_____^ help: try: `assert!(a.is_empty(), "qwqwq");` | ||
|
||
error: only a `panic!` in `if`-then statement | ||
--> $DIR/manual_assert.rs:42:5 | ||
| | ||
LL | / if b.is_empty() { | ||
LL | | panic!("panic1"); | ||
LL | | } | ||
| |_____^ help: try: `assert!(!b.is_empty(), "panic1");` | ||
|
||
error: only a `panic!` in `if`-then statement | ||
--> $DIR/manual_assert.rs:45:5 | ||
| | ||
LL | / if b.is_empty() && a.is_empty() { | ||
LL | | panic!("panic2"); | ||
LL | | } | ||
| |_____^ help: try: `assert!(!(b.is_empty() && a.is_empty()), "panic2");` | ||
|
||
error: only a `panic!` in `if`-then statement | ||
--> $DIR/manual_assert.rs:48:5 | ||
| | ||
LL | / if a.is_empty() && !b.is_empty() { | ||
LL | | panic!("panic3"); | ||
LL | | } | ||
| |_____^ help: try: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");` | ||
|
||
error: only a `panic!` in `if`-then statement | ||
--> $DIR/manual_assert.rs:51:5 | ||
| | ||
LL | / if b.is_empty() || a.is_empty() { | ||
LL | | panic!("panic4"); | ||
LL | | } | ||
| |_____^ help: try: `assert!(!(b.is_empty() || a.is_empty()), "panic4");` | ||
|
||
error: only a `panic!` in `if`-then statement | ||
--> $DIR/manual_assert.rs:54:5 | ||
| | ||
LL | / if a.is_empty() || !b.is_empty() { | ||
LL | | panic!("panic5"); | ||
LL | | } | ||
| |_____^ help: try: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");` | ||
|
||
error: aborting due to 7 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.