1
Fork 0

reduce false positives on some common cases from if-let-rescope

This commit is contained in:
Ding Xiang Fei 2024-12-02 18:27:09 +08:00
parent 76f3ff6059
commit 2d61c0906a
No known key found for this signature in database
GPG key ID: 3CD748647EEF6359
4 changed files with 47 additions and 40 deletions

View file

@ -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