diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2023-03-14 18:36:15 +0400 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2023-03-16 17:22:18 +0400 |
| commit | 52c73975b48b49ab6b14896a9d8d6fc665cf85da (patch) | |
| tree | d2488471c25b5687d20b0d309026948ecd5e7acb /compiler/rustc_resolve/src | |
| parent | d99e01fa7eb0dd2344040b3402a0f0961126d87e (diff) | |
| download | rust-52c73975b48b49ab6b14896a9d8d6fc665cf85da.tar.gz rust-52c73975b48b49ab6b14896a9d8d6fc665cf85da.zip | |
resolve: Use `item_name` and `opt_parent` in `Resolver::get_module`
This is a cleanup that doesn't introduce new query calls, but this way `def_key` is decoded twice which may matter for performance or may not
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/build_reduced_graph.rs | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 362ef693c48..a0613962a00 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -27,7 +27,6 @@ use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID}; use rustc_metadata::creader::LoadedMacro; use rustc_middle::metadata::ModChild; use rustc_middle::{bug, ty}; -use rustc_session::cstore::CrateStore; use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::Span; @@ -118,20 +117,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let def_kind = self.cstore().def_kind(def_id); match def_kind { DefKind::Mod | DefKind::Enum | DefKind::Trait => { - let def_key = self.cstore().def_key(def_id); - let parent = def_key.parent.map(|index| { - self.get_nearest_non_block_module(DefId { index, krate: def_id.krate }) - }); - let name = if let Some(cnum) = def_id.as_crate_root() { - self.cstore().crate_name(cnum) - } else { - def_key.disambiguated_data.data.get_opt_name().expect("module without name") - }; - + let parent = self + .tcx + .opt_parent(def_id) + .map(|parent_id| self.get_nearest_non_block_module(parent_id)); let expn_id = self.cstore().module_expansion_untracked(def_id, &self.tcx.sess); Some(self.new_module( parent, - ModuleKind::Def(def_kind, def_id, name), + ModuleKind::Def(def_kind, def_id, self.tcx.item_name(def_id)), expn_id, self.def_span(def_id), // FIXME: Account for `#[no_implicit_prelude]` attributes. |
