Skip to content
Open
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
3 changes: 2 additions & 1 deletion clippy_lints/src/unnecessary_semicolon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessarySemicolon {
)
&& cx.typeck_results().expr_ty(expr).is_unit()
// if a stmt has attrs, then turning it into an expr will break the code, since attrs aren't allowed on exprs
&& cx.tcx.hir_attrs(stmt.hir_id).is_empty()
// -- unless the corresponding feature is enabled
&& (cx.tcx.hir_attrs(stmt.hir_id).is_empty() || cx.tcx.features().stmt_expr_attributes())
{
if let Some(block_is_unit) = self.is_last_in_block(stmt) {
if cx.tcx.sess.edition() <= Edition2021 && leaks_droppable_temporary_with_limited_lifetime(cx, expr) {
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/unnecessary_semicolon_feature_stmt_expr_attributes.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![warn(clippy::unnecessary_semicolon)]
#![feature(stmt_expr_attributes)]

fn main() {
// removing the `;` would turn the stmt into an expr, but attrs aren't allowed on exprs
// -- but not with the feature enabled
#[rustfmt::skip]
match 0 {
0b00 => {} 0b01 => {}
0b11 => {} _ => {}
}
//~^ unnecessary_semicolon
}
13 changes: 13 additions & 0 deletions tests/ui/unnecessary_semicolon_feature_stmt_expr_attributes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![warn(clippy::unnecessary_semicolon)]
#![feature(stmt_expr_attributes)]

fn main() {
// removing the `;` would turn the stmt into an expr, but attrs aren't allowed on exprs
// -- but not with the feature enabled
#[rustfmt::skip]
match 0 {
0b00 => {} 0b01 => {}
0b11 => {} _ => {}
};
//~^ unnecessary_semicolon
}
11 changes: 11 additions & 0 deletions tests/ui/unnecessary_semicolon_feature_stmt_expr_attributes.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: unnecessary semicolon
--> tests/ui/unnecessary_semicolon_feature_stmt_expr_attributes.rs:11:6
|
LL | };
| ^ help: remove
|
= note: `-D clippy::unnecessary-semicolon` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_semicolon)]`

error: aborting due to 1 previous error