Skip to content

Commit 1e0155e

Browse files
committed
fix unnecessary_semicolon: FN on #[feature(stmt_expr_attributes)]
inspired by #15476
1 parent 355e4ba commit 1e0155e

4 files changed

+39
-1
lines changed

clippy_lints/src/unnecessary_semicolon.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessarySemicolon {
8888
)
8989
&& cx.typeck_results().expr_ty(expr).is_unit()
9090
// if a stmt has attrs, then turning it into an expr will break the code, since attrs aren't allowed on exprs
91-
&& cx.tcx.hir_attrs(stmt.hir_id).is_empty()
91+
// -- unless the corresponding feature is enabled
92+
&& (cx.tcx.hir_attrs(stmt.hir_id).is_empty() || cx.tcx.features().stmt_expr_attributes())
9293
{
9394
if let Some(block_is_unit) = self.is_last_in_block(stmt) {
9495
if cx.tcx.sess.edition() <= Edition2021 && leaks_droppable_temporary_with_limited_lifetime(cx, expr) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![warn(clippy::unnecessary_semicolon)]
2+
#![feature(stmt_expr_attributes)]
3+
4+
fn main() {
5+
// removing the `;` would turn the stmt into an expr, but attrs aren't allowed on exprs
6+
// -- but not with the feature enabled
7+
#[rustfmt::skip]
8+
match 0 {
9+
0b00 => {} 0b01 => {}
10+
0b11 => {} _ => {}
11+
}
12+
//~^ unnecessary_semicolon
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![warn(clippy::unnecessary_semicolon)]
2+
#![feature(stmt_expr_attributes)]
3+
4+
fn main() {
5+
// removing the `;` would turn the stmt into an expr, but attrs aren't allowed on exprs
6+
// -- but not with the feature enabled
7+
#[rustfmt::skip]
8+
match 0 {
9+
0b00 => {} 0b01 => {}
10+
0b11 => {} _ => {}
11+
};
12+
//~^ unnecessary_semicolon
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: unnecessary semicolon
2+
--> tests/ui/unnecessary_semicolon_feature_stmt_expr_attributes.rs:11:6
3+
|
4+
LL | };
5+
| ^ help: remove
6+
|
7+
= note: `-D clippy::unnecessary-semicolon` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_semicolon)]`
9+
10+
error: aborting due to 1 previous error
11+

0 commit comments

Comments
 (0)