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:
commit
1f83a4de1f
13 changed files with 189 additions and 40 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue