diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 433b177b055d..a28cb068aa4a 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -293,11 +293,6 @@ fn get_import_res(&self, id: NodeId) -> PerNS>> { self.import_res_map.get(&id).copied().unwrap_or_default() } - /// Obtains resolution for a lifetime with the given `NodeId`. - fn get_lifetime_res(&self, id: NodeId) -> Option { - self.lifetimes_res_map.get(&id).copied() - } - /// Obtain the list of lifetimes parameters to add to an item. /// /// Extra lifetime parameters should only be added in places that can appear @@ -1616,7 +1611,7 @@ fn lower_ty_direct_lifetime( None => { let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) = - self.resolver.get_lifetime_res(t.id) + self.owner.get_lifetime_res(t.id) { assert_eq!(start.plus(1), end); start @@ -2025,7 +2020,7 @@ fn new_named_lifetime( source: LifetimeSource, syntax: LifetimeSyntax, ) -> &'hir hir::Lifetime { - let res = if let Some(res) = self.resolver.get_lifetime_res(id) { + let res = if let Some(res) = self.owner.get_lifetime_res(id) { match res { LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param), LifetimeRes::Fresh { param, .. } => { @@ -2111,13 +2106,12 @@ fn lower_generic_param_kind( // AST resolution emitted an error on those parameters, so we lower them using // `ParamName::Error`. let ident = self.lower_ident(param.ident); - let param_name = if let Some(LifetimeRes::Error(..)) = - self.resolver.get_lifetime_res(param.id) - { - ParamName::Error(ident) - } else { - ParamName::Plain(ident) - }; + let param_name = + if let Some(LifetimeRes::Error(..)) = self.owner.get_lifetime_res(param.id) { + ParamName::Error(ident) + } else { + ParamName::Plain(ident) + }; let kind = hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit }; diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index ef60dc6fc4f1..f5a306aa9140 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -17,7 +17,7 @@ }; use super::{ AllowReturnTypeNotation, GenericArgsCtor, GenericArgsMode, ImplTraitContext, ImplTraitPosition, - LifetimeRes, LoweringContext, ParamMode, ResolverAstLoweringExt, + LifetimeRes, LoweringContext, ParamMode, }; impl<'hir> LoweringContext<'_, 'hir> { @@ -422,7 +422,7 @@ fn maybe_insert_elided_lifetimes_in_path( segment_ident_span: Span, generic_args: &mut GenericArgsCtor<'hir>, ) { - let (start, end) = match self.resolver.get_lifetime_res(segment_id) { + let (start, end) = match self.owner.get_lifetime_res(segment_id) { Some(LifetimeRes::ElidedAnchor { start, end }) => (start, end), None => return, Some(res) => { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index dc67e0fcf079..591b6f5cfa5c 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -212,6 +212,8 @@ pub struct PerOwnerResolverData { /// Resolutions for labels. /// Maps from NodeId of the break/continue expression to the NodeId of their corresponding blocks or loops. pub label_res_map: NodeMap = Default::default(), + /// Resolutions for lifetimes. + pub lifetimes_res_map: NodeMap = Default::default(), /// The id of the owner pub id: ast::NodeId, @@ -228,6 +230,11 @@ pub fn new(id: ast::NodeId, def_id: LocalDefId) -> PerOwnerResolverData { pub fn get_label_res(&self, id: ast::NodeId) -> Option { self.label_res_map.get(&id).copied() } + + /// Obtains resolution for a lifetime with the given `NodeId`. + pub fn get_lifetime_res(&self, id: ast::NodeId) -> Option { + self.lifetimes_res_map.get(&id).copied() + } } /// Resolutions that should only be used for lowering. @@ -238,8 +245,6 @@ pub struct ResolverAstLowering<'tcx> { pub partial_res_map: NodeMap, /// Resolutions for import nodes, which have multiple resolutions in different namespaces. pub import_res_map: NodeMap>>>, - /// Resolutions for lifetimes. - pub lifetimes_res_map: NodeMap, /// Lifetime parameters that lowering will have to introduce. pub extra_lifetime_params_map: NodeMap>, diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 9a3731e70a68..ee08a2fbcd97 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -2412,7 +2412,7 @@ fn record_lifetime_res( res: LifetimeRes, candidate: LifetimeElisionCandidate, ) { - if let Some(prev_res) = self.r.lifetimes_res_map.insert(id, res) { + if let Some(prev_res) = self.r.current_owner.lifetimes_res_map.insert(id, res) { panic!("lifetime {id:?} resolved multiple times ({prev_res:?} before, {res:?} now)") } @@ -2428,7 +2428,7 @@ fn record_lifetime_res( #[instrument(level = "debug", skip(self))] fn record_lifetime_param(&mut self, id: NodeId, res: LifetimeRes) { - if let Some(prev_res) = self.r.lifetimes_res_map.insert(id, res) { + if let Some(prev_res) = self.r.current_owner.lifetimes_res_map.insert(id, res) { panic!( "lifetime parameter {id:?} resolved multiple times ({prev_res:?} before, {res:?} now)" ) @@ -2637,11 +2637,11 @@ fn visit_ty(&mut self, ty: &'ra Ty) { let lt_id = if let Some(lt) = lt { lt.id } else { - let res = self.r.lifetimes_res_map[&ty.id]; + let res = self.r.current_owner.lifetimes_res_map[&ty.id]; let LifetimeRes::ElidedAnchor { start, .. } = res else { bug!() }; start }; - let lt_res = self.r.lifetimes_res_map[<_id]; + let lt_res = self.r.current_owner.lifetimes_res_map[<_id]; trace!("FindReferenceVisitor inserting res={:?}", lt_res); self.lifetime.insert(lt_res); } diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index b38fad8b09d7..3bfa415bf75d 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -1380,8 +1380,6 @@ pub struct Resolver<'ra, 'tcx> { import_res_map: NodeMap>> = Default::default(), /// An import will be inserted into this map if it has been used. import_use_map: FxHashMap, Used> = default::fx_hash_map(), - /// Resolutions for lifetimes. - lifetimes_res_map: NodeMap = Default::default(), /// Lifetime parameters that lowering will have to introduce. extra_lifetime_params_map: NodeMap> = Default::default(), @@ -2013,7 +2011,6 @@ pub fn into_outputs(self) -> ResolverOutputs<'tcx> { let ast_lowering = ty::ResolverAstLowering { partial_res_map: self.partial_res_map, import_res_map: self.import_res_map, - lifetimes_res_map: self.lifetimes_res_map, extra_lifetime_params_map: self.extra_lifetime_params_map, next_node_id: self.next_node_id, owners: self.owners,