Skip to content

Commit 88bb8d1

Browse files
Fix semicolon_outside_block suggests wrongly when inside macros (#14954)
Closes rust-lang/rust-clippy#14926 changelog: [`semicolon_outside_block`] fix wrong suggestions when inside macros
2 parents a5a7eea + 12fc6c7 commit 88bb8d1

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

clippy_lints/src/semicolon_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl LateLintPass<'_> for SemicolonBlock {
143143
StmtKind::Expr(Expr {
144144
kind: ExprKind::Block(block, _),
145145
..
146-
}) if !block.span.from_expansion() => {
146+
}) if !block.span.from_expansion() && stmt.span.contains(block.span) => {
147147
let Block {
148148
expr: None,
149149
stmts: [.., stmt],

tests/ui/semicolon_outside_block.fixed

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,28 @@ fn main() {
9696

9797
unit_fn_block()
9898
}
99+
100+
fn issue14926() {
101+
macro_rules! gen_code {
102+
[$l:lifetime: $b:block, $b2: block $(,)?] => {
103+
$l: loop {
104+
$b
105+
break $l;
106+
}
107+
$l: loop {
108+
$b2
109+
break $l;
110+
}
111+
};
112+
}
113+
114+
gen_code! {
115+
'root:
116+
{
117+
println!("Block1");
118+
},
119+
{
120+
println!("Block2");
121+
},
122+
}
123+
}

tests/ui/semicolon_outside_block.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,28 @@ fn main() {
9696

9797
unit_fn_block()
9898
}
99+
100+
fn issue14926() {
101+
macro_rules! gen_code {
102+
[$l:lifetime: $b:block, $b2: block $(,)?] => {
103+
$l: loop {
104+
$b
105+
break $l;
106+
}
107+
$l: loop {
108+
$b2
109+
break $l;
110+
}
111+
};
112+
}
113+
114+
gen_code! {
115+
'root:
116+
{
117+
println!("Block1");
118+
},
119+
{
120+
println!("Block2");
121+
},
122+
}
123+
}

0 commit comments

Comments
 (0)