Skip to content

Commit 559648a

Browse files
committed
Handle all PatExprs in dead code analysis
1 parent 8f09abb commit 559648a

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

Diff for: compiler/rustc_passes/src/dead.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_errors::MultiSpan;
1313
use rustc_hir::def::{CtorOf, DefKind, Res};
1414
use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId};
1515
use rustc_hir::intravisit::{self, Visitor};
16-
use rustc_hir::{self as hir, Node, PatExpr, PatExprKind, PatKind, TyKind};
16+
use rustc_hir::{self as hir, Node, PatKind, TyKind};
1717
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1818
use rustc_middle::middle::privacy::Level;
1919
use rustc_middle::query::Providers;
@@ -636,10 +636,6 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
636636
let res = self.typeck_results().qpath_res(path, pat.hir_id);
637637
self.handle_field_pattern_match(pat, res, fields);
638638
}
639-
PatKind::Expr(PatExpr { kind: PatExprKind::Path(ref qpath), hir_id, .. }) => {
640-
let res = self.typeck_results().qpath_res(qpath, *hir_id);
641-
self.handle_res(res);
642-
}
643639
PatKind::TupleStruct(ref qpath, fields, dotdot) => {
644640
let res = self.typeck_results().qpath_res(qpath, pat.hir_id);
645641
self.handle_tuple_field_pattern_match(pat, res, fields, dotdot);
@@ -651,6 +647,17 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
651647
self.in_pat = false;
652648
}
653649

650+
fn visit_pat_expr(&mut self, expr: &'tcx rustc_hir::PatExpr<'tcx>) {
651+
match &expr.kind {
652+
rustc_hir::PatExprKind::Path(qpath) => {
653+
let res = self.typeck_results().qpath_res(qpath, expr.hir_id);
654+
self.handle_res(res);
655+
}
656+
_ => {}
657+
}
658+
intravisit::walk_pat_expr(self, expr);
659+
}
660+
654661
fn visit_path(&mut self, path: &hir::Path<'tcx>, _: hir::HirId) {
655662
self.handle_res(path.res);
656663
intravisit::walk_path(self, path);

Diff for: tests/ui/pattern/issue-110508.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//@ run-pass
2+
13
#![deny(dead_code)]
24

35
#[derive(PartialEq, Eq)]
@@ -11,7 +13,7 @@ impl Foo {
1113
const A2: Foo = Self::FooA(());
1214
const A3: Self = Foo::FooA(());
1315
const A4: Self = Self::FooA(());
14-
const A5: u32 = 1; //~ ERROR: dead_code
16+
const A5: u32 = 1;
1517
}
1618

1719
fn main() {

Diff for: tests/ui/pattern/issue-110508.stderr

-17
This file was deleted.

0 commit comments

Comments
 (0)