diff options
| author | Ding Xiang Fei <dingxiangfei2009@protonmail.ch> | 2024-12-02 18:27:09 +0800 |
|---|---|---|
| committer | Ding Xiang Fei <dingxiangfei2009@protonmail.ch> | 2024-12-02 18:30:29 +0800 |
| commit | 2d61c0906a31ff1310603ee13582c05f29aa1190 (patch) | |
| tree | 295c5e346279965e03d4986153e6123e9df1728f /compiler | |
| parent | 76f3ff605962d7046bc1537597ceed5e12325f54 (diff) | |
| download | rust-2d61c0906a31ff1310603ee13582c05f29aa1190.tar.gz rust-2d61c0906a31ff1310603ee13582c05f29aa1190.zip | |
reduce false positives on some common cases from if-let-rescope
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_lint/src/if_let_rescope.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/compiler/rustc_lint/src/if_let_rescope.rs b/compiler/rustc_lint/src/if_let_rescope.rs index 0e874669043..2db229ed133 100644 --- a/compiler/rustc_lint/src/if_let_rescope.rs +++ b/compiler/rustc_lint/src/if_let_rescope.rs @@ -103,8 +103,11 @@ fn expr_parent_is_else(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool { } fn expr_parent_is_stmt(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool { - let Some((_, hir::Node::Stmt(stmt))) = tcx.hir().parent_iter(hir_id).next() else { - return false; + let mut parents = tcx.hir().parent_iter(hir_id); + let stmt = match parents.next() { + Some((_, hir::Node::Stmt(stmt))) => stmt, + Some((_, hir::Node::Block(_) | hir::Node::Arm(_))) => return true, + _ => return false, }; let (hir::StmtKind::Semi(expr) | hir::StmtKind::Expr(expr)) = stmt.kind else { return false }; expr.hir_id == hir_id |
