Skip to content

Commit b69baba

Browse files
committed
Track lifetimes_res_map per owner
1 parent 87c7663 commit b69baba

5 files changed

Lines changed: 21 additions & 25 deletions

File tree

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,6 @@ impl<'tcx> ResolverAstLowering<'tcx> {
293293
self.import_res_map.get(&id).copied().unwrap_or_default()
294294
}
295295

296-
/// Obtains resolution for a lifetime with the given `NodeId`.
297-
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes> {
298-
self.lifetimes_res_map.get(&id).copied()
299-
}
300-
301296
/// Obtain the list of lifetimes parameters to add to an item.
302297
///
303298
/// Extra lifetime parameters should only be added in places that can appear
@@ -1616,7 +1611,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16161611

16171612
None => {
16181613
let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
1619-
self.resolver.get_lifetime_res(t.id)
1614+
self.owner.get_lifetime_res(t.id)
16201615
{
16211616
assert_eq!(start.plus(1), end);
16221617
start
@@ -2025,7 +2020,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
20252020
source: LifetimeSource,
20262021
syntax: LifetimeSyntax,
20272022
) -> &'hir hir::Lifetime {
2028-
let res = if let Some(res) = self.resolver.get_lifetime_res(id) {
2023+
let res = if let Some(res) = self.owner.get_lifetime_res(id) {
20292024
match res {
20302025
LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param),
20312026
LifetimeRes::Fresh { param, .. } => {
@@ -2111,13 +2106,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
21112106
// AST resolution emitted an error on those parameters, so we lower them using
21122107
// `ParamName::Error`.
21132108
let ident = self.lower_ident(param.ident);
2114-
let param_name = if let Some(LifetimeRes::Error(..)) =
2115-
self.resolver.get_lifetime_res(param.id)
2116-
{
2117-
ParamName::Error(ident)
2118-
} else {
2119-
ParamName::Plain(ident)
2120-
};
2109+
let param_name =
2110+
if let Some(LifetimeRes::Error(..)) = self.owner.get_lifetime_res(param.id) {
2111+
ParamName::Error(ident)
2112+
} else {
2113+
ParamName::Plain(ident)
2114+
};
21212115
let kind =
21222116
hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit };
21232117

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use super::errors::{
1717
};
1818
use super::{
1919
AllowReturnTypeNotation, GenericArgsCtor, GenericArgsMode, ImplTraitContext, ImplTraitPosition,
20-
LifetimeRes, LoweringContext, ParamMode, ResolverAstLoweringExt,
20+
LifetimeRes, LoweringContext, ParamMode,
2121
};
2222

2323
impl<'hir> LoweringContext<'_, 'hir> {
@@ -422,7 +422,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
422422
segment_ident_span: Span,
423423
generic_args: &mut GenericArgsCtor<'hir>,
424424
) {
425-
let (start, end) = match self.resolver.get_lifetime_res(segment_id) {
425+
let (start, end) = match self.owner.get_lifetime_res(segment_id) {
426426
Some(LifetimeRes::ElidedAnchor { start, end }) => (start, end),
427427
None => return,
428428
Some(res) => {

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ pub struct PerOwnerResolverData {
212212
/// Resolutions for labels.
213213
/// Maps from NodeId of the break/continue expression to the NodeId of their corresponding blocks or loops.
214214
pub label_res_map: NodeMap<ast::NodeId> = Default::default(),
215+
/// Resolutions for lifetimes.
216+
pub lifetimes_res_map: NodeMap<LifetimeRes> = Default::default(),
215217

216218
/// The id of the owner
217219
pub id: ast::NodeId,
@@ -228,6 +230,11 @@ impl PerOwnerResolverData {
228230
pub fn get_label_res(&self, id: ast::NodeId) -> Option<ast::NodeId> {
229231
self.label_res_map.get(&id).copied()
230232
}
233+
234+
/// Obtains resolution for a lifetime with the given `NodeId`.
235+
pub fn get_lifetime_res(&self, id: ast::NodeId) -> Option<LifetimeRes> {
236+
self.lifetimes_res_map.get(&id).copied()
237+
}
231238
}
232239

233240
/// Resolutions that should only be used for lowering.
@@ -238,8 +245,6 @@ pub struct ResolverAstLowering<'tcx> {
238245
pub partial_res_map: NodeMap<hir::def::PartialRes>,
239246
/// Resolutions for import nodes, which have multiple resolutions in different namespaces.
240247
pub import_res_map: NodeMap<hir::def::PerNS<Option<Res<ast::NodeId>>>>,
241-
/// Resolutions for lifetimes.
242-
pub lifetimes_res_map: NodeMap<LifetimeRes>,
243248
/// Lifetime parameters that lowering will have to introduce.
244249
pub extra_lifetime_params_map: NodeMap<Vec<(Ident, ast::NodeId, LifetimeRes)>>,
245250

compiler/rustc_resolve/src/late.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,7 +2412,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
24122412
res: LifetimeRes,
24132413
candidate: LifetimeElisionCandidate,
24142414
) {
2415-
if let Some(prev_res) = self.r.lifetimes_res_map.insert(id, res) {
2415+
if let Some(prev_res) = self.r.current_owner.lifetimes_res_map.insert(id, res) {
24162416
panic!("lifetime {id:?} resolved multiple times ({prev_res:?} before, {res:?} now)")
24172417
}
24182418

@@ -2428,7 +2428,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
24282428

24292429
#[instrument(level = "debug", skip(self))]
24302430
fn record_lifetime_param(&mut self, id: NodeId, res: LifetimeRes) {
2431-
if let Some(prev_res) = self.r.lifetimes_res_map.insert(id, res) {
2431+
if let Some(prev_res) = self.r.current_owner.lifetimes_res_map.insert(id, res) {
24322432
panic!(
24332433
"lifetime parameter {id:?} resolved multiple times ({prev_res:?} before, {res:?} now)"
24342434
)
@@ -2637,11 +2637,11 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
26372637
let lt_id = if let Some(lt) = lt {
26382638
lt.id
26392639
} else {
2640-
let res = self.r.lifetimes_res_map[&ty.id];
2640+
let res = self.r.current_owner.lifetimes_res_map[&ty.id];
26412641
let LifetimeRes::ElidedAnchor { start, .. } = res else { bug!() };
26422642
start
26432643
};
2644-
let lt_res = self.r.lifetimes_res_map[&lt_id];
2644+
let lt_res = self.r.current_owner.lifetimes_res_map[&lt_id];
26452645
trace!("FindReferenceVisitor inserting res={:?}", lt_res);
26462646
self.lifetime.insert(lt_res);
26472647
}

compiler/rustc_resolve/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,8 +1380,6 @@ pub struct Resolver<'ra, 'tcx> {
13801380
import_res_map: NodeMap<PerNS<Option<Res>>> = Default::default(),
13811381
/// An import will be inserted into this map if it has been used.
13821382
import_use_map: FxHashMap<Import<'ra>, Used> = default::fx_hash_map(),
1383-
/// Resolutions for lifetimes.
1384-
lifetimes_res_map: NodeMap<LifetimeRes> = Default::default(),
13851383
/// Lifetime parameters that lowering will have to introduce.
13861384
extra_lifetime_params_map: NodeMap<Vec<(Ident, NodeId, LifetimeRes)>> = Default::default(),
13871385

@@ -2013,7 +2011,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20132011
let ast_lowering = ty::ResolverAstLowering {
20142012
partial_res_map: self.partial_res_map,
20152013
import_res_map: self.import_res_map,
2016-
lifetimes_res_map: self.lifetimes_res_map,
20172014
extra_lifetime_params_map: self.extra_lifetime_params_map,
20182015
next_node_id: self.next_node_id,
20192016
owners: self.owners,

0 commit comments

Comments
 (0)