Skip to content

Commit 2969aec

Browse files
committed
Fix dead code warning when inline const is used in pattern
1 parent a59e885 commit 2969aec

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

compiler/rustc_passes/src/dead.rs

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_middle::middle::privacy;
1515
use rustc_middle::ty::{self, DefIdTree, TyCtxt};
1616
use rustc_session::lint;
1717
use rustc_span::symbol::{sym, Symbol};
18+
use std::mem;
1819

1920
// Any local node that may call something in its body block should be
2021
// explored. For example, if it's a live Node::Item that is a
@@ -395,8 +396,14 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
395396
}
396397

397398
fn visit_anon_const(&mut self, c: &'tcx hir::AnonConst) {
399+
// When inline const blocks are used in pattern position, paths
400+
// referenced by it should be considered as used.
401+
let in_pat = mem::replace(&mut self.in_pat, false);
402+
398403
self.live_symbols.insert(self.tcx.hir().local_def_id(c.hir_id));
399404
intravisit::walk_anon_const(self, c);
405+
406+
self.in_pat = in_pat;
400407
}
401408
}
402409

0 commit comments

Comments
 (0)