unwrap_used, expect_used: accept macro result as receiver (#14575)
changelog: [`unwrap_used`, `expect_used`]: lint even when the receiver is a macro expansion result This also paves the way for expanding more method call lints to expanded receivers or arguments. Fixes rust-lang/rust-clippy#13455
This commit is contained in:
commit
ca78fb4031
3 changed files with 105 additions and 44 deletions
|
|
@ -66,3 +66,20 @@ fn main() {
|
|||
SOME.expect("Still not three?");
|
||||
}
|
||||
}
|
||||
|
||||
mod with_expansion {
|
||||
macro_rules! open {
|
||||
($file:expr) => {
|
||||
std::fs::File::open($file)
|
||||
};
|
||||
}
|
||||
|
||||
fn test(file: &str) {
|
||||
use std::io::Read;
|
||||
let mut s = String::new();
|
||||
let _ = open!(file).unwrap(); //~ unwrap_used
|
||||
let _ = open!(file).expect("can open"); //~ expect_used
|
||||
let _ = open!(file).unwrap_err(); //~ unwrap_used
|
||||
let _ = open!(file).expect_err("can open"); //~ expect_used
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,5 +50,37 @@ LL | a.expect_err("Hello error!");
|
|||
|
|
||||
= note: if this value is an `Ok`, it will panic
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error: used `unwrap()` on a `Result` value
|
||||
--> tests/ui/unwrap_expect_used.rs:80:17
|
||||
|
|
||||
LL | let _ = open!(file).unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: if this value is an `Err`, it will panic
|
||||
|
||||
error: used `expect()` on a `Result` value
|
||||
--> tests/ui/unwrap_expect_used.rs:81:17
|
||||
|
|
||||
LL | let _ = open!(file).expect("can open");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: if this value is an `Err`, it will panic
|
||||
|
||||
error: used `unwrap_err()` on a `Result` value
|
||||
--> tests/ui/unwrap_expect_used.rs:82:17
|
||||
|
|
||||
LL | let _ = open!(file).unwrap_err();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: if this value is an `Ok`, it will panic
|
||||
|
||||
error: used `expect_err()` on a `Result` value
|
||||
--> tests/ui/unwrap_expect_used.rs:83:17
|
||||
|
|
||||
LL | let _ = open!(file).expect_err("can open");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: if this value is an `Ok`, it will panic
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue