fix unnecessary_semicolon: don't lint on stmts with attrs (#15466)

fixes https://github.com/rust-lang/rust-clippy/issues/15426

changelog: [`unnecessary_semicolon`]: don't lint on statements with
attributes
This commit is contained in:
dswij
2025-08-12 19:56:16 +00:00
committed by GitHub
4 changed files with 30 additions and 1 deletions
+3 -1
View File
@@ -86,7 +86,9 @@ fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &Stmt<'tcx>) {
expr.kind,
ExprKind::If(..) | ExprKind::Match(_, _, MatchSource::Normal | MatchSource::Postfix)
)
&& cx.typeck_results().expr_ty(expr) == cx.tcx.types.unit
&& 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()
{
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) {
@@ -63,3 +63,12 @@ fn issue14100() -> bool {
// cast into the `bool` function return type.
if return true {};
}
fn issue15426(x: u32) {
// removing the `;` would turn the stmt into an expr, but attrs aren't allowed on exprs
#[rustfmt::skip]
match x {
0b00 => {} 0b01 => {}
0b11 => {} _ => {}
};
}
@@ -63,3 +63,12 @@ fn issue14100() -> bool {
// cast into the `bool` function return type.
if return true {};
}
fn issue15426(x: u32) {
// removing the `;` would turn the stmt into an expr, but attrs aren't allowed on exprs
#[rustfmt::skip]
match x {
0b00 => {} 0b01 => {}
0b11 => {} _ => {}
};
}
+9
View File
@@ -63,3 +63,12 @@ fn issue14100() -> bool {
// cast into the `bool` function return type.
if return true {};
}
fn issue15426(x: u32) {
// removing the `;` would turn the stmt into an expr, but attrs aren't allowed on exprs
#[rustfmt::skip]
match x {
0b00 => {} 0b01 => {}
0b11 => {} _ => {}
};
}