Skip to content

Commit 6fd0258

Browse files
committed
Auto merge of rust-lang#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 rust-lang#12162
2 parents 4b3a9c0 + c6079a6 commit 6fd0258

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

Diff for: clippy_lints/src/blocks_in_conditions.rs

+5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInConditions {
6767
);
6868

6969
if let ExprKind::Block(block, _) = &cond.kind {
70+
if !block.span.eq_ctxt(expr.span) {
71+
// If the block comes from a macro, or as an argument to a macro,
72+
// do not lint.
73+
return;
74+
}
7075
if block.rules == BlockCheckMode::DefaultBlock {
7176
if block.stmts.is_empty() {
7277
if let Some(ex) = &block.expr {

Diff for: tests/ui/blocks_in_conditions.fixed

+14
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,18 @@ fn block_in_match_expr(num: i32) -> i32 {
8585
}
8686
}
8787

88+
// issue #12162
89+
macro_rules! timed {
90+
($name:expr, $body:expr $(,)?) => {{
91+
let __scope = ();
92+
$body
93+
}};
94+
}
95+
96+
fn issue_12162() {
97+
if timed!("check this!", false) {
98+
println!();
99+
}
100+
}
101+
88102
fn main() {}

Diff for: tests/ui/blocks_in_conditions.rs

+14
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,18 @@ fn block_in_match_expr(num: i32) -> i32 {
8585
}
8686
}
8787

88+
// issue #12162
89+
macro_rules! timed {
90+
($name:expr, $body:expr $(,)?) => {{
91+
let __scope = ();
92+
$body
93+
}};
94+
}
95+
96+
fn issue_12162() {
97+
if timed!("check this!", false) {
98+
println!();
99+
}
100+
}
101+
88102
fn main() {}

0 commit comments

Comments
 (0)