-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
{expect,unwrap}_used
: add options to lint at compilation time (#14200)
By default, do not lint `.unwrap()` and `.expect(…)` in always const contexts, as a failure would be detected at compile time anyway. New options `allow_expect_in_consts` and `allow_unwrap_in_consts`, defaulting to `true`, can be turned unset to still lint in always const contexts. Close #14198 changelog: [`unwrap_used`, `expect_used`]: add new option to lint in always constant contexts
- Loading branch information
Showing
13 changed files
with
123 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
allow-expect-in-consts = false | ||
allow-expect-in-tests = true |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
allow-unwrap-in-consts = false | ||
allow-unwrap-in-tests = true |
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,11 @@ | ||
#![warn(clippy::unwrap_used)] | ||
|
||
fn main() { | ||
const SOME: Option<i32> = Some(3); | ||
const UNWRAPPED: i32 = SOME.unwrap(); | ||
//~^ ERROR: used `unwrap()` on an `Option` value | ||
const { | ||
SOME.unwrap(); | ||
//~^ ERROR: used `unwrap()` on an `Option` value | ||
} | ||
} |
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,22 @@ | ||
error: used `unwrap()` on an `Option` value | ||
--> tests/ui-toml/unwrap_used/unwrap_used_const.rs:5:28 | ||
| | ||
LL | const UNWRAPPED: i32 = SOME.unwrap(); | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= note: if this value is `None`, it will panic | ||
= help: consider using `expect()` to provide a better panic message | ||
= note: `-D clippy::unwrap-used` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::unwrap_used)]` | ||
|
||
error: used `unwrap()` on an `Option` value | ||
--> tests/ui-toml/unwrap_used/unwrap_used_const.rs:8:9 | ||
| | ||
LL | SOME.unwrap(); | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= note: if this value is `None`, it will panic | ||
= help: consider using `expect()` to provide a better panic message | ||
|
||
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