finish RegionKind
rename
- `ReFree` -> `ReLateParam` - `ReEarlyBound` -> `ReEarlyParam`
This commit is contained in:
parent
5526682702
commit
15f21562e6
61 changed files with 300 additions and 274 deletions
|
@ -17,7 +17,7 @@ impl<'a> DescriptionCtx<'a> {
|
|||
alt_span: Option<Span>,
|
||||
) -> Option<Self> {
|
||||
let (span, kind, arg) = match *region {
|
||||
ty::ReEarlyBound(ref br) => {
|
||||
ty::ReEarlyParam(ref br) => {
|
||||
let scope = region.free_region_binding_scope(tcx).expect_local();
|
||||
let span = if let Some(param) =
|
||||
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
|
||||
|
@ -32,7 +32,7 @@ impl<'a> DescriptionCtx<'a> {
|
|||
(Some(span), "as_defined_anon", String::new())
|
||||
}
|
||||
}
|
||||
ty::ReFree(ref fr) => {
|
||||
ty::ReLateParam(ref fr) => {
|
||||
if !fr.bound_region.is_named()
|
||||
&& let Some((ty, _)) = find_anon_type(tcx, region, &fr.bound_region)
|
||||
{
|
||||
|
@ -70,7 +70,7 @@ impl<'a> DescriptionCtx<'a> {
|
|||
ty::RePlaceholder(_) | ty::ReError(_) => return None,
|
||||
|
||||
// FIXME(#13998) RePlaceholder should probably print like
|
||||
// ReFree rather than dumping Debug output on the user.
|
||||
// ReLateParam rather than dumping Debug output on the user.
|
||||
//
|
||||
// We shouldn't really be having unification failures with ReVar
|
||||
// and ReBound though.
|
||||
|
|
|
@ -172,7 +172,7 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
|
|||
r: ty::Region<'tcx>,
|
||||
) -> ty::Region<'tcx> {
|
||||
match *r {
|
||||
ty::ReFree(_) | ty::ReErased | ty::ReStatic | ty::ReEarlyBound(..) => r,
|
||||
ty::ReLateParam(_) | ty::ReErased | ty::ReStatic | ty::ReEarlyParam(..) => r,
|
||||
|
||||
ty::RePlaceholder(placeholder) => canonicalizer.canonical_var_for_region(
|
||||
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderRegion(placeholder) },
|
||||
|
@ -223,7 +223,11 @@ impl CanonicalizeMode for CanonicalizeUserTypeAnnotation {
|
|||
r: ty::Region<'tcx>,
|
||||
) -> ty::Region<'tcx> {
|
||||
match *r {
|
||||
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReErased | ty::ReStatic | ty::ReError(_) => r,
|
||||
ty::ReEarlyParam(_)
|
||||
| ty::ReLateParam(_)
|
||||
| ty::ReErased
|
||||
| ty::ReStatic
|
||||
| ty::ReError(_) => r,
|
||||
ty::ReVar(_) => canonicalizer.canonical_var_for_region_in_root_universe(r),
|
||||
ty::RePlaceholder(..) | ty::ReBound(..) => {
|
||||
// We only expect region names that the user can type.
|
||||
|
@ -359,9 +363,9 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
|
|||
}
|
||||
|
||||
ty::ReStatic
|
||||
| ty::ReEarlyBound(..)
|
||||
| ty::ReEarlyParam(..)
|
||||
| ty::ReError(_)
|
||||
| ty::ReFree(_)
|
||||
| ty::ReLateParam(_)
|
||||
| ty::RePlaceholder(..)
|
||||
| ty::ReErased => self.canonicalize_mode.canonicalize_free_region(self, r),
|
||||
}
|
||||
|
|
|
@ -168,7 +168,7 @@ pub(super) fn note_and_explain_region<'tcx>(
|
|||
alt_span: Option<Span>,
|
||||
) {
|
||||
let (description, span) = match *region {
|
||||
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::RePlaceholder(_) | ty::ReStatic => {
|
||||
ty::ReEarlyParam(_) | ty::ReLateParam(_) | ty::RePlaceholder(_) | ty::ReStatic => {
|
||||
msg_span_from_named_region(tcx, region, alt_span)
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ fn msg_span_from_named_region<'tcx>(
|
|||
alt_span: Option<Span>,
|
||||
) -> (String, Option<Span>) {
|
||||
match *region {
|
||||
ty::ReEarlyBound(ref br) => {
|
||||
ty::ReEarlyParam(ref br) => {
|
||||
let scope = region.free_region_binding_scope(tcx).expect_local();
|
||||
let span = if let Some(param) =
|
||||
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
|
||||
|
@ -218,7 +218,7 @@ fn msg_span_from_named_region<'tcx>(
|
|||
};
|
||||
(text, Some(span))
|
||||
}
|
||||
ty::ReFree(ref fr) => {
|
||||
ty::ReLateParam(ref fr) => {
|
||||
if !fr.bound_region.is_named()
|
||||
&& let Some((ty, _)) = find_anon_type(tcx, region, &fr.bound_region)
|
||||
{
|
||||
|
@ -315,7 +315,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
|
|||
|
||||
// Explain the region we are capturing.
|
||||
match *hidden_region {
|
||||
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic => {
|
||||
ty::ReEarlyParam(_) | ty::ReLateParam(_) | ty::ReStatic => {
|
||||
// Assuming regionck succeeded (*), we ought to always be
|
||||
// capturing *some* region from the fn header, and hence it
|
||||
// ought to be free. So under normal circumstances, we will go
|
||||
|
@ -2364,7 +2364,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
span,
|
||||
format!("{labeled_user_string} may not live long enough"),
|
||||
match sub.kind() {
|
||||
ty::ReEarlyBound(_) | ty::ReFree(_) if sub.has_name() => error_code!(E0309),
|
||||
ty::ReEarlyParam(_) | ty::ReLateParam(_) if sub.has_name() => error_code!(E0309),
|
||||
ty::ReStatic => error_code!(E0310),
|
||||
_ => error_code!(E0311),
|
||||
},
|
||||
|
@ -2372,7 +2372,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
|
||||
'_explain: {
|
||||
let (description, span) = match sub.kind() {
|
||||
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic => {
|
||||
ty::ReEarlyParam(_) | ty::ReLateParam(_) | ty::ReStatic => {
|
||||
msg_span_from_named_region(self.tcx, sub, Some(span))
|
||||
}
|
||||
_ => (format!("lifetime `{sub}`"), Some(span)),
|
||||
|
@ -2515,7 +2515,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
|
||||
let (lifetime_def_id, lifetime_scope) = match self.tcx.is_suitable_region(lifetime) {
|
||||
Some(info) if !lifetime.has_name() => {
|
||||
(info.boundregion.get_id().unwrap().expect_local(), info.def_id)
|
||||
(info.bound_region.get_id().unwrap().expect_local(), info.def_id)
|
||||
}
|
||||
_ => return lifetime.get_name_or_anon().to_string(),
|
||||
};
|
||||
|
@ -2714,8 +2714,8 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
|
|||
a: ty::Region<'tcx>,
|
||||
b: ty::Region<'tcx>,
|
||||
) -> RelateResult<'tcx, ty::Region<'tcx>> {
|
||||
if (a.is_var() && b.is_free_or_static())
|
||||
|| (b.is_var() && a.is_free_or_static())
|
||||
if (a.is_var() && b.is_free())
|
||||
|| (b.is_var() && a.is_free())
|
||||
|| (a.is_var() && b.is_var())
|
||||
|| a == b
|
||||
{
|
||||
|
@ -2779,7 +2779,9 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
br_string(br),
|
||||
self.tcx.associated_item(def_id).name
|
||||
),
|
||||
infer::EarlyBoundRegion(_, name) => format!(" for lifetime parameter `{name}`"),
|
||||
infer::RegionParameterDefinition(_, name) => {
|
||||
format!(" for lifetime parameter `{name}`")
|
||||
}
|
||||
infer::UpvarRegion(ref upvar_id, _) => {
|
||||
let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
|
||||
format!(" for capture of `{var_name}` by closure")
|
||||
|
|
|
@ -70,9 +70,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
|
||||
let anon_reg_sub = self.tcx().is_suitable_region(sub)?;
|
||||
let scope_def_id_sup = anon_reg_sup.def_id;
|
||||
let bregion_sup = anon_reg_sup.boundregion;
|
||||
let bregion_sup = anon_reg_sup.bound_region;
|
||||
let scope_def_id_sub = anon_reg_sub.def_id;
|
||||
let bregion_sub = anon_reg_sub.boundregion;
|
||||
let bregion_sub = anon_reg_sub.bound_region;
|
||||
|
||||
let ty_sup = find_anon_type(self.tcx(), sup, &bregion_sup)?;
|
||||
|
||||
|
|
|
@ -41,8 +41,8 @@ pub fn find_param_with_region<'tcx>(
|
|||
replace_region: Region<'tcx>,
|
||||
) -> Option<AnonymousParamInfo<'tcx>> {
|
||||
let (id, bound_region) = match *anon_region {
|
||||
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
|
||||
ty::ReEarlyBound(ebr) => {
|
||||
ty::ReLateParam(late_param) => (late_param.scope, late_param.bound_region),
|
||||
ty::ReEarlyParam(ebr) => {
|
||||
(tcx.parent(ebr.def_id), ty::BoundRegionKind::BrNamed(ebr.def_id, ebr.name))
|
||||
}
|
||||
_ => return None, // not a free region
|
||||
|
|
|
@ -22,8 +22,8 @@ impl<'a, 'tcx> RegionRelations<'a, 'tcx> {
|
|||
Self { tcx, free_regions }
|
||||
}
|
||||
|
||||
pub fn lub_free_regions(&self, r_a: Region<'tcx>, r_b: Region<'tcx>) -> Region<'tcx> {
|
||||
self.free_regions.lub_free_regions(self.tcx, r_a, r_b)
|
||||
pub fn lub_param_regions(&self, r_a: Region<'tcx>, r_b: Region<'tcx>) -> Region<'tcx> {
|
||||
self.free_regions.lub_param_regions(self.tcx, r_a, r_b)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ impl<'tcx> FreeRegionMap<'tcx> {
|
|||
r_a: Region<'tcx>,
|
||||
r_b: Region<'tcx>,
|
||||
) -> bool {
|
||||
assert!(r_a.is_free_or_static() && r_b.is_free_or_static());
|
||||
assert!(r_a.is_free() && r_b.is_free());
|
||||
let re_static = tcx.lifetimes.re_static;
|
||||
if self.check_relation(re_static, r_b) {
|
||||
// `'a <= 'static` is always true, and not stored in the
|
||||
|
@ -80,15 +80,15 @@ impl<'tcx> FreeRegionMap<'tcx> {
|
|||
/// cases, this is more conservative than necessary, in order to
|
||||
/// avoid making arbitrary choices. See
|
||||
/// `TransitiveRelation::postdom_upper_bound` for more details.
|
||||
pub fn lub_free_regions(
|
||||
pub fn lub_param_regions(
|
||||
&self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
r_a: Region<'tcx>,
|
||||
r_b: Region<'tcx>,
|
||||
) -> Region<'tcx> {
|
||||
debug!("lub_free_regions(r_a={:?}, r_b={:?})", r_a, r_b);
|
||||
assert!(r_a.is_free());
|
||||
assert!(r_b.is_free());
|
||||
debug!("lub_param_regions(r_a={:?}, r_b={:?})", r_a, r_b);
|
||||
assert!(r_a.is_late_or_early_param());
|
||||
assert!(r_b.is_late_or_early_param());
|
||||
let result = if r_a == r_b {
|
||||
r_a
|
||||
} else {
|
||||
|
@ -97,7 +97,7 @@ impl<'tcx> FreeRegionMap<'tcx> {
|
|||
Some(r) => r,
|
||||
}
|
||||
};
|
||||
debug!("lub_free_regions(r_a={:?}, r_b={:?}) = {:?}", r_a, r_b, result);
|
||||
debug!("lub_param_regions(r_a={:?}, r_b={:?}) = {:?}", r_a, r_b, result);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,8 +115,8 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {
|
|||
r
|
||||
}
|
||||
|
||||
ty::ReEarlyBound(..)
|
||||
| ty::ReFree(_)
|
||||
ty::ReEarlyParam(..)
|
||||
| ty::ReLateParam(_)
|
||||
| ty::ReVar(_)
|
||||
| ty::RePlaceholder(..)
|
||||
| ty::ReStatic
|
||||
|
|
|
@ -340,8 +340,8 @@ where
|
|||
ty::RePlaceholder(..)
|
||||
| ty::ReVar(..)
|
||||
| ty::ReStatic
|
||||
| ty::ReEarlyBound(..)
|
||||
| ty::ReFree(..) => {
|
||||
| ty::ReEarlyParam(..)
|
||||
| ty::ReLateParam(..) => {
|
||||
// see common code below
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ use rustc_index::{IndexSlice, IndexVec};
|
|||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{ReBound, RePlaceholder, ReVar};
|
||||
use rustc_middle::ty::{ReEarlyBound, ReErased, ReError, ReFree, ReStatic};
|
||||
use rustc_middle::ty::{ReEarlyParam, ReErased, ReError, ReLateParam, ReStatic};
|
||||
use rustc_middle::ty::{Region, RegionVid};
|
||||
use rustc_span::Span;
|
||||
use std::fmt;
|
||||
|
@ -390,7 +390,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||
);
|
||||
}
|
||||
|
||||
ReStatic | ReEarlyBound(_) | ReFree(_) => {
|
||||
ReStatic | ReEarlyParam(_) | ReLateParam(_) => {
|
||||
// nothing lives longer than `'static`
|
||||
|
||||
// All empty regions are less than early-bound, free,
|
||||
|
@ -423,9 +423,9 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||
);
|
||||
}
|
||||
|
||||
ReStatic | ReEarlyBound(_) | ReFree(_) => {
|
||||
ReStatic | ReEarlyParam(_) | ReLateParam(_) => {
|
||||
// nothing lives longer than `'static`
|
||||
// All empty regions are less than early-bound, free,
|
||||
// All empty regions are less than early-bound, late-bound,
|
||||
// and scope regions.
|
||||
true
|
||||
}
|
||||
|
@ -450,8 +450,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||
|
||||
// Check for the case where we know that `'b: 'static` -- in that case,
|
||||
// `a <= b` for all `a`.
|
||||
let b_free_or_static = b.is_free_or_static();
|
||||
if b_free_or_static && sub_free_regions(tcx.lifetimes.re_static, b) {
|
||||
if b.is_free() && sub_free_regions(tcx.lifetimes.re_static, b) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -460,8 +459,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||
// `lub` relationship defined below, since sometimes the "lub"
|
||||
// is actually the `postdom_upper_bound` (see
|
||||
// `TransitiveRelation` for more details).
|
||||
let a_free_or_static = a.is_free_or_static();
|
||||
if a_free_or_static && b_free_or_static {
|
||||
if a.is_free() && b.is_free() {
|
||||
return sub_free_regions(a, b);
|
||||
}
|
||||
|
||||
|
@ -501,8 +499,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||
self.tcx().lifetimes.re_static
|
||||
}
|
||||
|
||||
(ReEarlyBound(_) | ReFree(_), ReEarlyBound(_) | ReFree(_)) => {
|
||||
self.region_rels.lub_free_regions(a, b)
|
||||
(ReEarlyParam(_) | ReLateParam(_), ReEarlyParam(_) | ReLateParam(_)) => {
|
||||
self.region_rels.lub_param_regions(a, b)
|
||||
}
|
||||
|
||||
// For these types, we cannot define any additional
|
||||
|
@ -723,13 +721,13 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
|||
return;
|
||||
}
|
||||
|
||||
// We place free regions first because we are special casing
|
||||
// SubSupConflict(ReFree, ReFree) when reporting error, and so
|
||||
// We place late-bound regions first because we are special casing
|
||||
// SubSupConflict(ReLateParam, ReLateParam) when reporting error, and so
|
||||
// the user will more likely get a specific suggestion.
|
||||
fn region_order_key(x: &RegionAndOrigin<'_>) -> u8 {
|
||||
match *x.region {
|
||||
ReEarlyBound(_) => 0,
|
||||
ReFree(_) => 1,
|
||||
ReEarlyParam(_) => 0,
|
||||
ReLateParam(_) => 1,
|
||||
_ => 2,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -508,7 +508,10 @@ pub enum RegionVariableOrigin {
|
|||
Coercion(Span),
|
||||
|
||||
/// Region variables created as the values for early-bound regions.
|
||||
EarlyBoundRegion(Span, Symbol),
|
||||
///
|
||||
/// FIXME(@lcnr): This can also store a `DefId`, similar to
|
||||
/// `TypeVariableOriginKind::TypeParameterDefinition`.
|
||||
RegionParameterDefinition(Span, Symbol),
|
||||
|
||||
/// Region variables created when instantiating a binder with
|
||||
/// existential variables, e.g. when calling a function or method.
|
||||
|
@ -1165,7 +1168,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
GenericParamDefKind::Lifetime => {
|
||||
// Create a region inference variable for the given
|
||||
// region parameter definition.
|
||||
self.next_region_var(EarlyBoundRegion(span, param.name)).into()
|
||||
self.next_region_var(RegionParameterDefinition(span, param.name)).into()
|
||||
}
|
||||
GenericParamDefKind::Type { .. } => {
|
||||
// Create a type inference variable for the given
|
||||
|
@ -2041,7 +2044,7 @@ impl RegionVariableOrigin {
|
|||
| AddrOfRegion(a)
|
||||
| Autoref(a)
|
||||
| Coercion(a)
|
||||
| EarlyBoundRegion(a, ..)
|
||||
| RegionParameterDefinition(a, ..)
|
||||
| BoundRegion(a, ..)
|
||||
| UpvarRegion(_, a) => a,
|
||||
Nll(..) => bug!("NLL variable used with `span`"),
|
||||
|
|
|
@ -138,8 +138,8 @@ impl<'tcx> OutlivesEnvironmentBuilder<'tcx> {
|
|||
}
|
||||
OutlivesBound::RegionSubRegion(r_a, r_b) => match (*r_a, *r_b) {
|
||||
(
|
||||
ty::ReStatic | ty::ReEarlyBound(_) | ty::ReFree(_),
|
||||
ty::ReStatic | ty::ReEarlyBound(_) | ty::ReFree(_),
|
||||
ty::ReStatic | ty::ReEarlyParam(_) | ty::ReLateParam(_),
|
||||
ty::ReStatic | ty::ReEarlyParam(_) | ty::ReLateParam(_),
|
||||
) => self.region_relation.add(r_a, r_b),
|
||||
(ty::ReError(_), _) | (_, ty::ReError(_)) => {}
|
||||
// FIXME(#109628): We shouldn't have existential variables in implied bounds.
|
||||
|
|
|
@ -662,8 +662,8 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
|||
match *region {
|
||||
ty::ReStatic
|
||||
| ty::ReErased
|
||||
| ty::ReFree(..)
|
||||
| ty::ReEarlyBound(..)
|
||||
| ty::ReLateParam(..)
|
||||
| ty::ReEarlyParam(..)
|
||||
| ty::ReError(_) => ty::UniverseIndex::ROOT,
|
||||
ty::RePlaceholder(placeholder) => placeholder.universe,
|
||||
ty::ReVar(vid) => self.var_universe(vid),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue