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.
Auto merge of rust-lang#9338 - sgued:9331-unwrap-err-used, r=giraffate
unwrap_used and expect_used: trigger on uses of their _err variants changelog: [`unwrap_used`]: lint uses of `unwrap_err` changelog: [`expect_used`]: lint uses of `expect_err` fixes rust-lang#9331
- Loading branch information
Showing
9 changed files
with
101 additions
and
24 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
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