@@ -651,9 +651,11 @@ trait UnusedDelimLint {
651
651
652
652
fn is_expr_delims_necessary(
653
653
inner: &ast::Expr,
654
+ ctx: UnusedDelimsCtx,
654
655
followed_by_block: bool,
655
- followed_by_else: bool,
656
656
) -> bool {
657
+ let followed_by_else = ctx == UnusedDelimsCtx::AssignedValueLetElse;
658
+
657
659
if followed_by_else {
658
660
match inner.kind {
659
661
ast::ExprKind::Binary(op, ..) if op.node.is_lazy() => return true,
@@ -662,6 +664,13 @@ trait UnusedDelimLint {
662
664
}
663
665
}
664
666
667
+ // Check it's range in LetScrutineeExpr
668
+ if let ast::ExprKind::Range(..) = inner.kind
669
+ && matches!(ctx, UnusedDelimsCtx::LetScrutineeExpr)
670
+ {
671
+ return true;
672
+ }
673
+
665
674
// Check if LHS needs parens to prevent false-positives in cases like `fn x() -> u8 { ({ 0 } + 1) }`.
666
675
{
667
676
let mut innermost = inner;
@@ -1007,8 +1016,7 @@ impl UnusedDelimLint for UnusedParens {
1007
1016
) {
1008
1017
match value.kind {
1009
1018
ast::ExprKind::Paren(ref inner) => {
1010
- let followed_by_else = ctx == UnusedDelimsCtx::AssignedValueLetElse;
1011
- if !Self::is_expr_delims_necessary(inner, followed_by_block, followed_by_else)
1019
+ if !Self::is_expr_delims_necessary(inner, ctx, followed_by_block)
1012
1020
&& value.attrs.is_empty()
1013
1021
&& !value.span.from_expansion()
1014
1022
&& (ctx != UnusedDelimsCtx::LetScrutineeExpr
@@ -1334,7 +1342,7 @@ impl UnusedDelimLint for UnusedBraces {
1334
1342
// FIXME(const_generics): handle paths when #67075 is fixed.
1335
1343
if let [stmt] = inner.stmts.as_slice() {
1336
1344
if let ast::StmtKind::Expr(ref expr) = stmt.kind {
1337
- if !Self::is_expr_delims_necessary(expr, followed_by_block, false )
1345
+ if !Self::is_expr_delims_necessary(expr, ctx, followed_by_block )
1338
1346
&& (ctx != UnusedDelimsCtx::AnonConst
1339
1347
|| (matches!(expr.kind, ast::ExprKind::Lit(_))
1340
1348
&& !expr.span.from_expansion()))
0 commit comments