Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use super::diagnostics::{
use super::stability::{enabled_names, gate_unstable_abi};
use super::{
FnDeclKind, GenericArgsMode, ImplTraitContext, ImplTraitPosition, LoweringContext, ParamMode,
RelaxedBoundForbiddenReason, RelaxedBoundPolicy, ResolverAstLoweringExt,
RelaxedBoundForbiddenReason, RelaxedBoundPolicy,
};
use crate::diagnostics::ConstComptimeFn;

Expand Down Expand Up @@ -1878,7 +1878,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
.collect();

// Introduce extra lifetimes if late resolution tells us to.
let extra_lifetimes = self.resolver.extra_lifetime_params(self.owner.id);
let extra_lifetimes = self.owner.extra_lifetime_params(self.owner.id);
params.extend(extra_lifetimes.into_iter().map(|&(ident, node_id, kind)| {
self.lifetime_res_to_generic_param(
ident,
Expand Down
13 changes: 1 addition & 12 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,17 +351,6 @@ impl<'tcx> ResolverAstLowering<'tcx> {
)
.map(|fn_indexes| fn_indexes.iter().map(|(num, _)| *num).collect())
}

/// Obtain the list of lifetimes parameters to add to an item.
///
/// Extra lifetime parameters should only be added in places that can appear
/// as a `binder` in `LifetimeRes`.
///
/// The extra lifetimes that appear from the parenthesized `Fn`-trait desugaring
/// should appear at the enclosing `PolyTraitRef`.
fn extra_lifetime_params(&self, id: NodeId) -> &[(Ident, NodeId, MissingLifetimeKind)] {
self.extra_lifetime_params_map.get(&id).map_or(&[], |v| &v[..])
}
}

/// How relaxed bounds `?Trait` should be treated.
Expand Down Expand Up @@ -1129,7 +1118,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
) -> &'hir [hir::GenericParam<'hir>] {
// Start by creating params for extra lifetimes params, as this creates the definitions
// that may be referred to by the AST inside `generic_params`.
let extra_lifetimes = self.resolver.extra_lifetime_params(binder);
let extra_lifetimes = self.owner.extra_lifetime_params(binder);
debug!(?extra_lifetimes);
let extra_lifetimes: Vec<_> = extra_lifetimes
.iter()
Expand Down
17 changes: 14 additions & 3 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use rustc_abi::{
Align, FieldIdx, Integer, IntegerType, ReprFlags, ReprOptions, ScalableElt, VariantIdx,
};
use rustc_ast::node_id::NodeMap;
use rustc_ast::{self as ast};
use rustc_ast::{self as ast, NodeId};
pub use rustc_ast_ir::{Movability, Mutability, try_visit};
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::intern::Interned;
Expand Down Expand Up @@ -224,6 +224,8 @@ pub struct PerOwnerResolverData<'tcx> {

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

/// The id of the owner
pub id: ast::NodeId,
Expand All @@ -245,6 +247,17 @@ impl<'tcx> PerOwnerResolverData<'tcx> {
pub fn get_lifetime_res(&self, id: ast::NodeId) -> Option<LifetimeRes> {
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
/// as a `binder` in `LifetimeRes`.
///
/// The extra lifetimes that appear from the parenthesized `Fn`-trait desugaring
/// should appear at the enclosing `PolyTraitRef`.
pub fn extra_lifetime_params(&self, id: NodeId) -> &[(Ident, NodeId, MissingLifetimeKind)] {
self.extra_lifetime_params_map.get(&id).map_or(&[], |v| &v[..])
}
}

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

pub next_node_id: ast::NodeId,

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {

// Record the created lifetime parameter so lowering can pick it up and add it to HIR.
self.r
.current_owner
.extra_lifetime_params_map
.entry(binder)
.or_insert_with(Vec::new)
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use rustc_hir::def::{
};
use rustc_hir::def_id::{CRATE_DEF_ID, CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalDefIdMap};
use rustc_hir::definitions::{PerParentDisambiguatorState, PerParentDisambiguatorsMap};
use rustc_hir::{MissingLifetimeKind, PrimTy, TraitCandidate, find_attr};
use rustc_hir::{PrimTy, TraitCandidate, find_attr};
use rustc_index::bit_set::DenseBitSet;
use rustc_metadata::creader::CStore;
use rustc_middle::metadata::{AmbigModChild, ModChild, Reexport};
Expand Down Expand Up @@ -1336,8 +1336,6 @@ pub struct Resolver<'ra, 'tcx> {
partial_res_map: NodeMap<PartialRes> = Default::default(),
/// An import will be inserted into this map if it has been used.
import_use_map: FxHashMap<Import<'ra>, Used> = default::fx_hash_map(),
/// Lifetime parameters that lowering will have to introduce.
extra_lifetime_params_map: NodeMap<Vec<(Ident, NodeId, MissingLifetimeKind)>> = Default::default(),

/// `CrateNum` resolutions of `extern crate` items.
extern_crate_map: UnordMap<LocalDefId, CrateNum> = Default::default(),
Expand Down Expand Up @@ -1975,7 +1973,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
};
let ast_lowering = ty::ResolverAstLowering {
partial_res_map: self.partial_res_map,
extra_lifetime_params_map: self.extra_lifetime_params_map,
next_node_id: self.next_node_id,
owners: self.owners,
lint_buffer: Steal::new(self.lint_buffer),
Expand Down
Loading