Rollup merge of #99821 - cjgillot:ast-lifetimes-2, r=compiler-errors
Remove separate indexing of early-bound regions ~Based on https://github.com/rust-lang/rust/pull/99728.~ This PR copies some modifications from https://github.com/rust-lang/rust/pull/97839 around object lifetime defaults. These modifications allow to stop counting generic parameters during lifetime resolution, and rely on the indexing given by `rustc_typeck::collect`.
This commit is contained in:
commit
5555e13a6e
17 changed files with 180 additions and 432 deletions
|
@ -486,7 +486,9 @@ impl<'hir> Map<'hir> {
|
|||
let def_kind = self.tcx.def_kind(def_id);
|
||||
match def_kind {
|
||||
DefKind::Trait | DefKind::TraitAlias => def_id,
|
||||
DefKind::TyParam | DefKind::ConstParam => self.tcx.local_parent(def_id),
|
||||
DefKind::LifetimeParam | DefKind::TyParam | DefKind::ConstParam => {
|
||||
self.tcx.local_parent(def_id)
|
||||
}
|
||||
_ => bug!("ty_param_owner: {:?} is a {:?} not a type parameter", def_id, def_kind),
|
||||
}
|
||||
}
|
||||
|
@ -495,7 +497,9 @@ impl<'hir> Map<'hir> {
|
|||
let def_kind = self.tcx.def_kind(def_id);
|
||||
match def_kind {
|
||||
DefKind::Trait | DefKind::TraitAlias => kw::SelfUpper,
|
||||
DefKind::TyParam | DefKind::ConstParam => self.tcx.item_name(def_id.to_def_id()),
|
||||
DefKind::LifetimeParam | DefKind::TyParam | DefKind::ConstParam => {
|
||||
self.tcx.item_name(def_id.to_def_id())
|
||||
}
|
||||
_ => bug!("ty_param_name: {:?} is a {:?} not a type parameter", def_id, def_kind),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ use rustc_macros::HashStable;
|
|||
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)]
|
||||
pub enum Region {
|
||||
Static,
|
||||
EarlyBound(/* index */ u32, /* lifetime decl */ DefId),
|
||||
EarlyBound(/* lifetime decl */ DefId),
|
||||
LateBound(ty::DebruijnIndex, /* late-bound index */ u32, /* lifetime decl */ DefId),
|
||||
Free(DefId, /* lifetime decl */ DefId),
|
||||
}
|
||||
|
@ -35,7 +35,13 @@ impl<T: PartialEq> Set1<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub type ObjectLifetimeDefault = Set1<Region>;
|
||||
#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)]
|
||||
pub enum ObjectLifetimeDefault {
|
||||
Empty,
|
||||
Static,
|
||||
Ambiguous,
|
||||
Param(DefId),
|
||||
}
|
||||
|
||||
/// Maps the id of each lifetime reference to the lifetime decl
|
||||
/// that it corresponds to.
|
||||
|
|
|
@ -1597,8 +1597,9 @@ rustc_queries! {
|
|||
/// for each parameter if a trait object were to be passed for that parameter.
|
||||
/// For example, for `struct Foo<'a, T, U>`, this would be `['static, 'static]`.
|
||||
/// For `struct Foo<'a, T: 'a, U>`, this would instead be `['a, 'static]`.
|
||||
query object_lifetime_defaults(_: LocalDefId) -> Option<&'tcx [ObjectLifetimeDefault]> {
|
||||
desc { "looking up lifetime defaults for a region on an item" }
|
||||
query object_lifetime_default(key: DefId) -> Option<ObjectLifetimeDefault> {
|
||||
desc { "looking up lifetime defaults for generic parameter `{:?}`", key }
|
||||
separate_provide_extern
|
||||
}
|
||||
query late_bound_vars_map(_: LocalDefId)
|
||||
-> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use crate::middle::resolve_lifetime::ObjectLifetimeDefault;
|
||||
use crate::ty;
|
||||
use crate::ty::subst::{Subst, SubstsRef};
|
||||
use crate::ty::EarlyBinder;
|
||||
|
@ -13,7 +12,7 @@ use super::{EarlyBoundRegion, InstantiatedPredicates, ParamConst, ParamTy, Predi
|
|||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
|
||||
pub enum GenericParamDefKind {
|
||||
Lifetime,
|
||||
Type { has_default: bool, object_lifetime_default: ObjectLifetimeDefault, synthetic: bool },
|
||||
Type { has_default: bool, synthetic: bool },
|
||||
Const { has_default: bool },
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ trivially_parameterized_over_tcx! {
|
|||
crate::metadata::ModChild,
|
||||
crate::middle::codegen_fn_attrs::CodegenFnAttrs,
|
||||
crate::middle::exported_symbols::SymbolExportInfo,
|
||||
crate::middle::resolve_lifetime::ObjectLifetimeDefault,
|
||||
crate::mir::ConstQualifs,
|
||||
ty::Generics,
|
||||
ty::ImplPolarity,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue