Skip to content

Commit

Permalink
Auto merge of rust-lang#12173 - samueltardieu:issue-12162, r=Manishearth
Browse files Browse the repository at this point in the history
blocks_in_conditions: do not warn if condition comes from macro

changelog: [`blocks_in_conditions`]: do not warn if condition comes from macro

Fix rust-lang#12162
  • Loading branch information
bors committed Jan 19, 2024
2 parents 4b3a9c0 + c6079a6 commit 6fd0258
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions clippy_lints/src/blocks_in_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInConditions {
);

if let ExprKind::Block(block, _) = &cond.kind {
if !block.span.eq_ctxt(expr.span) {
// If the block comes from a macro, or as an argument to a macro,
// do not lint.
return;
}
if block.rules == BlockCheckMode::DefaultBlock {
if block.stmts.is_empty() {
if let Some(ex) = &block.expr {
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/blocks_in_conditions.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,18 @@ fn block_in_match_expr(num: i32) -> i32 {
}
}

// issue #12162
macro_rules! timed {
($name:expr, $body:expr $(,)?) => {{
let __scope = ();
$body
}};
}

fn issue_12162() {
if timed!("check this!", false) {
println!();
}
}

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/blocks_in_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,18 @@ fn block_in_match_expr(num: i32) -> i32 {
}
}

// issue #12162
macro_rules! timed {
($name:expr, $body:expr $(,)?) => {{
let __scope = ();
$body
}};
}

fn issue_12162() {
if timed!("check this!", false) {
println!();
}
}

fn main() {}

0 comments on commit 6fd0258

Please sign in to comment.