Skip to content

Commit 0126bc9

Browse files
authored
Fix semicolon_inside_block FP when attribute over expr is not enabled (#15476)
Closes #15388 changelog: [`semicolon_inside_block`] fix FP when attribute over expr is not enabled
2 parents 22c47f0 + f11d512 commit 0126bc9

6 files changed

+53
-0
lines changed

clippy_lints/src/semicolon_block.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ impl LateLintPass<'_> for SemicolonBlock {
155155
kind: ExprKind::Block(block, _),
156156
..
157157
}) if !block.span.from_expansion() => {
158+
let attrs = cx.tcx.hir_attrs(stmt.hir_id);
159+
if !attrs.is_empty() && !cx.tcx.features().stmt_expr_attributes() {
160+
return;
161+
}
162+
158163
if let Some(tail) = block.expr {
159164
self.semicolon_inside_block(cx, block, tail, stmt.span);
160165
}

tests/ui/semicolon_inside_block.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,8 @@ fn main() {
8686

8787
unit_fn_block()
8888
}
89+
90+
pub fn issue15388() {
91+
#[rustfmt::skip]
92+
{0; 0};
93+
}

tests/ui/semicolon_inside_block.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,8 @@ fn main() {
8686

8787
unit_fn_block()
8888
}
89+
90+
pub fn issue15388() {
91+
#[rustfmt::skip]
92+
{0; 0};
93+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Test when the feature `stmt_expr_attributes` is enabled
2+
3+
#![feature(stmt_expr_attributes)]
4+
#![allow(clippy::no_effect)]
5+
#![warn(clippy::semicolon_inside_block)]
6+
7+
pub fn issue15388() {
8+
#[rustfmt::skip]
9+
{0; 0;}
10+
//~^ semicolon_inside_block
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Test when the feature `stmt_expr_attributes` is enabled
2+
3+
#![feature(stmt_expr_attributes)]
4+
#![allow(clippy::no_effect)]
5+
#![warn(clippy::semicolon_inside_block)]
6+
7+
pub fn issue15388() {
8+
#[rustfmt::skip]
9+
{0; 0};
10+
//~^ semicolon_inside_block
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: consider moving the `;` inside the block for consistent formatting
2+
--> tests/ui/semicolon_inside_block_stmt_expr_attrs.rs:9:5
3+
|
4+
LL | {0; 0};
5+
| ^^^^^^^
6+
|
7+
= note: `-D clippy::semicolon-inside-block` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::semicolon_inside_block)]`
9+
help: put the `;` here
10+
|
11+
LL - {0; 0};
12+
LL + {0; 0;}
13+
|
14+
15+
error: aborting due to 1 previous error
16+

0 commit comments

Comments
 (0)