Auto merge of #117908 - lcnr:region-kind-rename, r=BoxyUwU
finish `RegionKind` renaming second step of https://github.com/rust-lang/types-team/issues/95 continues the work from #117876. While working on this and I encountered a bunch of further cleanup which I'll either open a tracking issue for or will do in a separate PR: - rewrite the `RegionKind` docs, they still talk about `ReEmpty` and are generally out of date - rename `DescriptionCtx` to `DescriptionCtxt` - what is `CheckRegions::Bound`? - `collect_late_bound_regions` et al - `erase_late_bound_regions` -> `instantiate_bound_regions_with_erased`? - `EraseEarlyRegions` visitor should be removed, feels duplicate r? `@BoxyUwU`
This commit is contained in:
commit
1500db7314
61 changed files with 301 additions and 275 deletions
|
@ -64,8 +64,8 @@ impl<'tcx> UnifyValue for UnifiedRegion<'tcx> {
|
|||
cmp::min_by_key(r1, r2, |r| match r.kind() {
|
||||
ty::ReStatic
|
||||
| ty::ReErased
|
||||
| ty::ReFree(..)
|
||||
| ty::ReEarlyBound(..)
|
||||
| ty::ReLateParam(..)
|
||||
| ty::ReEarlyParam(..)
|
||||
| ty::ReError(_) => ty::UniverseIndex::ROOT,
|
||||
ty::RePlaceholder(placeholder) => placeholder.universe,
|
||||
ty::ReVar(..) | ty::ReBound(..) => bug!("not a universal region"),
|
||||
|
|
|
@ -77,7 +77,7 @@ use std::ops::Deref;
|
|||
/// picture, but rather the ending point.
|
||||
//
|
||||
// FIXME(pnkfelix): this currently derives `PartialOrd` and `Ord` to
|
||||
// placate the same deriving in `ty::FreeRegion`, but we may want to
|
||||
// placate the same deriving in `ty::LateParamRegion`, but we may want to
|
||||
// actually attach a more meaningful ordering to scopes than the one
|
||||
// generated via deriving here.
|
||||
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Copy, TyEncodable, TyDecodable)]
|
||||
|
|
|
@ -113,9 +113,9 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
|
|||
type ExprConst = ty::Expr<'tcx>;
|
||||
|
||||
type Region = Region<'tcx>;
|
||||
type EarlyBoundRegion = ty::EarlyBoundRegion;
|
||||
type EarlyParamRegion = ty::EarlyParamRegion;
|
||||
type BoundRegion = ty::BoundRegion;
|
||||
type FreeRegion = ty::FreeRegion;
|
||||
type LateParamRegion = ty::LateParamRegion;
|
||||
type InferRegion = ty::RegionVid;
|
||||
type PlaceholderRegion = ty::PlaceholderRegion;
|
||||
|
||||
|
@ -445,14 +445,14 @@ impl<'tcx> CommonConsts<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
/// This struct contains information regarding the `ReFree(FreeRegion)` corresponding to a lifetime
|
||||
/// conflict.
|
||||
/// This struct contains information regarding a free parameter region,
|
||||
/// either a `ReEarlyParam` or `ReLateParam`.
|
||||
#[derive(Debug)]
|
||||
pub struct FreeRegionInfo {
|
||||
/// `LocalDefId` corresponding to FreeRegion
|
||||
/// `LocalDefId` of the free region.
|
||||
pub def_id: LocalDefId,
|
||||
/// the bound region corresponding to FreeRegion
|
||||
pub boundregion: ty::BoundRegionKind,
|
||||
/// the bound region corresponding to free region.
|
||||
pub bound_region: ty::BoundRegionKind,
|
||||
/// checks if bound region is in Impl Item
|
||||
pub is_impl_item: bool,
|
||||
}
|
||||
|
@ -1080,8 +1080,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
pub fn is_suitable_region(self, mut region: Region<'tcx>) -> Option<FreeRegionInfo> {
|
||||
let (suitable_region_binding_scope, bound_region) = loop {
|
||||
let def_id = match region.kind() {
|
||||
ty::ReFree(fr) => fr.bound_region.get_id()?.as_local()?,
|
||||
ty::ReEarlyBound(ebr) => ebr.def_id.expect_local(),
|
||||
ty::ReLateParam(fr) => fr.bound_region.get_id()?.as_local()?,
|
||||
ty::ReEarlyParam(ebr) => ebr.def_id.expect_local(),
|
||||
_ => return None, // not a free region
|
||||
};
|
||||
let scope = self.local_parent(def_id);
|
||||
|
@ -1102,11 +1102,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
_ => false,
|
||||
};
|
||||
|
||||
Some(FreeRegionInfo {
|
||||
def_id: suitable_region_binding_scope,
|
||||
boundregion: bound_region,
|
||||
is_impl_item,
|
||||
})
|
||||
Some(FreeRegionInfo { def_id: suitable_region_binding_scope, bound_region, is_impl_item })
|
||||
}
|
||||
|
||||
/// Given a `DefId` for an `fn`, return all the `dyn` and `impl` traits in its return type.
|
||||
|
@ -1743,7 +1739,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> GenericArg<'tcx> {
|
||||
match param.kind {
|
||||
GenericParamDefKind::Lifetime => {
|
||||
ty::Region::new_early_bound(self, param.to_early_bound_region_data()).into()
|
||||
ty::Region::new_early_param(self, param.to_early_bound_region_data()).into()
|
||||
}
|
||||
GenericParamDefKind::Type { .. } => Ty::new_param(self, param.index, param.name).into(),
|
||||
GenericParamDefKind::Const { .. } => ty::Const::new_param(
|
||||
|
@ -2040,7 +2036,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
/// Given the def-id of an early-bound lifetime on an RPIT corresponding to
|
||||
/// a duplicated captured lifetime, map it back to the early- or late-bound
|
||||
/// lifetime of the function from which it originally as captured. If it is
|
||||
/// a late-bound lifetime, this will represent the liberated (`ReFree`) lifetime
|
||||
/// a late-bound lifetime, this will represent the liberated (`ReLateParam`) lifetime
|
||||
/// of the signature.
|
||||
// FIXME(RPITIT): if we ever synthesize new lifetimes for RPITITs and not just
|
||||
// re-use the generics of the opaque, this function will need to be tweaked slightly.
|
||||
|
@ -2079,9 +2075,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
}
|
||||
|
||||
let generics = self.generics_of(new_parent);
|
||||
return ty::Region::new_early_bound(
|
||||
return ty::Region::new_early_param(
|
||||
self,
|
||||
ty::EarlyBoundRegion {
|
||||
ty::EarlyParamRegion {
|
||||
def_id: ebv,
|
||||
index: generics
|
||||
.param_def_id_to_index(self, ebv)
|
||||
|
@ -2092,7 +2088,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
}
|
||||
Some(resolve_bound_vars::ResolvedArg::LateBound(_, _, lbv)) => {
|
||||
let new_parent = self.parent(lbv);
|
||||
return ty::Region::new_free(
|
||||
return ty::Region::new_late_param(
|
||||
self,
|
||||
new_parent,
|
||||
ty::BoundRegionKind::BrNamed(
|
||||
|
|
|
@ -326,7 +326,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
T: TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
self.replace_late_bound_regions_uncached(value, |br| {
|
||||
ty::Region::new_free(self, all_outlive_scope, br.kind)
|
||||
ty::Region::new_late_param(self, all_outlive_scope, br.kind)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -809,7 +809,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for ArgFolder<'a, 'tcx> {
|
|||
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn region_param_out_of_range(data: ty::EarlyBoundRegion, args: &[GenericArg<'_>]) -> ! {
|
||||
fn region_param_out_of_range(data: ty::EarlyParamRegion, args: &[GenericArg<'_>]) -> ! {
|
||||
bug!(
|
||||
"Region parameter out of range when substituting in region {} (index={}, args = {:?})",
|
||||
data.name,
|
||||
|
@ -820,7 +820,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for ArgFolder<'a, 'tcx> {
|
|||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn region_param_invalid(data: ty::EarlyBoundRegion, other: GenericArgKind<'_>) -> ! {
|
||||
fn region_param_invalid(data: ty::EarlyParamRegion, other: GenericArgKind<'_>) -> ! {
|
||||
bug!(
|
||||
"Unexpected parameter {:?} when substituting in region {} (index={})",
|
||||
other,
|
||||
|
@ -835,7 +835,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for ArgFolder<'a, 'tcx> {
|
|||
// regions that appear in a function signature is done using
|
||||
// the specialized routine `ty::replace_late_regions()`.
|
||||
match *r {
|
||||
ty::ReEarlyBound(data) => {
|
||||
ty::ReEarlyParam(data) => {
|
||||
let rk = self.args.get(data.index as usize).map(|k| k.unpack());
|
||||
match rk {
|
||||
Some(GenericArgKind::Lifetime(lt)) => self.shift_region_through_binders(lt),
|
||||
|
@ -844,7 +844,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for ArgFolder<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
ty::ReBound(..)
|
||||
| ty::ReFree(_)
|
||||
| ty::ReLateParam(_)
|
||||
| ty::ReStatic
|
||||
| ty::RePlaceholder(_)
|
||||
| ty::ReErased
|
||||
|
|
|
@ -6,7 +6,7 @@ use rustc_hir::def_id::DefId;
|
|||
use rustc_span::symbol::{kw, Symbol};
|
||||
use rustc_span::Span;
|
||||
|
||||
use super::{Clause, EarlyBoundRegion, InstantiatedPredicates, ParamConst, ParamTy, Ty, TyCtxt};
|
||||
use super::{Clause, InstantiatedPredicates, ParamConst, ParamTy, Ty, TyCtxt};
|
||||
|
||||
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
|
||||
pub enum GenericParamDefKind {
|
||||
|
@ -62,9 +62,9 @@ pub struct GenericParamDef {
|
|||
}
|
||||
|
||||
impl GenericParamDef {
|
||||
pub fn to_early_bound_region_data(&self) -> ty::EarlyBoundRegion {
|
||||
pub fn to_early_bound_region_data(&self) -> ty::EarlyParamRegion {
|
||||
if let GenericParamDefKind::Lifetime = self.kind {
|
||||
ty::EarlyBoundRegion { def_id: self.def_id, index: self.index, name: self.name }
|
||||
ty::EarlyParamRegion { def_id: self.def_id, index: self.index, name: self.name }
|
||||
} else {
|
||||
bug!("cannot convert a non-lifetime parameter def to an early bound region")
|
||||
}
|
||||
|
@ -260,10 +260,10 @@ impl<'tcx> Generics {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the `GenericParamDef` associated with this `EarlyBoundRegion`.
|
||||
/// Returns the `GenericParamDef` associated with this `EarlyParamRegion`.
|
||||
pub fn region_param(
|
||||
&'tcx self,
|
||||
param: &EarlyBoundRegion,
|
||||
param: &ty::EarlyParamRegion,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
) -> &'tcx GenericParamDef {
|
||||
let param = self.param_at(param.index as usize, tcx);
|
||||
|
|
|
@ -98,11 +98,12 @@ pub use self::sty::BoundRegionKind::*;
|
|||
pub use self::sty::{
|
||||
AliasTy, Article, Binder, BoundRegion, BoundRegionKind, BoundTy, BoundTyKind, BoundVar,
|
||||
BoundVariableKind, CanonicalPolyFnSig, ClauseKind, ClosureArgs, ClosureArgsParts, ConstKind,
|
||||
ConstVid, CoroutineArgs, CoroutineArgsParts, EarlyBoundRegion, EffectVid, ExistentialPredicate,
|
||||
ExistentialProjection, ExistentialTraitRef, FnSig, FreeRegion, GenSig, InlineConstArgs,
|
||||
InlineConstArgsParts, ParamConst, ParamTy, PolyExistentialPredicate, PolyExistentialProjection,
|
||||
PolyExistentialTraitRef, PolyFnSig, PolyGenSig, PolyTraitRef, PredicateKind, Region,
|
||||
RegionKind, RegionVid, TraitRef, TyKind, TypeAndMut, UpvarArgs, VarianceDiagInfo,
|
||||
ConstVid, CoroutineArgs, CoroutineArgsParts, EarlyParamRegion, EffectVid, ExistentialPredicate,
|
||||
ExistentialProjection, ExistentialTraitRef, FnSig, GenSig, InlineConstArgs,
|
||||
InlineConstArgsParts, LateParamRegion, ParamConst, ParamTy, PolyExistentialPredicate,
|
||||
PolyExistentialProjection, PolyExistentialTraitRef, PolyFnSig, PolyGenSig, PolyTraitRef,
|
||||
PredicateKind, Region, RegionKind, RegionVid, TraitRef, TyKind, TypeAndMut, UpvarArgs,
|
||||
VarianceDiagInfo,
|
||||
};
|
||||
pub use self::trait_def::TraitDef;
|
||||
pub use self::typeck_results::{
|
||||
|
@ -463,7 +464,7 @@ pub struct CReaderCacheKey {
|
|||
#[rustc_pass_by_value]
|
||||
pub struct Ty<'tcx>(Interned<'tcx, WithCachedTypeInfo<TyKind<'tcx>>>);
|
||||
|
||||
impl ty::EarlyBoundRegion {
|
||||
impl EarlyParamRegion {
|
||||
/// Does this early bound region have a name? Early bound regions normally
|
||||
/// always have names except when using anonymous lifetimes (`'_`).
|
||||
pub fn has_name(&self) -> bool {
|
||||
|
|
|
@ -113,7 +113,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
|
|||
ty::ReError(_) => return r,
|
||||
|
||||
// The regions that we expect from borrow checking.
|
||||
ty::ReEarlyBound(_) | ty::ReFree(_) => {}
|
||||
ty::ReEarlyParam(_) | ty::ReLateParam(_) => {}
|
||||
|
||||
ty::RePlaceholder(_) | ty::ReVar(_) => {
|
||||
// All of the regions in the type should either have been
|
||||
|
|
|
@ -2158,10 +2158,10 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
|
|||
let identify_regions = self.tcx.sess.opts.unstable_opts.identify_regions;
|
||||
|
||||
match *region {
|
||||
ty::ReEarlyBound(ref data) => data.has_name(),
|
||||
ty::ReEarlyParam(ref data) => data.has_name(),
|
||||
|
||||
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
|
||||
| ty::ReFree(ty::FreeRegion { bound_region: br, .. })
|
||||
| ty::ReLateParam(ty::LateParamRegion { bound_region: br, .. })
|
||||
| ty::RePlaceholder(ty::Placeholder {
|
||||
bound: ty::BoundRegion { kind: br, .. }, ..
|
||||
}) => {
|
||||
|
@ -2228,14 +2228,14 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
|
|||
// to fit that into a short string. Hence the recommendation to use
|
||||
// `explain_region()` or `note_and_explain_region()`.
|
||||
match *region {
|
||||
ty::ReEarlyBound(ref data) => {
|
||||
ty::ReEarlyParam(ref data) => {
|
||||
if data.name != kw::Empty {
|
||||
p!(write("{}", data.name));
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
|
||||
| ty::ReFree(ty::FreeRegion { bound_region: br, .. })
|
||||
| ty::ReLateParam(ty::LateParamRegion { bound_region: br, .. })
|
||||
| ty::RePlaceholder(ty::Placeholder {
|
||||
bound: ty::BoundRegion { kind: br, .. }, ..
|
||||
}) => {
|
||||
|
|
|
@ -79,9 +79,9 @@ impl fmt::Debug for ty::BoundRegionKind {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::FreeRegion {
|
||||
impl fmt::Debug for ty::LateParamRegion {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "ReFree({:?}, {:?})", self.scope, self.bound_region)
|
||||
write!(f, "ReLateParam({:?}, {:?})", self.scope, self.bound_region)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -444,7 +444,7 @@ TrivialTypeTraversalImpls! {
|
|||
crate::ty::Placeholder<crate::ty::BoundRegion>,
|
||||
crate::ty::Placeholder<crate::ty::BoundTy>,
|
||||
crate::ty::Placeholder<ty::BoundVar>,
|
||||
crate::ty::FreeRegion,
|
||||
crate::ty::LateParamRegion,
|
||||
crate::ty::InferTy,
|
||||
crate::ty::IntVarValue,
|
||||
crate::ty::adjustment::PointerCoercion,
|
||||
|
|
|
@ -61,9 +61,9 @@ pub struct TypeAndMut<'tcx> {
|
|||
|
||||
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, TyEncodable, TyDecodable, Copy)]
|
||||
#[derive(HashStable)]
|
||||
/// A "free" region `fr` can be interpreted as "some region
|
||||
/// The parameter representation of late-bound function parameters, "some region
|
||||
/// at least as big as the scope `fr.scope`".
|
||||
pub struct FreeRegion {
|
||||
pub struct LateParamRegion {
|
||||
pub scope: DefId,
|
||||
pub bound_region: BoundRegionKind,
|
||||
}
|
||||
|
@ -1468,11 +1468,11 @@ pub struct Region<'tcx>(pub Interned<'tcx, RegionKind<'tcx>>);
|
|||
|
||||
impl<'tcx> Region<'tcx> {
|
||||
#[inline]
|
||||
pub fn new_early_bound(
|
||||
pub fn new_early_param(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
early_bound_region: ty::EarlyBoundRegion,
|
||||
early_bound_region: ty::EarlyParamRegion,
|
||||
) -> Region<'tcx> {
|
||||
tcx.intern_region(ty::ReEarlyBound(early_bound_region))
|
||||
tcx.intern_region(ty::ReEarlyParam(early_bound_region))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -1493,12 +1493,12 @@ impl<'tcx> Region<'tcx> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new_free(
|
||||
pub fn new_late_param(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
scope: DefId,
|
||||
bound_region: ty::BoundRegionKind,
|
||||
) -> Region<'tcx> {
|
||||
tcx.intern_region(ty::ReFree(ty::FreeRegion { scope, bound_region }))
|
||||
tcx.intern_region(ty::ReLateParam(ty::LateParamRegion { scope, bound_region }))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -1549,10 +1549,10 @@ impl<'tcx> Region<'tcx> {
|
|||
/// to avoid the cost of the `match`.
|
||||
pub fn new_from_kind(tcx: TyCtxt<'tcx>, kind: RegionKind<'tcx>) -> Region<'tcx> {
|
||||
match kind {
|
||||
ty::ReEarlyBound(region) => Region::new_early_bound(tcx, region),
|
||||
ty::ReEarlyParam(region) => Region::new_early_param(tcx, region),
|
||||
ty::ReBound(debruijn, region) => Region::new_bound(tcx, debruijn, region),
|
||||
ty::ReFree(ty::FreeRegion { scope, bound_region }) => {
|
||||
Region::new_free(tcx, scope, bound_region)
|
||||
ty::ReLateParam(ty::LateParamRegion { scope, bound_region }) => {
|
||||
Region::new_late_param(tcx, scope, bound_region)
|
||||
}
|
||||
ty::ReStatic => tcx.lifetimes.re_static,
|
||||
ty::ReVar(vid) => Region::new_var(tcx, vid),
|
||||
|
@ -1574,13 +1574,13 @@ impl<'tcx> Deref for Region<'tcx> {
|
|||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, PartialOrd, Ord)]
|
||||
#[derive(HashStable)]
|
||||
pub struct EarlyBoundRegion {
|
||||
pub struct EarlyParamRegion {
|
||||
pub def_id: DefId,
|
||||
pub index: u32,
|
||||
pub name: Symbol,
|
||||
}
|
||||
|
||||
impl fmt::Debug for EarlyBoundRegion {
|
||||
impl fmt::Debug for EarlyParamRegion {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{:?}, {}, {}", self.def_id, self.index, self.name)
|
||||
}
|
||||
|
@ -1722,9 +1722,9 @@ impl<'tcx> Region<'tcx> {
|
|||
pub fn get_name(self) -> Option<Symbol> {
|
||||
if self.has_name() {
|
||||
match *self {
|
||||
ty::ReEarlyBound(ebr) => Some(ebr.name),
|
||||
ty::ReEarlyParam(ebr) => Some(ebr.name),
|
||||
ty::ReBound(_, br) => br.kind.get_name(),
|
||||
ty::ReFree(fr) => fr.bound_region.get_name(),
|
||||
ty::ReLateParam(fr) => fr.bound_region.get_name(),
|
||||
ty::ReStatic => Some(kw::StaticLifetime),
|
||||
ty::RePlaceholder(placeholder) => placeholder.bound.kind.get_name(),
|
||||
_ => None,
|
||||
|
@ -1744,9 +1744,9 @@ impl<'tcx> Region<'tcx> {
|
|||
/// Is this region named by the user?
|
||||
pub fn has_name(self) -> bool {
|
||||
match *self {
|
||||
ty::ReEarlyBound(ebr) => ebr.has_name(),
|
||||
ty::ReEarlyParam(ebr) => ebr.has_name(),
|
||||
ty::ReBound(_, br) => br.kind.is_named(),
|
||||
ty::ReFree(fr) => fr.bound_region.is_named(),
|
||||
ty::ReLateParam(fr) => fr.bound_region.is_named(),
|
||||
ty::ReStatic => true,
|
||||
ty::ReVar(..) => false,
|
||||
ty::RePlaceholder(placeholder) => placeholder.bound.kind.is_named(),
|
||||
|
@ -1802,12 +1802,12 @@ impl<'tcx> Region<'tcx> {
|
|||
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
|
||||
flags = flags | TypeFlags::HAS_RE_PLACEHOLDER;
|
||||
}
|
||||
ty::ReEarlyBound(..) => {
|
||||
ty::ReEarlyParam(..) => {
|
||||
flags = flags | TypeFlags::HAS_FREE_REGIONS;
|
||||
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
|
||||
flags = flags | TypeFlags::HAS_RE_PARAM;
|
||||
}
|
||||
ty::ReFree { .. } => {
|
||||
ty::ReLateParam { .. } => {
|
||||
flags = flags | TypeFlags::HAS_FREE_REGIONS;
|
||||
flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
|
||||
}
|
||||
|
@ -1851,22 +1851,28 @@ impl<'tcx> Region<'tcx> {
|
|||
/// function might return the `DefId` of a closure.
|
||||
pub fn free_region_binding_scope(self, tcx: TyCtxt<'_>) -> DefId {
|
||||
match *self {
|
||||
ty::ReEarlyBound(br) => tcx.parent(br.def_id),
|
||||
ty::ReFree(fr) => fr.scope,
|
||||
ty::ReEarlyParam(br) => tcx.parent(br.def_id),
|
||||
ty::ReLateParam(fr) => fr.scope,
|
||||
_ => bug!("free_region_binding_scope invoked on inappropriate region: {:?}", self),
|
||||
}
|
||||
}
|
||||
|
||||
/// True for free regions other than `'static`.
|
||||
pub fn is_free(self) -> bool {
|
||||
matches!(*self, ty::ReEarlyBound(_) | ty::ReFree(_))
|
||||
pub fn is_param(self) -> bool {
|
||||
matches!(*self, ty::ReEarlyParam(_) | ty::ReLateParam(_))
|
||||
}
|
||||
|
||||
/// True if `self` is a free region or static.
|
||||
pub fn is_free_or_static(self) -> bool {
|
||||
/// True for free region in the current context.
|
||||
///
|
||||
/// This is the case for `'static` and param regions.
|
||||
pub fn is_free(self) -> bool {
|
||||
match *self {
|
||||
ty::ReStatic => true,
|
||||
_ => self.is_free(),
|
||||
ty::ReStatic | ty::ReEarlyParam(..) | ty::ReLateParam(..) => true,
|
||||
ty::ReVar(..)
|
||||
| ty::RePlaceholder(..)
|
||||
| ty::ReBound(..)
|
||||
| ty::ReErased
|
||||
| ty::ReError(..) => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ pub struct TypeckResults<'tcx> {
|
|||
/// fn(&'a u32) -> u32
|
||||
/// ```
|
||||
///
|
||||
/// Note that `'a` is not bound (it would be an `ReFree`) and
|
||||
/// Note that `'a` is not bound (it would be an `ReLateParam`) and
|
||||
/// that the `Foo` opaque type is replaced by its hidden type.
|
||||
liberated_fn_sigs: ItemLocalMap<ty::FnSig<'tcx>>,
|
||||
|
||||
|
|
|
@ -35,12 +35,14 @@ pub struct Discr<'tcx> {
|
|||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum CheckRegions {
|
||||
No,
|
||||
/// Only permit early bound regions. This is useful for Adts which
|
||||
/// can never have late bound regions.
|
||||
OnlyEarlyBound,
|
||||
/// Permit both late bound and early bound regions. Use this for functions,
|
||||
/// which frequently have late bound regions.
|
||||
Bound,
|
||||
/// Only permit parameter regions. This should be used
|
||||
/// for everything apart from functions, which may use
|
||||
/// `ReBound` to represent late-bound regions.
|
||||
OnlyParam,
|
||||
/// Check region parameters from a function definition.
|
||||
/// Allows `ReEarlyParam` and `ReBound` to handle early
|
||||
/// and late-bound region parameters.
|
||||
FromFunction,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
|
@ -431,7 +433,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
.filter(|&(_, k)| {
|
||||
match k.unpack() {
|
||||
GenericArgKind::Lifetime(region) => match region.kind() {
|
||||
ty::ReEarlyBound(ref ebr) => {
|
||||
ty::ReEarlyParam(ref ebr) => {
|
||||
!impl_generics.region_param(ebr, self).pure_wrt_drop
|
||||
}
|
||||
// Error: not a region param
|
||||
|
@ -468,17 +470,17 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
for arg in args {
|
||||
match arg.unpack() {
|
||||
GenericArgKind::Lifetime(lt) => match (ignore_regions, lt.kind()) {
|
||||
(CheckRegions::Bound, ty::ReBound(di, reg)) => {
|
||||
(CheckRegions::FromFunction, ty::ReBound(di, reg)) => {
|
||||
if !seen_late.insert((di, reg)) {
|
||||
return Err(NotUniqueParam::DuplicateParam(lt.into()));
|
||||
}
|
||||
}
|
||||
(CheckRegions::OnlyEarlyBound | CheckRegions::Bound, ty::ReEarlyBound(p)) => {
|
||||
(CheckRegions::OnlyParam | CheckRegions::FromFunction, ty::ReEarlyParam(p)) => {
|
||||
if !seen.insert(p.index) {
|
||||
return Err(NotUniqueParam::DuplicateParam(lt.into()));
|
||||
}
|
||||
}
|
||||
(CheckRegions::OnlyEarlyBound | CheckRegions::Bound, _) => {
|
||||
(CheckRegions::OnlyParam | CheckRegions::FromFunction, _) => {
|
||||
return Err(NotUniqueParam::NotParam(lt.into()));
|
||||
}
|
||||
(CheckRegions::No, _) => {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue