-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
245 additions
and
171 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
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,16 @@ | ||
#![warn(clippy::option_expect_used, clippy::result_expect_used)] | ||
|
||
fn expect_option() { | ||
let opt = Some(0); | ||
let _ = opt.expect(""); | ||
} | ||
|
||
fn expect_result() { | ||
let res: Result<u8, ()> = Ok(0); | ||
let _ = res.expect(""); | ||
} | ||
|
||
fn main() { | ||
expect_option(); | ||
expect_result(); | ||
} |
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,18 @@ | ||
error: used expect() on an Option value. If this value is an None it will panic | ||
--> $DIR/expect.rs:5:13 | ||
| | ||
LL | let _ = opt.expect(""); | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::option-expect-used` implied by `-D warnings` | ||
|
||
error: used expect() on a Result value. If this value is an Err it will panic | ||
--> $DIR/expect.rs:10:13 | ||
| | ||
LL | let _ = res.expect(""); | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::result-expect-used` implied by `-D warnings` | ||
|
||
error: aborting due to 2 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
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 |
---|---|---|
@@ -1,12 +1,61 @@ | ||
#![warn(clippy::panic)] | ||
#![warn(clippy::panic_params)] | ||
#![allow(clippy::assertions_on_constants)] | ||
fn missing() { | ||
if true { | ||
panic!("{}"); | ||
} else if false { | ||
panic!("{:?}"); | ||
} else { | ||
assert!(true, "here be missing values: {}"); | ||
} | ||
|
||
fn panic() { | ||
let a = 2; | ||
panic!(); | ||
let b = a + 2; | ||
panic!("{{{this}}}"); | ||
} | ||
|
||
fn ok_single() { | ||
panic!("foo bar"); | ||
} | ||
|
||
fn ok_inner() { | ||
// Test for #768 | ||
assert!("foo bar".contains(&format!("foo {}", "bar"))); | ||
} | ||
|
||
fn ok_multiple() { | ||
panic!("{}", "This is {ok}"); | ||
} | ||
|
||
fn ok_bracket() { | ||
match 42 { | ||
1337 => panic!("{so is this"), | ||
666 => panic!("so is this}"), | ||
_ => panic!("}so is that{"), | ||
} | ||
} | ||
|
||
const ONE: u32 = 1; | ||
|
||
fn ok_nomsg() { | ||
assert!({ 1 == ONE }); | ||
assert!(if 1 == ONE { ONE == 1 } else { false }); | ||
} | ||
|
||
fn ok_escaped() { | ||
panic!("{{ why should this not be ok? }}"); | ||
panic!(" or {{ that ?"); | ||
panic!(" or }} this ?"); | ||
panic!(" {or {{ that ?"); | ||
panic!(" }or }} this ?"); | ||
panic!("{{ test }"); | ||
panic!("{case }}"); | ||
} | ||
|
||
fn main() { | ||
panic(); | ||
missing(); | ||
ok_single(); | ||
ok_multiple(); | ||
ok_bracket(); | ||
ok_inner(); | ||
ok_nomsg(); | ||
ok_escaped(); | ||
} |
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 |
---|---|---|
@@ -1,10 +1,28 @@ | ||
error: `panic` should not be present in production code | ||
--> $DIR/panic.rs:6:5 | ||
error: you probably are missing some parameter in your format string | ||
--> $DIR/panic.rs:5:16 | ||
| | ||
LL | panic!(); | ||
| ^^^^^^^^^ | ||
LL | panic!("{}"); | ||
| ^^^^ | ||
| | ||
= note: `-D clippy::panic` implied by `-D warnings` | ||
= note: `-D clippy::panic-params` implied by `-D warnings` | ||
|
||
error: aborting due to previous error | ||
error: you probably are missing some parameter in your format string | ||
--> $DIR/panic.rs:7:16 | ||
| | ||
LL | panic!("{:?}"); | ||
| ^^^^^^ | ||
|
||
error: you probably are missing some parameter in your format string | ||
--> $DIR/panic.rs:9:23 | ||
| | ||
LL | assert!(true, "here be missing values: {}"); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: you probably are missing some parameter in your format string | ||
--> $DIR/panic.rs:12:12 | ||
| | ||
LL | panic!("{{{this}}}"); | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.