Skip to content

Commit b7ea5d8

Browse files
committed
Track lifetimes_res_map per owner
1 parent 5b37028 commit b7ea5d8

5 files changed

Lines changed: 21 additions & 26 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
@@ -1603,7 +1598,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16031598

16041599
None => {
16051600
let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
1606-
self.resolver.get_lifetime_res(t.id)
1601+
self.owner.get_lifetime_res(t.id)
16071602
{
16081603
assert_eq!(start.plus(1), end);
16091604
start
@@ -2012,7 +2007,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
20122007
source: LifetimeSource,
20132008
syntax: LifetimeSyntax,
20142009
) -> &'hir hir::Lifetime {
2015-
let res = if let Some(res) = self.resolver.get_lifetime_res(id) {
2010+
let res = if let Some(res) = self.owner.get_lifetime_res(id) {
20162011
match res {
20172012
LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param),
20182013
LifetimeRes::Fresh { param, .. } => {
@@ -2098,13 +2093,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
20982093
// AST resolution emitted an error on those parameters, so we lower them using
20992094
// `ParamName::Error`.
21002095
let ident = self.lower_ident(param.ident);
2101-
let param_name = if let Some(LifetimeRes::Error(..)) =
2102-
self.resolver.get_lifetime_res(param.id)
2103-
{
2104-
ParamName::Error(ident)
2105-
} else {
2106-
ParamName::Plain(ident)
2107-
};
2096+
let param_name =
2097+
if let Some(LifetimeRes::Error(..)) = self.owner.get_lifetime_res(param.id) {
2098+
ParamName::Error(ident)
2099+
} else {
2100+
ParamName::Plain(ident)
2101+
};
21082102
let kind =
21092103
hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit };
21102104

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
@@ -211,6 +211,8 @@ pub struct PerOwnerResolverData {
211211
/// Resolutions for labels.
212212
/// Maps from NodeId of the break/continue expression to the NodeId of their corresponding blocks or loops.
213213
pub label_res_map: NodeMap<ast::NodeId> = Default::default(),
214+
/// Resolutions for lifetimes.
215+
pub lifetimes_res_map: NodeMap<LifetimeRes> = Default::default(),
214216

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

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

compiler/rustc_resolve/src/late.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,7 +2406,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
24062406
/// Define a new lifetime (e.g. in generics)
24072407
#[instrument(level = "debug", skip(self))]
24082408
fn record_lifetime_def(&mut self, id: NodeId, res: LifetimeRes) {
2409-
if let Some(prev_res) = self.r.lifetimes_res_map.insert(id, res) {
2409+
if let Some(prev_res) = self.r.current_owner.lifetimes_res_map.insert(id, res) {
24102410
panic!(
24112411
"lifetime parameter {id:?} resolved multiple times ({prev_res:?} before, {res:?} now)"
24122412
)
@@ -2611,11 +2611,11 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
26112611
let lt_id = if let Some(lt) = lt {
26122612
lt.id
26132613
} else {
2614-
let res = self.r.lifetimes_res_map[&ty.id];
2614+
let res = self.r.current_owner.lifetimes_res_map[&ty.id];
26152615
let LifetimeRes::ElidedAnchor { start, .. } = res else { bug!() };
26162616
start
26172617
};
2618-
let lt_res = self.r.lifetimes_res_map[&lt_id];
2618+
let lt_res = self.r.current_owner.lifetimes_res_map[&lt_id];
26192619
trace!("FindReferenceVisitor inserting res={:?}", lt_res);
26202620
self.lifetime.insert(lt_res);
26212621
}

compiler/rustc_resolve/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ use rustc_feature::BUILTIN_ATTRIBUTES;
5353
use rustc_hir::attrs::StrippedCfgItem;
5454
use rustc_hir::def::Namespace::{self, *};
5555
use rustc_hir::def::{
56-
self, CtorOf, DefKind, DocLinkResMap, LifetimeRes, MacroKinds, NonMacroAttrKind, PartialRes,
57-
PerNS,
56+
self, CtorOf, DefKind, DocLinkResMap, MacroKinds, NonMacroAttrKind, PartialRes, PerNS,
5857
};
5958
use rustc_hir::def_id::{CRATE_DEF_ID, CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalDefIdMap};
6059
use rustc_hir::definitions::{PerParentDisambiguatorState, PerParentDisambiguatorsMap};
@@ -1369,8 +1368,6 @@ pub struct Resolver<'ra, 'tcx> {
13691368
import_res_map: NodeMap<PerNS<Option<Res>>> = Default::default(),
13701369
/// An import will be inserted into this map if it has been used.
13711370
import_use_map: FxHashMap<Import<'ra>, Used> = default::fx_hash_map(),
1372-
/// Resolutions for lifetimes.
1373-
lifetimes_res_map: NodeMap<LifetimeRes> = Default::default(),
13741371
/// Lifetime parameters that lowering will have to introduce.
13751372
extra_lifetime_params_map: NodeMap<Vec<(Ident, NodeId, MissingLifetimeKind)>> = Default::default(),
13761373

@@ -2001,7 +1998,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20011998
let ast_lowering = ty::ResolverAstLowering {
20021999
partial_res_map: self.partial_res_map,
20032000
import_res_map: self.import_res_map,
2004-
lifetimes_res_map: self.lifetimes_res_map,
20052001
extra_lifetime_params_map: self.extra_lifetime_params_map,
20062002
next_node_id: self.next_node_id,
20072003
owners: self.owners,

0 commit comments

Comments
 (0)