diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 211bcb9da94db..2f1d3fb1d35a2 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -173,7 +173,7 @@ impl<'tcx> Queries<'tcx> { feed.crate_for_resolver(tcx.arena.alloc(Steal::new((krate, pre_configured_attrs)))); feed.output_filenames(Arc::new(outputs)); - let feed = tcx.feed_local_def_id(CRATE_DEF_ID); + let feed = tcx.feed_local_crate_def_id(); feed.def_kind(DefKind::Mod); }); Ok(qcx) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index cc734e7157fa4..2e31e8b17b779 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -62,7 +62,7 @@ use rustc_session::config::CrateType; use rustc_session::cstore::{CrateStoreDyn, Untracked}; use rustc_session::lint::Lint; use rustc_session::{Limit, MetadataKind, Session}; -use rustc_span::def_id::{DefPathHash, StableCrateId}; +use rustc_span::def_id::{DefPathHash, StableCrateId, CRATE_DEF_ID}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; use rustc_target::abi::{FieldIdx, Layout, LayoutS, TargetDataLayout, VariantIdx}; @@ -76,6 +76,7 @@ use std::cmp::Ordering; use std::fmt; use std::hash::{Hash, Hasher}; use std::iter; +use std::marker::PhantomData; use std::mem; use std::ops::{Bound, Deref}; @@ -522,6 +523,23 @@ pub struct TyCtxtFeed<'tcx, KEY: Copy> { key: KEY, } +/// The same as `TyCtxtFeed`, but does not contain a `TyCtxt`. +/// Use this to pass around when you have a `TyCtxt` elsewhere. +/// Just an optimization to save space and not store hundreds of +/// `TyCtxtFeed` in the resolver. +#[derive(Copy, Clone)] +pub struct Feed<'tcx, KEY: Copy> { + _tcx: PhantomData>, + // Do not allow direct access, as downstream code must not mutate this field. + key: KEY, +} + +impl fmt::Debug for Feed<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.key.fmt(f) + } +} + impl<'tcx> TyCtxt<'tcx> { pub fn feed_unit_query(self) -> TyCtxtFeed<'tcx, ()> { TyCtxtFeed { tcx: self, key: () } @@ -529,8 +547,9 @@ impl<'tcx> TyCtxt<'tcx> { pub fn feed_local_crate(self) -> TyCtxtFeed<'tcx, CrateNum> { TyCtxtFeed { tcx: self, key: LOCAL_CRATE } } - pub fn feed_local_def_id(self, key: LocalDefId) -> TyCtxtFeed<'tcx, LocalDefId> { - TyCtxtFeed { tcx: self, key } + + pub fn feed_local_crate_def_id(self) -> TyCtxtFeed<'tcx, LocalDefId> { + TyCtxtFeed { tcx: self, key: CRATE_DEF_ID } } /// In order to break cycles involving `AnonConst`, we need to set the expected type by side @@ -547,6 +566,23 @@ impl<'tcx, KEY: Copy> TyCtxtFeed<'tcx, KEY> { pub fn key(&self) -> KEY { self.key } + + #[inline(always)] + pub fn downgrade(self) -> Feed<'tcx, KEY> { + Feed { _tcx: PhantomData, key: self.key } + } +} + +impl<'tcx, KEY: Copy> Feed<'tcx, KEY> { + #[inline(always)] + pub fn key(&self) -> KEY { + self.key + } + + #[inline(always)] + pub fn upgrade(self, tcx: TyCtxt<'tcx>) -> TyCtxtFeed<'tcx, KEY> { + TyCtxtFeed { tcx, key: self.key } + } } impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> { @@ -1091,7 +1127,7 @@ impl<'tcx> TyCtxt<'tcx> { // needs to be re-evaluated. self.dep_graph.read_index(DepNodeIndex::FOREVER_RED_NODE); - let feed = self.feed_local_def_id(def_id); + let feed = TyCtxtFeed { tcx: self, key: def_id }; feed.def_kind(def_kind); // Unique types created for closures participate in type privacy checking. // They have visibilities inherited from the module they are defined in. diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index eea3624898c8c..614d0ccc8133f 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -84,7 +84,8 @@ pub use self::consts::{ Const, ConstData, ConstInt, ConstKind, Expr, ScalarInt, UnevaluatedConst, ValTree, }; pub use self::context::{ - tls, CtxtInterners, DeducedParamAttrs, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, TyCtxtFeed, + tls, CtxtInterners, DeducedParamAttrs, Feed, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, + TyCtxtFeed, }; pub use self::instance::{Instance, InstanceDef, ShortInstance, UnusedGenericParams}; pub use self::list::List; diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 1c4aeefcbcfd0..dd18ab7d9d23e 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -25,6 +25,7 @@ use rustc_hir::def::{self, *}; use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID}; use rustc_metadata::creader::LoadedMacro; use rustc_middle::metadata::ModChild; +use rustc_middle::ty::Feed; use rustc_middle::{bug, ty}; use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; @@ -407,7 +408,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { // Top level use tree reuses the item's id and list stems reuse their parent // use tree's ids, so in both cases their visibilities are already filled. if nested && !list_stem { - self.r.feed_visibility(self.r.local_def_id(id), vis); + self.r.feed_visibility(self.r.feed(id), vis); } let mut prefix_iter = parent_prefix @@ -632,7 +633,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { &mut self, fields: &[ast::FieldDef], ident: Ident, - def_id: LocalDefId, + feed: Feed<'tcx, LocalDefId>, adt_res: Res, adt_vis: ty::Visibility, adt_span: Span, @@ -643,7 +644,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { // Define a name in the type namespace if it is not anonymous. self.r.define(parent, ident, TypeNS, (adt_res, adt_vis, adt_span, expansion)); - self.r.feed_visibility(def_id, adt_vis); + self.r.feed_visibility(feed, adt_vis); + let def_id = feed.key(); // Record field names for error reporting. self.insert_field_def_ids(def_id, fields); @@ -653,14 +655,15 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { match &field.ty.kind { ast::TyKind::AnonStruct(id, nested_fields) | ast::TyKind::AnonUnion(id, nested_fields) => { - let local_def_id = self.r.local_def_id(*id); + let feed = self.r.feed(*id); + let local_def_id = feed.key(); let def_id = local_def_id.to_def_id(); let def_kind = self.r.tcx.def_kind(local_def_id); let res = Res::Def(def_kind, def_id); self.build_reduced_graph_for_struct_variant( &nested_fields, Ident::empty(), - local_def_id, + feed, res, // Anonymous adts inherit visibility from their parent adts. adt_vis, @@ -680,12 +683,13 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { let ident = item.ident; let sp = item.span; let vis = self.resolve_visibility(&item.vis); - let local_def_id = self.r.local_def_id(item.id); + let feed = self.r.feed(item.id); + let local_def_id = feed.key(); let def_id = local_def_id.to_def_id(); let def_kind = self.r.tcx.def_kind(def_id); let res = Res::Def(def_kind, def_id); - self.r.feed_visibility(local_def_id, vis); + self.r.feed_visibility(feed, vis); match item.kind { ItemKind::Use(ref use_tree) => { @@ -762,7 +766,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { self.build_reduced_graph_for_struct_variant( vdata.fields(), ident, - local_def_id, + feed, res, vis, sp, @@ -795,10 +799,11 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { } ret_fields.push(field_vis.to_def_id()); } - let ctor_def_id = self.r.local_def_id(ctor_node_id); + let feed = self.r.feed(ctor_node_id); + let ctor_def_id = feed.key(); let ctor_res = self.res(ctor_def_id); self.r.define(parent, ident, ValueNS, (ctor_res, ctor_vis, sp, expansion)); - self.r.feed_visibility(ctor_def_id, ctor_vis); + self.r.feed_visibility(feed, ctor_vis); // We need the field visibility spans also for the constructor for E0603. self.insert_field_visibilities_local(ctor_def_id.to_def_id(), vdata.fields()); @@ -812,7 +817,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { self.build_reduced_graph_for_struct_variant( vdata.fields(), ident, - local_def_id, + feed, res, vis, sp, @@ -919,7 +924,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { /// Constructs the reduced graph for one foreign item. fn build_reduced_graph_for_foreign_item(&mut self, item: &ForeignItem) { - let local_def_id = self.r.local_def_id(item.id); + let feed = self.r.feed(item.id); + let local_def_id = feed.key(); let def_id = local_def_id.to_def_id(); let ns = match item.kind { ForeignItemKind::Fn(..) => ValueNS, @@ -931,7 +937,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { let expansion = self.parent_scope.expansion; let vis = self.resolve_visibility(&item.vis); self.r.define(parent, item.ident, ns, (self.res(def_id), vis, item.span, expansion)); - self.r.feed_visibility(local_def_id, vis); + self.r.feed_visibility(feed, vis); } fn build_reduced_graph_for_block(&mut self, block: &Block) { @@ -1218,7 +1224,8 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { fn define_macro(&mut self, item: &ast::Item) -> MacroRulesScopeRef<'a> { let parent_scope = self.parent_scope; let expansion = parent_scope.expansion; - let def_id = self.r.local_def_id(item.id); + let feed = self.r.feed(item.id); + let def_id = feed.key(); let (res, ident, span, macro_rules) = match &item.kind { ItemKind::MacroDef(def) => (self.res(def_id), item.ident, item.span, def.macro_rules), ItemKind::Fn(..) => match self.proc_macro_stub(item) { @@ -1269,7 +1276,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { self.r.check_reserved_macro_name(ident, res); self.insert_unused_macro(ident, def_id, item.id); } - self.r.feed_visibility(def_id, vis); + self.r.feed_visibility(feed, vis); let scope = self.r.arenas.alloc_macro_rules_scope(MacroRulesScope::Binding( self.r.arenas.alloc_macro_rules_binding(MacroRulesBinding { parent_macro_rules_scope: parent_scope.macro_rules, @@ -1293,7 +1300,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { self.insert_unused_macro(ident, def_id, item.id); } self.r.define(module, ident, MacroNS, (res, vis, span, expansion)); - self.r.feed_visibility(def_id, vis); + self.r.feed_visibility(feed, vis); self.parent_scope.macro_rules } } @@ -1385,7 +1392,8 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> { } let vis = self.resolve_visibility(&item.vis); - let local_def_id = self.r.local_def_id(item.id); + let feed = self.r.feed(item.id); + let local_def_id = feed.key(); let def_id = local_def_id.to_def_id(); if !(ctxt == AssocCtxt::Impl @@ -1395,7 +1403,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> { // Trait impl item visibility is inherited from its trait when not specified // explicitly. In that case we cannot determine it here in early resolve, // so we leave a hole in the visibility table to be filled later. - self.r.feed_visibility(local_def_id, vis); + self.r.feed_visibility(feed, vis); } if ctxt == AssocCtxt::Trait { @@ -1469,7 +1477,7 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> { self.visit_invoc(sf.id); } else { let vis = self.resolve_visibility(&sf.vis); - self.r.feed_visibility(self.r.local_def_id(sf.id), vis); + self.r.feed_visibility(self.r.feed(sf.id), vis); visit::walk_field_def(self, sf); } } @@ -1487,10 +1495,11 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> { let ident = variant.ident; // Define a name in the type namespace. - let def_id = self.r.local_def_id(variant.id); + let feed = self.r.feed(variant.id); + let def_id = feed.key(); let vis = self.resolve_visibility(&variant.vis); self.r.define(parent, ident, TypeNS, (self.res(def_id), vis, variant.span, expn_id)); - self.r.feed_visibility(def_id, vis); + self.r.feed_visibility(feed, vis); // If the variant is marked as non_exhaustive then lower the visibility to within the crate. let ctor_vis = @@ -1502,10 +1511,11 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> { // Define a constructor name in the value namespace. if let Some(ctor_node_id) = variant.data.ctor_node_id() { - let ctor_def_id = self.r.local_def_id(ctor_node_id); + let feed = self.r.feed(ctor_node_id); + let ctor_def_id = feed.key(); let ctor_res = self.res(ctor_def_id); self.r.define(parent, ident, ValueNS, (ctor_res, ctor_vis, variant.span, expn_id)); - self.r.feed_visibility(ctor_def_id, ctor_vis); + self.r.feed_visibility(feed, ctor_vis); } // Record field names for error reporting. diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index 12bf462a6fdfd..fdceb262fd88e 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -4,6 +4,7 @@ use rustc_ast::*; use rustc_expand::expand::AstFragment; use rustc_hir::def::{CtorKind, CtorOf, DefKind}; use rustc_hir::def_id::LocalDefId; +use rustc_middle::ty::Feed; use rustc_span::hygiene::LocalExpnId; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::Span; @@ -26,26 +27,38 @@ struct DefCollector<'a, 'b, 'tcx> { } impl<'a, 'b, 'tcx> DefCollector<'a, 'b, 'tcx> { - fn create_def( + fn create_def_with_feed( &mut self, node_id: NodeId, name: Symbol, def_kind: DefKind, span: Span, - ) -> LocalDefId { + ) -> Feed<'tcx, LocalDefId> { let parent_def = self.parent_def; debug!( "create_def(node_id={:?}, def_kind={:?}, parent_def={:?})", node_id, def_kind, parent_def ); - self.resolver.create_def( - parent_def, - node_id, - name, - def_kind, - self.expansion.to_expn_id(), - span.with_parent(None), - ) + self.resolver + .create_def( + parent_def, + node_id, + name, + def_kind, + self.expansion.to_expn_id(), + span.with_parent(None), + ) + .downgrade() + } + + fn create_def( + &mut self, + node_id: NodeId, + name: Symbol, + def_kind: DefKind, + span: Span, + ) -> LocalDefId { + self.create_def_with_feed(node_id, name, def_kind, span).key() } fn with_parent(&mut self, parent_def: LocalDefId, f: F) { diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 1cf3fecc28989..9bff7ec473dfc 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -3118,7 +3118,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { ); rustc_middle::ty::Visibility::Public }; - this.r.feed_visibility(this.r.local_def_id(id), vis); + this.r.feed_visibility(this.r.feed(id), vis); }; let Some(binding) = binding else { diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 1c625f49e3e9a..d7ec696d8368d 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -52,7 +52,7 @@ use rustc_middle::metadata::ModChild; use rustc_middle::middle::privacy::EffectiveVisibilities; use rustc_middle::query::Providers; use rustc_middle::span_bug; -use rustc_middle::ty::{self, MainDefinition, RegisteredTools, TyCtxt}; +use rustc_middle::ty::{self, Feed, MainDefinition, RegisteredTools, TyCtxt, TyCtxtFeed}; use rustc_middle::ty::{ResolverGlobalCtxt, ResolverOutputs}; use rustc_query_system::ich::StableHashingContext; use rustc_session::lint::builtin::PRIVATE_MACRO_USE; @@ -1115,7 +1115,7 @@ pub struct Resolver<'a, 'tcx> { next_node_id: NodeId, - node_id_to_def_id: NodeMap, + node_id_to_def_id: NodeMap>, def_id_to_node_id: IndexVec, /// Indices of unnamed struct or variant fields with unresolved attributes. @@ -1231,11 +1231,19 @@ impl<'a, 'tcx> AsMut> for Resolver<'a, 'tcx> { impl<'tcx> Resolver<'_, 'tcx> { fn opt_local_def_id(&self, node: NodeId) -> Option { - self.node_id_to_def_id.get(&node).copied() + self.opt_feed(node).map(|f| f.key()) } fn local_def_id(&self, node: NodeId) -> LocalDefId { - self.opt_local_def_id(node).unwrap_or_else(|| panic!("no entry for node id: `{node:?}`")) + self.feed(node).key() + } + + fn opt_feed(&self, node: NodeId) -> Option> { + self.node_id_to_def_id.get(&node).copied() + } + + fn feed(&self, node: NodeId) -> Feed<'tcx, LocalDefId> { + self.opt_feed(node).unwrap_or_else(|| panic!("no entry for node id: `{node:?}`")) } fn local_def_kind(&self, node: NodeId) -> DefKind { @@ -1251,18 +1259,19 @@ impl<'tcx> Resolver<'_, 'tcx> { def_kind: DefKind, expn_id: ExpnId, span: Span, - ) -> LocalDefId { + ) -> TyCtxtFeed<'tcx, LocalDefId> { let data = def_kind.def_path_data(name); assert!( !self.node_id_to_def_id.contains_key(&node_id), "adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}", node_id, data, - self.tcx.definitions_untracked().def_key(self.node_id_to_def_id[&node_id]), + self.tcx.definitions_untracked().def_key(self.node_id_to_def_id[&node_id].key()), ); // FIXME: remove `def_span` body, pass in the right spans here and call `tcx.at().create_def()` - let def_id = self.tcx.create_def(parent, name, def_kind).def_id(); + let feed = self.tcx.create_def(parent, name, def_kind); + let def_id = feed.def_id(); // Create the definition. if expn_id != ExpnId::root() { @@ -1279,11 +1288,11 @@ impl<'tcx> Resolver<'_, 'tcx> { // we don't need a mapping from `NodeId` to `LocalDefId`. if node_id != ast::DUMMY_NODE_ID { debug!("create_def: def_id_to_node_id[{:?}] <-> {:?}", def_id, node_id); - self.node_id_to_def_id.insert(node_id, def_id); + self.node_id_to_def_id.insert(node_id, feed.downgrade()); } assert_eq!(self.def_id_to_node_id.push(node_id), def_id); - def_id + feed } fn item_generics_num_lifetimes(&self, def_id: DefId) -> usize { @@ -1331,7 +1340,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let mut def_id_to_node_id = IndexVec::default(); assert_eq!(def_id_to_node_id.push(CRATE_NODE_ID), CRATE_DEF_ID); let mut node_id_to_def_id = NodeMap::default(); - node_id_to_def_id.insert(CRATE_NODE_ID, CRATE_DEF_ID); + let crate_feed = tcx.feed_local_crate_def_id().downgrade(); + node_id_to_def_id.insert(CRATE_NODE_ID, crate_feed); let mut invocation_parents = FxHashMap::default(); invocation_parents.insert(LocalExpnId::ROOT, (CRATE_DEF_ID, ImplTraitContext::Existential)); @@ -1482,7 +1492,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let root_parent_scope = ParentScope::module(graph_root, &resolver); resolver.invocation_parent_scopes.insert(LocalExpnId::ROOT, root_parent_scope); - resolver.feed_visibility(CRATE_DEF_ID, ty::Visibility::Public); + resolver.feed_visibility(crate_feed, ty::Visibility::Public); resolver } @@ -1530,9 +1540,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { Default::default() } - fn feed_visibility(&mut self, def_id: LocalDefId, vis: ty::Visibility) { - self.tcx.feed_local_def_id(def_id).visibility(vis.to_def_id()); - self.visibilities_for_hashing.push((def_id, vis)); + fn feed_visibility(&mut self, feed: Feed<'tcx, LocalDefId>, vis: ty::Visibility) { + let feed = feed.upgrade(self.tcx); + feed.visibility(vis.to_def_id()); + self.visibilities_for_hashing.push((feed.def_id(), vis)); } pub fn into_outputs(self) -> ResolverOutputs { @@ -1547,7 +1558,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { self.tcx.feed_local_crate().stripped_cfg_items(self.tcx.arena.alloc_from_iter( self.stripped_cfg_items.into_iter().filter_map(|item| { - let parent_module = self.node_id_to_def_id.get(&item.parent_module)?.to_def_id(); + let parent_module = + self.node_id_to_def_id.get(&item.parent_module)?.key().to_def_id(); Some(StrippedCfgItem { parent_module, name: item.name, cfg: item.cfg }) }), )); @@ -1576,7 +1588,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { lifetimes_res_map: self.lifetimes_res_map, extra_lifetime_params_map: self.extra_lifetime_params_map, next_node_id: self.next_node_id, - node_id_to_def_id: self.node_id_to_def_id, + node_id_to_def_id: self + .node_id_to_def_id + .into_items() + .map(|(k, f)| (k, f.key())) + .collect(), def_id_to_node_id: self.def_id_to_node_id, trait_map: self.trait_map, lifetime_elision_allowed: self.lifetime_elision_allowed,