fix unnecessary_semicolon: don't lint on stmts with attrs
This commit is contained in:
parent
874f1c8dc0
commit
af2dd2d3bc
4 changed files with 29 additions and 0 deletions
|
|
@ -87,6 +87,8 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessarySemicolon {
|
|||
ExprKind::If(..) | ExprKind::Match(_, _, MatchSource::Normal | MatchSource::Postfix)
|
||||
)
|
||||
&& cx.typeck_results().expr_ty(expr) == cx.tcx.types.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