Don't emit try_err lint in external macros

This commit is contained in:
Philipp Hansch 2019-10-24 07:52:01 +02:00
parent 850dfdae60
commit 52f52900a4
No known key found for this signature in database
GPG key ID: 82AA61CAA11397E6
5 changed files with 37 additions and 7 deletions

View file

@ -16,3 +16,18 @@ macro_rules! must_use_unit {
fn foo() {}
};
}
#[macro_export]
macro_rules! try_err {
() => {
pub fn try_err_fn() -> Result<i32, i32> {
let err: i32 = 1;
// To avoid warnings during rustfix
if true {
Err(err)?
} else {
Ok(2)
}
}
};
}

View file

@ -1,7 +1,11 @@
// run-rustfix
// aux-build:macro_rules.rs
#![deny(clippy::try_err)]
#[macro_use]
extern crate macro_rules;
// Tests that a simple case works
// Should flag `Err(err)?`
pub fn basic_test() -> Result<i32, i32> {
@ -77,6 +81,9 @@ fn main() {
negative_test().unwrap();
closure_matches_test().unwrap();
closure_into_test().unwrap();
// We don't want to lint in external macros
try_err!();
}
macro_rules! bar {

View file

@ -1,7 +1,11 @@
// run-rustfix
// aux-build:macro_rules.rs
#![deny(clippy::try_err)]
#[macro_use]
extern crate macro_rules;
// Tests that a simple case works
// Should flag `Err(err)?`
pub fn basic_test() -> Result<i32, i32> {
@ -77,6 +81,9 @@ fn main() {
negative_test().unwrap();
closure_matches_test().unwrap();
closure_into_test().unwrap();
// We don't want to lint in external macros
try_err!();
}
macro_rules! bar {

View file

@ -1,35 +1,35 @@
error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:11:9
--> $DIR/try_err.rs:15:9
|
LL | Err(err)?;
| ^^^^^^^^^ help: try this: `return Err(err)`
|
note: lint level defined here
--> $DIR/try_err.rs:3:9
--> $DIR/try_err.rs:4:9
|
LL | #![deny(clippy::try_err)]
| ^^^^^^^^^^^^^^^
error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:21:9
--> $DIR/try_err.rs:25:9
|
LL | Err(err)?;
| ^^^^^^^^^ help: try this: `return Err(err.into())`
error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:41:17
--> $DIR/try_err.rs:45:17
|
LL | Err(err)?;
| ^^^^^^^^^ help: try this: `return Err(err)`
error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:60:17
--> $DIR/try_err.rs:64:17
|
LL | Err(err)?;
| ^^^^^^^^^ help: try this: `return Err(err.into())`
error: returning an `Err(_)` with the `?` operator
--> $DIR/try_err.rs:96:9
--> $DIR/try_err.rs:103:9
|
LL | Err(foo!())?;
| ^^^^^^^^^^^^ help: try this: `return Err(foo!())`