forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unwrap_used and expect_used: trigger on uses of their _err variants
- Loading branch information
Showing
5 changed files
with
78 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,35 @@ | ||
#![warn(clippy::unwrap_used, clippy::expect_used)] | ||
|
||
trait OptionExt { | ||
type Item; | ||
|
||
fn unwrap_err(self) -> Self::Item; | ||
|
||
fn expect_err(self, msg: &str) -> Self::Item; | ||
} | ||
|
||
impl<T> OptionExt for Option<T> { | ||
type Item = T; | ||
fn unwrap_err(self) -> T { | ||
panic!(); | ||
} | ||
|
||
fn expect_err(self, msg: &str) -> T { | ||
panic!(); | ||
} | ||
} | ||
|
||
fn main() { | ||
Some(3).unwrap(); | ||
Some(3).expect("Hello world!"); | ||
|
||
// Don't trigger on unwrap_err on an option | ||
Some(3).unwrap_err(); | ||
Some(3).expect_err("Hellow none!"); | ||
|
||
let a: Result<i32, i32> = Ok(3); | ||
a.unwrap(); | ||
a.expect("Hello world!"); | ||
a.unwrap_err(); | ||
a.expect_err("Hello error!"); | ||
} |
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