diff options
| author | Gary Guo <gary@garyguo.net> | 2021-08-14 21:54:17 +0100 |
|---|---|---|
| committer | Gary Guo <gary@garyguo.net> | 2021-08-14 22:58:04 +0100 |
| commit | 2969aece415baa1a42df2a06ba635311000a2b5b (patch) | |
| tree | c9abfdda26f378f5bc6345d4086b567cfa3a7052 | |
| parent | a59e8853148c6a26ed583cccd0f1c3fc50444c9c (diff) | |
| download | rust-2969aece415baa1a42df2a06ba635311000a2b5b.tar.gz rust-2969aece415baa1a42df2a06ba635311000a2b5b.zip | |
Fix dead code warning when inline const is used in pattern
| -rw-r--r-- | compiler/rustc_passes/src/dead.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 4e157b0a574..ae65222f3f2 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -15,6 +15,7 @@ use rustc_middle::middle::privacy; use rustc_middle::ty::{self, DefIdTree, TyCtxt}; use rustc_session::lint; use rustc_span::symbol::{sym, Symbol}; +use std::mem; // Any local node that may call something in its body block should be // explored. For example, if it's a live Node::Item that is a @@ -395,8 +396,14 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> { } fn visit_anon_const(&mut self, c: &'tcx hir::AnonConst) { + // When inline const blocks are used in pattern position, paths + // referenced by it should be considered as used. + let in_pat = mem::replace(&mut self.in_pat, false); + self.live_symbols.insert(self.tcx.hir().local_def_id(c.hir_id)); intravisit::walk_anon_const(self, c); + + self.in_pat = in_pat; } } |
