diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2025-06-02 09:17:55 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-02 09:17:55 +0000 |
| commit | 88bb8d169bc2c9b688bb2e9adf98f9cb72b08057 (patch) | |
| tree | b6c9819adf6346e64638e0d17e56288cdc357a72 | |
| parent | a5a7eea0a2dd0bc2c6736075a8394eeb679341de (diff) | |
| parent | 12fc6c7cc919ff5bdbce93da70e221a060acf23f (diff) | |
| download | rust-88bb8d169bc2c9b688bb2e9adf98f9cb72b08057.tar.gz rust-88bb8d169bc2c9b688bb2e9adf98f9cb72b08057.zip | |
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
| -rw-r--r-- | clippy_lints/src/semicolon_block.rs | 2 | ||||
| -rw-r--r-- | tests/ui/semicolon_outside_block.fixed | 25 | ||||
| -rw-r--r-- | tests/ui/semicolon_outside_block.rs | 25 |
3 files changed, 51 insertions, 1 deletions
diff --git a/clippy_lints/src/semicolon_block.rs b/clippy_lints/src/semicolon_block.rs index d85f4a8fa01..f6c128d4c52 100644 --- a/clippy_lints/src/semicolon_block.rs +++ b/clippy_lints/src/semicolon_block.rs @@ -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], diff --git a/tests/ui/semicolon_outside_block.fixed b/tests/ui/semicolon_outside_block.fixed index 52fae9a3aff..a3be80b4928 100644 --- a/tests/ui/semicolon_outside_block.fixed +++ b/tests/ui/semicolon_outside_block.fixed @@ -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"); + }, + } +} diff --git a/tests/ui/semicolon_outside_block.rs b/tests/ui/semicolon_outside_block.rs index 5975e66fbb8..3b7bf68029f 100644 --- a/tests/ui/semicolon_outside_block.rs +++ b/tests/ui/semicolon_outside_block.rs @@ -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"); + }, + } +} |
