about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2025-01-29 08:52:43 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2025-01-29 15:45:13 +0000
commit559648a0a4c942993c321d999f708e64f169b245 (patch)
treeed4ba881e545cfb38b789db6c98442d50f20f327
parent8f09abb49757a65f143c6794fcb22a70945e67d1 (diff)
downloadrust-559648a0a4c942993c321d999f708e64f169b245.tar.gz
rust-559648a0a4c942993c321d999f708e64f169b245.zip
Handle all `PatExpr`s in dead code analysis
-rw-r--r--compiler/rustc_passes/src/dead.rs17
-rw-r--r--tests/ui/pattern/issue-110508.rs4
-rw-r--r--tests/ui/pattern/issue-110508.stderr17
3 files changed, 15 insertions, 23 deletions
diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs
index bc2bebdfef6..95f18eaa7ef 100644
--- a/compiler/rustc_passes/src/dead.rs
+++ b/compiler/rustc_passes/src/dead.rs
@@ -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;
@@ -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);
@@ -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);
diff --git a/tests/ui/pattern/issue-110508.rs b/tests/ui/pattern/issue-110508.rs
index 980d8d52f1d..74a8d673e83 100644
--- a/tests/ui/pattern/issue-110508.rs
+++ b/tests/ui/pattern/issue-110508.rs
@@ -1,3 +1,5 @@
+//@ run-pass
+
 #![deny(dead_code)]
 
 #[derive(PartialEq, Eq)]
@@ -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() {
diff --git a/tests/ui/pattern/issue-110508.stderr b/tests/ui/pattern/issue-110508.stderr
deleted file mode 100644
index aaec9116769..00000000000
--- a/tests/ui/pattern/issue-110508.stderr
+++ /dev/null
@@ -1,17 +0,0 @@
-error: associated constant `A5` is never used
-  --> $DIR/issue-110508.rs:14:11
-   |
-LL | impl Foo {
-   | -------- associated constant in this implementation
-...
-LL |     const A5: u32 = 1;
-   |           ^^
-   |
-note: the lint level is defined here
-  --> $DIR/issue-110508.rs:1:9
-   |
-LL | #![deny(dead_code)]
-   |         ^^^^^^^^^
-
-error: aborting due to 1 previous error
-