Skip to content

Commit 5ccf44c

Browse files
committed
Track extra_lifetime_params_map per-owner
1 parent 2d0faf8 commit 5ccf44c

5 files changed

Lines changed: 19 additions & 21 deletions

File tree

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use super::diagnostics::{
2424
use super::stability::{enabled_names, gate_unstable_abi};
2525
use super::{
2626
FnDeclKind, GenericArgsMode, ImplTraitContext, ImplTraitPosition, LoweringContext, ParamMode,
27-
RelaxedBoundForbiddenReason, RelaxedBoundPolicy, ResolverAstLoweringExt,
27+
RelaxedBoundForbiddenReason, RelaxedBoundPolicy,
2828
};
2929
use crate::diagnostics::ConstComptimeFn;
3030

@@ -1878,7 +1878,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18781878
.collect();
18791879

18801880
// Introduce extra lifetimes if late resolution tells us to.
1881-
let extra_lifetimes = self.resolver.extra_lifetime_params(self.owner.id);
1881+
let extra_lifetimes = self.owner.extra_lifetime_params(self.owner.id);
18821882
params.extend(extra_lifetimes.into_iter().map(|&(ident, node_id, kind)| {
18831883
self.lifetime_res_to_generic_param(
18841884
ident,

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -351,17 +351,6 @@ impl<'tcx> ResolverAstLowering<'tcx> {
351351
)
352352
.map(|fn_indexes| fn_indexes.iter().map(|(num, _)| *num).collect())
353353
}
354-
355-
/// Obtain the list of lifetimes parameters to add to an item.
356-
///
357-
/// Extra lifetime parameters should only be added in places that can appear
358-
/// as a `binder` in `LifetimeRes`.
359-
///
360-
/// The extra lifetimes that appear from the parenthesized `Fn`-trait desugaring
361-
/// should appear at the enclosing `PolyTraitRef`.
362-
fn extra_lifetime_params(&self, id: NodeId) -> &[(Ident, NodeId, MissingLifetimeKind)] {
363-
self.extra_lifetime_params_map.get(&id).map_or(&[], |v| &v[..])
364-
}
365354
}
366355

367356
/// How relaxed bounds `?Trait` should be treated.
@@ -1129,7 +1118,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11291118
) -> &'hir [hir::GenericParam<'hir>] {
11301119
// Start by creating params for extra lifetimes params, as this creates the definitions
11311120
// that may be referred to by the AST inside `generic_params`.
1132-
let extra_lifetimes = self.resolver.extra_lifetime_params(binder);
1121+
let extra_lifetimes = self.owner.extra_lifetime_params(binder);
11331122
debug!(?extra_lifetimes);
11341123
let extra_lifetimes: Vec<_> = extra_lifetimes
11351124
.iter()

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_abi::{
2828
Align, FieldIdx, Integer, IntegerType, ReprFlags, ReprOptions, ScalableElt, VariantIdx,
2929
};
3030
use rustc_ast::node_id::NodeMap;
31-
use rustc_ast::{self as ast};
31+
use rustc_ast::{self as ast, NodeId};
3232
pub use rustc_ast_ir::{Movability, Mutability, try_visit};
3333
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
3434
use rustc_data_structures::intern::Interned;
@@ -224,6 +224,8 @@ pub struct PerOwnerResolverData<'tcx> {
224224

225225
/// Resolution for import nodes, which have multiple resolutions in different namespaces.
226226
pub import_res: hir::def::PerNS<Option<Res<ast::NodeId>>> = Default::default(),
227+
/// Lifetime parameters that lowering will have to introduce.
228+
pub extra_lifetime_params_map: NodeMap<Vec<(Ident, ast::NodeId, MissingLifetimeKind)>> = Default::default(),
227229

228230
/// The id of the owner
229231
pub id: ast::NodeId,
@@ -245,6 +247,17 @@ impl<'tcx> PerOwnerResolverData<'tcx> {
245247
pub fn get_lifetime_res(&self, id: ast::NodeId) -> Option<LifetimeRes> {
246248
self.lifetimes_res_map.get(&id).copied()
247249
}
250+
251+
/// Obtain the list of lifetimes parameters to add to an item.
252+
///
253+
/// Extra lifetime parameters should only be added in places that can appear
254+
/// as a `binder` in `LifetimeRes`.
255+
///
256+
/// The extra lifetimes that appear from the parenthesized `Fn`-trait desugaring
257+
/// should appear at the enclosing `PolyTraitRef`.
258+
pub fn extra_lifetime_params(&self, id: NodeId) -> &[(Ident, NodeId, MissingLifetimeKind)] {
259+
self.extra_lifetime_params_map.get(&id).map_or(&[], |v| &v[..])
260+
}
248261
}
249262

250263
/// Resolutions that should only be used for lowering.
@@ -253,8 +266,6 @@ impl<'tcx> PerOwnerResolverData<'tcx> {
253266
pub struct ResolverAstLowering<'tcx> {
254267
/// Resolutions for nodes that have a single resolution.
255268
pub partial_res_map: NodeMap<hir::def::PartialRes>,
256-
/// Lifetime parameters that lowering will have to introduce.
257-
pub extra_lifetime_params_map: NodeMap<Vec<(Ident, ast::NodeId, MissingLifetimeKind)>>,
258269

259270
pub next_node_id: ast::NodeId,
260271

compiler/rustc_resolve/src/late.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
21702170

21712171
// Record the created lifetime parameter so lowering can pick it up and add it to HIR.
21722172
self.r
2173+
.current_owner
21732174
.extra_lifetime_params_map
21742175
.entry(binder)
21752176
.or_insert_with(Vec::new)

compiler/rustc_resolve/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use rustc_hir::def::{
5858
};
5959
use rustc_hir::def_id::{CRATE_DEF_ID, CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalDefIdMap};
6060
use rustc_hir::definitions::{PerParentDisambiguatorState, PerParentDisambiguatorsMap};
61-
use rustc_hir::{MissingLifetimeKind, PrimTy, TraitCandidate, find_attr};
61+
use rustc_hir::{PrimTy, TraitCandidate, find_attr};
6262
use rustc_index::bit_set::DenseBitSet;
6363
use rustc_metadata::creader::CStore;
6464
use rustc_middle::metadata::{AmbigModChild, ModChild, Reexport};
@@ -1336,8 +1336,6 @@ pub struct Resolver<'ra, 'tcx> {
13361336
partial_res_map: NodeMap<PartialRes> = Default::default(),
13371337
/// An import will be inserted into this map if it has been used.
13381338
import_use_map: FxHashMap<Import<'ra>, Used> = default::fx_hash_map(),
1339-
/// Lifetime parameters that lowering will have to introduce.
1340-
extra_lifetime_params_map: NodeMap<Vec<(Ident, NodeId, MissingLifetimeKind)>> = Default::default(),
13411339

13421340
/// `CrateNum` resolutions of `extern crate` items.
13431341
extern_crate_map: UnordMap<LocalDefId, CrateNum> = Default::default(),
@@ -1975,7 +1973,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
19751973
};
19761974
let ast_lowering = ty::ResolverAstLowering {
19771975
partial_res_map: self.partial_res_map,
1978-
extra_lifetime_params_map: self.extra_lifetime_params_map,
19791976
next_node_id: self.next_node_id,
19801977
owners: self.owners,
19811978
lint_buffer: Steal::new(self.lint_buffer),

0 commit comments

Comments
 (0)