1
Fork 0

Adding BreakValue to UnusedDelimsCtx to make UnusedParens and UnusedBraces checking break

This commit is contained in:
surechen 2024-11-14 09:08:56 +08:00
parent 33d3c27d38
commit 3a74bce72e
13 changed files with 182 additions and 44 deletions

View file

@ -584,6 +584,7 @@ enum UnusedDelimsCtx {
MatchScrutineeExpr,
ReturnValue,
BlockRetValue,
BreakValue,
LetScrutineeExpr,
ArrayLenExpr,
AnonConst,
@ -605,6 +606,7 @@ impl From<UnusedDelimsCtx> for &'static str {
UnusedDelimsCtx::MatchScrutineeExpr => "`match` scrutinee expression",
UnusedDelimsCtx::ReturnValue => "`return` value",
UnusedDelimsCtx::BlockRetValue => "block return value",
UnusedDelimsCtx::BreakValue => "`break` value",
UnusedDelimsCtx::LetScrutineeExpr => "`let` scrutinee expression",
UnusedDelimsCtx::ArrayLenExpr | UnusedDelimsCtx::AnonConst => "const expression",
UnusedDelimsCtx::MatchArmExpr => "match arm expression",
@ -913,6 +915,10 @@ trait UnusedDelimLint {
(value, UnusedDelimsCtx::ReturnValue, false, Some(left), None, true)
}
Break(_, Some(ref value)) => {
(value, UnusedDelimsCtx::BreakValue, false, None, None, true)
}
Index(_, ref value, _) => (value, UnusedDelimsCtx::IndexExpr, false, None, None, false),
Assign(_, ref value, _) | AssignOp(.., ref value) => {
@ -1063,7 +1069,8 @@ impl UnusedDelimLint for UnusedParens {
_,
_,
) if node.is_lazy()))
&& !(ctx == UnusedDelimsCtx::ReturnValue
&& !((ctx == UnusedDelimsCtx::ReturnValue
|| ctx == UnusedDelimsCtx::BreakValue)
&& matches!(inner.kind, ast::ExprKind::Assign(_, _, _)))
{
self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos, is_kw)