diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2022-10-19 16:49:21 -0300 |
|---|---|---|
| committer | Santiago Pastorino <spastorino@gmail.com> | 2022-10-19 16:49:39 -0300 |
| commit | fb5475887f8f3641aea994e1f8f8954d1290449a (patch) | |
| tree | 8de7c62e8c2ccdd2b5bfc14ebae87b5580f86d0c | |
| parent | 4b8f4319954ff2642690b9e5cbe4af352d095bf6 (diff) | |
| download | rust-fb5475887f8f3641aea994e1f8f8954d1290449a.tar.gz rust-fb5475887f8f3641aea994e1f8f8954d1290449a.zip | |
Extract orig_opt_local_def_id as a function
| -rw-r--r-- | compiler/rustc_ast_lowering/src/lib.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 724056f7268..ea213385dc6 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -507,6 +507,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } /// Given the id of some node in the AST, finds the `LocalDefId` associated with it by the name + /// resolver (if any). + fn orig_opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> { + self.resolver.node_id_to_def_id.get(&node).map(|local_def_id| *local_def_id) + } + + fn orig_local_def_id(&self, node: NodeId) -> LocalDefId { + self.orig_opt_local_def_id(node) + .unwrap_or_else(|| panic!("no entry for node id: `{:?}`", node)) + } + + /// Given the id of some node in the AST, finds the `LocalDefId` associated with it by the name /// resolver (if any), after applying any remapping from `get_remapped_def_id`. /// /// For example, in a function like `fn foo<'a>(x: &'a u32)`, @@ -520,10 +531,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { /// we would create an opaque type `type FooReturn<'a1> = impl Debug + 'a1`. /// When lowering the `Debug + 'a` bounds, we add a remapping to map `'a` to `'a1`. fn opt_local_def_id(&self, node: NodeId) -> Option<LocalDefId> { - self.resolver - .node_id_to_def_id - .get(&node) - .map(|local_def_id| self.get_remapped_def_id(*local_def_id)) + self.orig_opt_local_def_id(node).map(|local_def_id| self.get_remapped_def_id(local_def_id)) } fn local_def_id(&self, node: NodeId) -> LocalDefId { |
