Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clippy_lints/src/semicolon_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ impl LateLintPass<'_> for SemicolonBlock {
kind: ExprKind::Block(block, _),
..
}) if !block.span.from_expansion() => {
let attrs = cx.tcx.hir_attrs(stmt.hir_id);
if !attrs.is_empty() && !cx.tcx.features().stmt_expr_attributes() {
return;
}

if let Some(tail) = block.expr {
self.semicolon_inside_block(cx, block, tail, stmt.span);
}
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/semicolon_inside_block.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,8 @@ fn main() {

unit_fn_block()
}

pub fn issue15388() {
#[rustfmt::skip]
{0; 0};
}
5 changes: 5 additions & 0 deletions tests/ui/semicolon_inside_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,8 @@ fn main() {

unit_fn_block()
}

pub fn issue15388() {
#[rustfmt::skip]
{0; 0};
}
11 changes: 11 additions & 0 deletions tests/ui/semicolon_inside_block_stmt_expr_attrs.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Test when the feature `stmt_expr_attributes` is enabled

#![feature(stmt_expr_attributes)]
#![allow(clippy::no_effect)]
#![warn(clippy::semicolon_inside_block)]

pub fn issue15388() {
#[rustfmt::skip]
{0; 0;}
//~^ semicolon_inside_block
}
11 changes: 11 additions & 0 deletions tests/ui/semicolon_inside_block_stmt_expr_attrs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Test when the feature `stmt_expr_attributes` is enabled

#![feature(stmt_expr_attributes)]
#![allow(clippy::no_effect)]
#![warn(clippy::semicolon_inside_block)]

pub fn issue15388() {
#[rustfmt::skip]
{0; 0};
//~^ semicolon_inside_block
}
16 changes: 16 additions & 0 deletions tests/ui/semicolon_inside_block_stmt_expr_attrs.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: consider moving the `;` inside the block for consistent formatting
--> tests/ui/semicolon_inside_block_stmt_expr_attrs.rs:9:5
|
LL | {0; 0};
| ^^^^^^^
|
= note: `-D clippy::semicolon-inside-block` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::semicolon_inside_block)]`
help: put the `;` here
|
LL - {0; 0};
LL + {0; 0;}
|

error: aborting due to 1 previous error