1
Fork 0

Rollup merge of #132936 - surechen:fix_131989, r=Nadrieril

For expr `return (_ = 42);` unused_paren lint should not be triggered

fixes #131989
This commit is contained in:
Guillaume Gomez 2024-11-15 23:38:09 +01:00 committed by GitHub
commit 1f83a4de1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 189 additions and 40 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,6 +1069,9 @@ impl UnusedDelimLint for UnusedParens {
_,
_,
) if node.is_lazy()))
&& !((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)
}