Skip to content

Commit

Permalink
Handle all PatExprs in dead code analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jan 29, 2025
1 parent 8f09abb commit 559648a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
17 changes: 12 additions & 5 deletions compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_errors::MultiSpan;
use rustc_hir::def::{CtorOf, DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{self as hir, Node, PatExpr, PatExprKind, PatKind, TyKind};
use rustc_hir::{self as hir, Node, PatKind, TyKind};
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::middle::privacy::Level;
use rustc_middle::query::Providers;
Expand Down Expand Up @@ -636,10 +636,6 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
let res = self.typeck_results().qpath_res(path, pat.hir_id);
self.handle_field_pattern_match(pat, res, fields);
}
PatKind::Expr(PatExpr { kind: PatExprKind::Path(ref qpath), hir_id, .. }) => {
let res = self.typeck_results().qpath_res(qpath, *hir_id);
self.handle_res(res);
}
PatKind::TupleStruct(ref qpath, fields, dotdot) => {
let res = self.typeck_results().qpath_res(qpath, pat.hir_id);
self.handle_tuple_field_pattern_match(pat, res, fields, dotdot);
Expand All @@ -651,6 +647,17 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
self.in_pat = false;
}

fn visit_pat_expr(&mut self, expr: &'tcx rustc_hir::PatExpr<'tcx>) {
match &expr.kind {
rustc_hir::PatExprKind::Path(qpath) => {
let res = self.typeck_results().qpath_res(qpath, expr.hir_id);
self.handle_res(res);
}
_ => {}
}
intravisit::walk_pat_expr(self, expr);
}

fn visit_path(&mut self, path: &hir::Path<'tcx>, _: hir::HirId) {
self.handle_res(path.res);
intravisit::walk_path(self, path);
Expand Down
4 changes: 3 additions & 1 deletion tests/ui/pattern/issue-110508.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//@ run-pass

#![deny(dead_code)]

#[derive(PartialEq, Eq)]
Expand All @@ -11,7 +13,7 @@ impl Foo {
const A2: Foo = Self::FooA(());
const A3: Self = Foo::FooA(());
const A4: Self = Self::FooA(());
const A5: u32 = 1; //~ ERROR: dead_code
const A5: u32 = 1;
}

fn main() {
Expand Down
17 changes: 0 additions & 17 deletions tests/ui/pattern/issue-110508.stderr

This file was deleted.

0 comments on commit 559648a

Please sign in to comment.