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
This commit is contained in:
Samuel Tardieu 2025-06-02 09:17:55 +00:00 committed by GitHub
commit 88bb8d169b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 51 additions and 1 deletions

View file

@ -143,7 +143,7 @@ impl LateLintPass<'_> for SemicolonBlock {
StmtKind::Expr(Expr {
kind: ExprKind::Block(block, _),
..
}) if !block.span.from_expansion() => {
}) if !block.span.from_expansion() && stmt.span.contains(block.span) => {
let Block {
expr: None,
stmts: [.., stmt],

View file

@ -96,3 +96,28 @@ fn main() {
unit_fn_block()
}
fn issue14926() {
macro_rules! gen_code {
[$l:lifetime: $b:block, $b2: block $(,)?] => {
$l: loop {
$b
break $l;
}
$l: loop {
$b2
break $l;
}
};
}
gen_code! {
'root:
{
println!("Block1");
},
{
println!("Block2");
},
}
}

View file

@ -96,3 +96,28 @@ fn main() {
unit_fn_block()
}
fn issue14926() {
macro_rules! gen_code {
[$l:lifetime: $b:block, $b2: block $(,)?] => {
$l: loop {
$b
break $l;
}
$l: loop {
$b2
break $l;
}
};
}
gen_code! {
'root:
{
println!("Block1");
},
{
println!("Block2");
},
}
}