Auto merge of #12173 - samueltardieu:issue-12162, r=Manishearth

blocks_in_conditions: do not warn if condition comes from macro

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

Fix #12162
This commit is contained in:
bors 2024-01-19 01:30:43 +00:00
commit 6fd0258e45
3 changed files with 33 additions and 0 deletions

View File

@ -67,6 +67,11 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
); );
if let ExprKind::Block(block, _) = &cond.kind { 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.rules == BlockCheckMode::DefaultBlock {
if block.stmts.is_empty() { if block.stmts.is_empty() {
if let Some(ex) = &block.expr { if let Some(ex) = &block.expr {

View File

@ -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() {} fn main() {}

View File

@ -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() {} fn main() {}