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:
commit
306d4e39de
4 changed files with 30 additions and 1 deletions
|
|
@ -86,7 +86,9 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessarySemicolon {
|
|||
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 => {} _ => {}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 => {} _ => {}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue