mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-25 20:07:21 +00:00
commit
5a61a95d31
2 changed files with 15 additions and 2 deletions
|
@ -92,7 +92,9 @@ impl LateLintPass for BlockInIfCondition {
|
||||||
snippet_block(cx, then.span, "..")));
|
snippet_block(cx, then.span, "..")));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if in_macro(cx, expr.span) || differing_macro_contexts(expr.span, block.stmts[0].span) {
|
let span = block.expr.as_ref().map_or_else(|| block.stmts[0].span,
|
||||||
|
|e| e.span);
|
||||||
|
if in_macro(cx, span) || differing_macro_contexts(expr.span, span) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// move block higher
|
// move block higher
|
||||||
|
|
|
@ -3,17 +3,28 @@
|
||||||
|
|
||||||
#![deny(block_in_if_condition_expr)]
|
#![deny(block_in_if_condition_expr)]
|
||||||
#![deny(block_in_if_condition_stmt)]
|
#![deny(block_in_if_condition_stmt)]
|
||||||
#![allow(unused)]
|
#![allow(unused, let_and_return)]
|
||||||
|
|
||||||
|
|
||||||
macro_rules! blocky {
|
macro_rules! blocky {
|
||||||
() => {{true}}
|
() => {{true}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! blocky_too {
|
||||||
|
() => {{
|
||||||
|
let r = true;
|
||||||
|
r
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
fn macro_if() {
|
fn macro_if() {
|
||||||
if blocky!() {
|
if blocky!() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if blocky_too!() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn condition_has_block() -> i32 {
|
fn condition_has_block() -> i32 {
|
||||||
|
|
||||||
if { //~ERROR in an 'if' condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a 'let'
|
if { //~ERROR in an 'if' condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a 'let'
|
||||||
|
|
Loading…
Add table
Reference in a new issue