Auto merge of #10822 - Alexendoo:needless-else-cfg, r=llogiq
Ignore `#[cfg]`'d out code in `needless_else` changelog: none (same release as #10810) `#[cfg]` making things fun once more This lead me to think about macro calls that expand to nothing as well, but apparently they produce an empty stmt in the AST so are already handled, added a test for that r? `@llogiq`
This commit is contained in:
commit
c9ddcf0d06
4 changed files with 58 additions and 20 deletions
|
|
@ -12,6 +12,10 @@ macro_rules! mac {
|
|||
};
|
||||
}
|
||||
|
||||
macro_rules! empty_expansion {
|
||||
() => {};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let b = std::hint::black_box(true);
|
||||
|
||||
|
|
@ -37,4 +41,17 @@ fn main() {
|
|||
|
||||
// Do not lint because inside a macro
|
||||
mac!(b);
|
||||
|
||||
if b {
|
||||
println!("Foobar");
|
||||
} else {
|
||||
#[cfg(foo)]
|
||||
"Do not lint cfg'd out code"
|
||||
}
|
||||
|
||||
if b {
|
||||
println!("Foobar");
|
||||
} else {
|
||||
empty_expansion!();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,10 @@ macro_rules! mac {
|
|||
};
|
||||
}
|
||||
|
||||
macro_rules! empty_expansion {
|
||||
() => {};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let b = std::hint::black_box(true);
|
||||
|
||||
|
|
@ -38,4 +42,17 @@ fn main() {
|
|||
|
||||
// Do not lint because inside a macro
|
||||
mac!(b);
|
||||
|
||||
if b {
|
||||
println!("Foobar");
|
||||
} else {
|
||||
#[cfg(foo)]
|
||||
"Do not lint cfg'd out code"
|
||||
}
|
||||
|
||||
if b {
|
||||
println!("Foobar");
|
||||
} else {
|
||||
empty_expansion!();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: this else branch is empty
|
||||
--> $DIR/needless_else.rs:20:7
|
||||
--> $DIR/needless_else.rs:24:7
|
||||
|
|
||||
LL | } else {
|
||||
| _______^
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue