1
Fork 0

Add specialized variants of mk_region.

Much like there are specialized variants of `mk_ty`. This will enable
some optimization in the next commit.

Also rename the existing `re_error*` functions as `mk_re_error*`, for
consistency.
This commit is contained in:
Nicholas Nethercote 2023-02-13 13:03:45 +11:00
parent 7439028374
commit cef9004f5a
39 changed files with 196 additions and 173 deletions

View file

@ -180,20 +180,20 @@ trait TypeOpInfo<'tcx> {
return; return;
}; };
let placeholder_region = tcx.mk_region(ty::RePlaceholder(ty::Placeholder { let placeholder_region = tcx.mk_re_placeholder(ty::Placeholder {
name: placeholder.name, name: placeholder.name,
universe: adjusted_universe.into(), universe: adjusted_universe.into(),
})); });
let error_region = let error_region =
if let RegionElement::PlaceholderRegion(error_placeholder) = error_element { if let RegionElement::PlaceholderRegion(error_placeholder) = error_element {
let adjusted_universe = let adjusted_universe =
error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32()); error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32());
adjusted_universe.map(|adjusted| { adjusted_universe.map(|adjusted| {
tcx.mk_region(ty::RePlaceholder(ty::Placeholder { tcx.mk_re_placeholder(ty::Placeholder {
name: error_placeholder.name, name: error_placeholder.name,
universe: adjusted.into(), universe: adjusted.into(),
})) })
}) })
} else { } else {
None None
@ -390,7 +390,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
error_region, error_region,
&region_constraints, &region_constraints,
|vid| ocx.infcx.region_var_origin(vid), |vid| ocx.infcx.region_var_origin(vid),
|vid| ocx.infcx.universe_of_region(ocx.infcx.tcx.mk_region(ty::ReVar(vid))), |vid| ocx.infcx.universe_of_region(ocx.infcx.tcx.mk_re_var(vid)),
) )
} }
@ -411,7 +411,7 @@ fn try_extract_error_from_region_constraints<'tcx>(
} }
// FIXME: Should this check the universe of the var? // FIXME: Should this check the universe of the var?
Constraint::VarSubReg(vid, sup) if sup == placeholder_region => { Constraint::VarSubReg(vid, sup) if sup == placeholder_region => {
Some((infcx.tcx.mk_region(ty::ReVar(vid)), cause.clone())) Some((infcx.tcx.mk_re_var(vid), cause.clone()))
} }
_ => None, _ => None,
} }

View file

@ -1284,7 +1284,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
let vid = self.to_region_vid(r); let vid = self.to_region_vid(r);
let scc = self.constraint_sccs.scc(vid); let scc = self.constraint_sccs.scc(vid);
let repr = self.scc_representatives[scc]; let repr = self.scc_representatives[scc];
tcx.mk_region(ty::ReVar(repr)) tcx.mk_re_var(repr)
}) })
} }
@ -1706,7 +1706,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
} }
// If not, report an error. // If not, report an error.
let member_region = infcx.tcx.mk_region(ty::ReVar(member_region_vid)); let member_region = infcx.tcx.mk_re_var(member_region_vid);
errors_buffer.push(RegionErrorKind::UnexpectedHiddenRegion { errors_buffer.push(RegionErrorKind::UnexpectedHiddenRegion {
span: m_c.definition_span, span: m_c.definition_span,
hidden_ty: m_c.hidden_ty, hidden_ty: m_c.hidden_ty,

View file

@ -91,7 +91,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
} }
None => { None => {
subst_regions.push(vid); subst_regions.push(vid);
infcx.tcx.re_error_with_message( infcx.tcx.mk_re_error_with_message(
concrete_type.span, concrete_type.span,
"opaque type with non-universal region substs", "opaque type with non-universal region substs",
) )

View file

@ -137,7 +137,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
upvars: &[Upvar<'tcx>], upvars: &[Upvar<'tcx>],
use_polonius: bool, use_polonius: bool,
) -> MirTypeckResults<'tcx> { ) -> MirTypeckResults<'tcx> {
let implicit_region_bound = infcx.tcx.mk_region(ty::ReVar(universal_regions.fr_fn_body)); let implicit_region_bound = infcx.tcx.mk_re_var(universal_regions.fr_fn_body);
let mut constraints = MirTypeckRegionConstraints { let mut constraints = MirTypeckRegionConstraints {
placeholder_indices: PlaceholderIndices::default(), placeholder_indices: PlaceholderIndices::default(),
placeholder_index_to_region: IndexVec::default(), placeholder_index_to_region: IndexVec::default(),

View file

@ -480,10 +480,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
LangItem::VaList, LangItem::VaList,
Some(self.infcx.tcx.def_span(self.mir_def.did)), Some(self.infcx.tcx.def_span(self.mir_def.did)),
); );
let region = self let region =
.infcx self.infcx.tcx.mk_re_var(self.infcx.next_nll_region_var(FR).to_region_vid());
.tcx
.mk_region(ty::ReVar(self.infcx.next_nll_region_var(FR).to_region_vid()));
let va_list_ty = self let va_list_ty = self
.infcx .infcx
.tcx .tcx
@ -636,7 +634,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
var: ty::BoundVar::from_usize(bound_vars.len() - 1), var: ty::BoundVar::from_usize(bound_vars.len() - 1),
kind: ty::BrEnv, kind: ty::BrEnv,
}; };
let env_region = ty::ReLateBound(ty::INNERMOST, br); let env_region = tcx.mk_re_late_bound(ty::INNERMOST, br);
let closure_ty = tcx.closure_env_ty(def_id, substs, env_region).unwrap(); let closure_ty = tcx.closure_env_ty(def_id, substs, env_region).unwrap();
// The "inputs" of the closure in the // The "inputs" of the closure in the
@ -748,10 +746,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
{ {
let (value, _map) = self.tcx.replace_late_bound_regions(value, |br| { let (value, _map) = self.tcx.replace_late_bound_regions(value, |br| {
debug!(?br); debug!(?br);
let liberated_region = self.tcx.mk_region(ty::ReFree(ty::FreeRegion { let liberated_region = self.tcx.mk_re_free(all_outlive_scope.to_def_id(), br.kind);
scope: all_outlive_scope.to_def_id(),
bound_region: br.kind,
}));
let region_vid = self.next_nll_region_var(origin); let region_vid = self.next_nll_region_var(origin);
indices.insert_late_bound_region(liberated_region, region_vid.to_region_vid()); indices.insert_late_bound_region(liberated_region, region_vid.to_region_vid());
debug!(?liberated_region, ?region_vid); debug!(?liberated_region, ?region_vid);
@ -843,7 +838,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
tcx.fold_regions(value, |region, _| tcx.mk_region(ty::ReVar(self.to_region_vid(region)))) tcx.fold_regions(value, |region, _| tcx.mk_re_var(self.to_region_vid(region)))
} }
} }
@ -883,8 +878,7 @@ fn for_each_late_bound_region_in_item<'tcx>(
for bound_var in tcx.late_bound_vars(tcx.hir().local_def_id_to_hir_id(mir_def_id)) { for bound_var in tcx.late_bound_vars(tcx.hir().local_def_id_to_hir_id(mir_def_id)) {
let ty::BoundVariableKind::Region(bound_region) = bound_var else { continue; }; let ty::BoundVariableKind::Region(bound_region) = bound_var else { continue; };
let liberated_region = tcx let liberated_region = tcx.mk_re_free(mir_def_id.to_def_id(), bound_region);
.mk_region(ty::ReFree(ty::FreeRegion { scope: mir_def_id.to_def_id(), bound_region }));
f(liberated_region); f(liberated_region);
} }
} }

View file

@ -234,7 +234,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
var: ty::BoundVar::from_u32(index), var: ty::BoundVar::from_u32(index),
kind: ty::BrNamed(def_id, name), kind: ty::BrNamed(def_id, name),
}; };
tcx.mk_region(ty::ReLateBound(debruijn, br)) tcx.mk_re_late_bound(debruijn, br)
} }
Some(rl::Region::EarlyBound(def_id)) => { Some(rl::Region::EarlyBound(def_id)) => {
@ -242,15 +242,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let item_def_id = tcx.hir().ty_param_owner(def_id.expect_local()); let item_def_id = tcx.hir().ty_param_owner(def_id.expect_local());
let generics = tcx.generics_of(item_def_id); let generics = tcx.generics_of(item_def_id);
let index = generics.param_def_id_to_index[&def_id]; let index = generics.param_def_id_to_index[&def_id];
tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name })) tcx.mk_re_early_bound(ty::EarlyBoundRegion { def_id, index, name })
} }
Some(rl::Region::Free(scope, id)) => { Some(rl::Region::Free(scope, id)) => {
let name = lifetime_name(id.expect_local()); let name = lifetime_name(id.expect_local());
tcx.mk_region(ty::ReFree(ty::FreeRegion { tcx.mk_re_free(scope, ty::BrNamed(id, name))
scope,
bound_region: ty::BrNamed(id, name),
}))
// (*) -- not late-bound, won't change // (*) -- not late-bound, won't change
} }
@ -263,7 +260,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// elision. `resolve_lifetime` should have // elision. `resolve_lifetime` should have
// reported an error in this case -- but if // reported an error in this case -- but if
// not, let's error out. // not, let's error out.
tcx.re_error_with_message(lifetime.ident.span, "unelided lifetime in signature") tcx.mk_re_error_with_message(
lifetime.ident.span,
"unelided lifetime in signature",
)
}) })
} }
} }
@ -477,7 +477,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
debug!(?param, "unelided lifetime in signature"); debug!(?param, "unelided lifetime in signature");
// This indicates an illegal lifetime in a non-assoc-trait position // This indicates an illegal lifetime in a non-assoc-trait position
tcx.re_error_with_message(self.span, "unelided lifetime in signature") tcx.mk_re_error_with_message(
self.span,
"unelided lifetime in signature",
)
}) })
.into(), .into(),
GenericParamDefKind::Type { has_default, .. } => { GenericParamDefKind::Type { has_default, .. } => {
@ -1622,7 +1625,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} else { } else {
err.emit() err.emit()
}; };
tcx.re_error(e) tcx.mk_re_error(e)
}) })
} }
}) })

View file

@ -471,14 +471,10 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateBound<'_, 'tcx> {
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
if let ty::ReFree(fr) = *r { if let ty::ReFree(fr) = *r {
self.tcx.mk_region(ty::ReFree(ty::FreeRegion { self.tcx.mk_re_free(
bound_region: self fr.scope,
.mapping self.mapping.get(&fr.bound_region).copied().unwrap_or(fr.bound_region),
.get(&fr.bound_region) )
.copied()
.unwrap_or(fr.bound_region),
..fr
}))
} else { } else {
r r
} }
@ -786,13 +782,13 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
} }
let Some(ty::ReEarlyBound(e)) = map.get(&region.into()).map(|r| r.expect_region().kind()) let Some(ty::ReEarlyBound(e)) = map.get(&region.into()).map(|r| r.expect_region().kind())
else { else {
return tcx.re_error_with_message(return_span, "expected ReFree to map to ReEarlyBound") return tcx.mk_re_error_with_message(return_span, "expected ReFree to map to ReEarlyBound")
}; };
tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { tcx.mk_re_early_bound(ty::EarlyBoundRegion {
def_id: e.def_id, def_id: e.def_id,
name: e.name, name: e.name,
index: (e.index as usize - num_trait_substs + num_impl_substs) as u32, index: (e.index as usize - num_trait_substs + num_impl_substs) as u32,
})) })
}); });
debug!(%ty); debug!(%ty);
collected_tys.insert(def_id, ty); collected_tys.insert(def_id, ty);
@ -1937,10 +1933,10 @@ pub(super) fn check_type_bounds<'tcx>(
let kind = ty::BoundRegionKind::BrNamed(param.def_id, param.name); let kind = ty::BoundRegionKind::BrNamed(param.def_id, param.name);
let bound_var = ty::BoundVariableKind::Region(kind); let bound_var = ty::BoundVariableKind::Region(kind);
bound_vars.push(bound_var); bound_vars.push(bound_var);
tcx.mk_region(ty::ReLateBound( tcx.mk_re_late_bound(
ty::INNERMOST, ty::INNERMOST,
ty::BoundRegion { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind }, ty::BoundRegion { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind },
)) )
.into() .into()
} }
GenericParamDefKind::Const { .. } => { GenericParamDefKind::Const { .. } => {

View file

@ -149,14 +149,14 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
); );
let mk_va_list_ty = |mutbl| { let mk_va_list_ty = |mutbl| {
tcx.lang_items().va_list().map(|did| { tcx.lang_items().va_list().map(|did| {
let region = tcx.mk_region(ty::ReLateBound( let region = tcx.mk_re_late_bound(
ty::INNERMOST, ty::INNERMOST,
ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0, None) }, ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0, None) },
)); );
let env_region = tcx.mk_region(ty::ReLateBound( let env_region = tcx.mk_re_late_bound(
ty::INNERMOST, ty::INNERMOST,
ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrEnv }, ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrEnv },
)); );
let va_list_ty = tcx.bound_type_of(did).subst(tcx, &[region.into()]); let va_list_ty = tcx.bound_type_of(did).subst(tcx, &[region.into()]);
(tcx.mk_ref(env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty) (tcx.mk_ref(env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty)
}) })
@ -377,9 +377,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0, None) }; ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0, None) };
( (
1, 1,
vec![ vec![tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0))],
tcx.mk_imm_ref(tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)), param(0)),
],
tcx.mk_projection(discriminant_def_id, tcx.mk_substs([param(0).into()].iter())), tcx.mk_projection(discriminant_def_id, tcx.mk_substs([param(0).into()].iter())),
) )
} }
@ -430,8 +428,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
sym::raw_eq => { sym::raw_eq => {
let br = let br =
ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0, None) }; ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0, None) };
let param_ty = let param_ty = tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0));
tcx.mk_imm_ref(tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)), param(0));
(1, vec![param_ty; 2], tcx.types.bool) (1, vec![param_ty; 2], tcx.types.bool)
} }

View file

@ -607,12 +607,11 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
// Same for the region. In our example, 'a corresponds // Same for the region. In our example, 'a corresponds
// to the 'me parameter. // to the 'me parameter.
let region_param = gat_generics.param_at(*region_a_idx, tcx); let region_param = gat_generics.param_at(*region_a_idx, tcx);
let region_param = let region_param = tcx.mk_re_early_bound(ty::EarlyBoundRegion {
tcx.mk_region(ty::RegionKind::ReEarlyBound(ty::EarlyBoundRegion { def_id: region_param.def_id,
def_id: region_param.def_id, index: region_param.index,
index: region_param.index, name: region_param.name,
name: region_param.name, });
}));
// The predicate we expect to see. (In our example, // The predicate we expect to see. (In our example,
// `Self: 'me`.) // `Self: 'me`.)
let clause = ty::PredicateKind::Clause(ty::Clause::TypeOutlives( let clause = ty::PredicateKind::Clause(ty::Clause::TypeOutlives(
@ -645,20 +644,18 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>(
debug!("required clause: {region_a} must outlive {region_b}"); debug!("required clause: {region_a} must outlive {region_b}");
// Translate into the generic parameters of the GAT. // Translate into the generic parameters of the GAT.
let region_a_param = gat_generics.param_at(*region_a_idx, tcx); let region_a_param = gat_generics.param_at(*region_a_idx, tcx);
let region_a_param = let region_a_param = tcx.mk_re_early_bound(ty::EarlyBoundRegion {
tcx.mk_region(ty::RegionKind::ReEarlyBound(ty::EarlyBoundRegion { def_id: region_a_param.def_id,
def_id: region_a_param.def_id, index: region_a_param.index,
index: region_a_param.index, name: region_a_param.name,
name: region_a_param.name, });
}));
// Same for the region. // Same for the region.
let region_b_param = gat_generics.param_at(*region_b_idx, tcx); let region_b_param = gat_generics.param_at(*region_b_idx, tcx);
let region_b_param = let region_b_param = tcx.mk_re_early_bound(ty::EarlyBoundRegion {
tcx.mk_region(ty::RegionKind::ReEarlyBound(ty::EarlyBoundRegion { def_id: region_b_param.def_id,
def_id: region_b_param.def_id, index: region_b_param.index,
index: region_b_param.index, name: region_b_param.name,
name: region_b_param.name, });
}));
// The predicate we expect to see. // The predicate we expect to see.
let clause = ty::PredicateKind::Clause(ty::Clause::RegionOutlives( let clause = ty::PredicateKind::Clause(ty::Clause::RegionOutlives(
ty::OutlivesPredicate(region_a_param, region_b_param), ty::OutlivesPredicate(region_a_param, region_b_param),

View file

@ -458,13 +458,11 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
self.tcx.replace_late_bound_regions_uncached( self.tcx.replace_late_bound_regions_uncached(
poly_trait_ref, poly_trait_ref,
|_| { |_| {
self.tcx.mk_region(ty::ReEarlyBound( self.tcx.mk_re_early_bound(ty::EarlyBoundRegion {
ty::EarlyBoundRegion { def_id: item_def_id,
def_id: item_def_id, index: 0,
index: 0, name: Symbol::intern(&lt_name),
name: Symbol::intern(&lt_name), })
},
))
} }
), ),
), ),

View file

@ -284,11 +284,11 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
let Some(dup_index) = generics.param_def_id_to_index(tcx, dup_def) else { bug!() }; let Some(dup_index) = generics.param_def_id_to_index(tcx, dup_def) else { bug!() };
let dup_region = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { let dup_region = tcx.mk_re_early_bound(ty::EarlyBoundRegion {
def_id: dup_def, def_id: dup_def,
index: dup_index, index: dup_index,
name: duplicate.name.ident().name, name: duplicate.name.ident().name,
})); });
predicates.push(( predicates.push((
ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::RegionOutlives( ty::Binder::dummy(ty::PredicateKind::Clause(ty::Clause::RegionOutlives(
ty::OutlivesPredicate(orig_region, dup_region), ty::OutlivesPredicate(orig_region, dup_region),

View file

@ -1264,10 +1264,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// ``` // ```
let ref_ty = match mutability { let ref_ty = match mutability {
hir::Mutability::Mut => { hir::Mutability::Mut => {
self.tcx.mk_mut_ref(self.tcx.mk_region(ty::ReStatic), checked_ty) self.tcx.mk_mut_ref(self.tcx.lifetimes.re_static, checked_ty)
} }
hir::Mutability::Not => { hir::Mutability::Not => {
self.tcx.mk_imm_ref(self.tcx.mk_region(ty::ReStatic), checked_ty) self.tcx.mk_imm_ref(self.tcx.lifetimes.re_static, checked_ty)
} }
}; };
if self.can_coerce(ref_ty, expected) { if self.can_coerce(ref_ty, expected) {

View file

@ -271,7 +271,7 @@ pub fn resolve_interior<'a, 'tcx>(
}, },
_ => mk_bound_region(None), _ => mk_bound_region(None),
}; };
let r = fcx.tcx.mk_region(ty::ReLateBound(current_depth, br)); let r = fcx.tcx.mk_re_late_bound(current_depth, br);
r r
}); });
if captured_tys.insert(ty) { if captured_tys.insert(ty) {
@ -302,7 +302,7 @@ pub fn resolve_interior<'a, 'tcx>(
let var = ty::BoundVar::from_usize(bound_vars.len()); let var = ty::BoundVar::from_usize(bound_vars.len());
bound_vars.push(ty::BoundVariableKind::Region(kind)); bound_vars.push(ty::BoundVariableKind::Region(kind));
counter += 1; counter += 1;
fcx.tcx.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BoundRegion { var, kind })) fcx.tcx.mk_re_late_bound(ty::INNERMOST, ty::BoundRegion { var, kind })
}, },
types: &mut |b| bug!("unexpected bound ty in binder: {b:?}"), types: &mut |b| bug!("unexpected bound ty in binder: {b:?}"),
consts: &mut |b, ty| bug!("unexpected bound ct in binder: {b:?} {ty}"), consts: &mut |b, ty| bug!("unexpected bound ct in binder: {b:?} {ty}"),
@ -364,7 +364,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
let ty = tcx.mk_ref( let ty = tcx.mk_ref(
// Use `ReErased` as `resolve_interior` is going to replace all the // Use `ReErased` as `resolve_interior` is going to replace all the
// regions anyway. // regions anyway.
tcx.mk_region(ty::ReErased), tcx.lifetimes.re_erased,
ty::TypeAndMut { ty, mutbl: hir::Mutability::Not }, ty::TypeAndMut { ty, mutbl: hir::Mutability::Not },
); );
self.interior_visitor.record( self.interior_visitor.record(

View file

@ -363,7 +363,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
opportunistically resolved to {:?}", opportunistically resolved to {:?}",
vid, resolved_vid vid, resolved_vid
); );
let r = self.tcx.mk_region(ty::ReVar(resolved_vid)); let r = self.tcx.mk_re_var(resolved_vid);
self.canonicalize_mode.canonicalize_free_region(self, r) self.canonicalize_mode.canonicalize_free_region(self, r)
} }
@ -737,8 +737,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
) -> ty::Region<'tcx> { ) -> ty::Region<'tcx> {
let var = self.canonical_var(info, r.into()); let var = self.canonical_var(info, r.into());
let br = ty::BoundRegion { var, kind: ty::BrAnon(var.as_u32(), None) }; let br = ty::BoundRegion { var, kind: ty::BrAnon(var.as_u32(), None) };
let region = ty::ReLateBound(self.binder_index, br); self.interner().mk_re_late_bound(self.binder_index, br)
self.interner().mk_region(region)
} }
/// Given a type variable `ty_var` of the given kind, first check /// Given a type variable `ty_var` of the given kind, first check

View file

@ -137,7 +137,7 @@ impl<'tcx> InferCtxt<'tcx> {
CanonicalVarKind::PlaceholderRegion(ty::PlaceholderRegion { universe, name }) => { CanonicalVarKind::PlaceholderRegion(ty::PlaceholderRegion { universe, name }) => {
let universe_mapped = universe_map(universe); let universe_mapped = universe_map(universe);
let placeholder_mapped = ty::PlaceholderRegion { universe: universe_mapped, name }; let placeholder_mapped = ty::PlaceholderRegion { universe: universe_mapped, name };
self.tcx.mk_region(ty::RePlaceholder(placeholder_mapped)).into() self.tcx.mk_re_placeholder(placeholder_mapped).into()
} }
CanonicalVarKind::Const(ui, ty) => self CanonicalVarKind::Const(ui, ty) => self

View file

@ -642,15 +642,14 @@ pub fn make_query_region_constraints<'tcx>(
let constraint = match *k { let constraint = match *k {
// Swap regions because we are going from sub (<=) to outlives // Swap regions because we are going from sub (<=) to outlives
// (>=). // (>=).
Constraint::VarSubVar(v1, v2) => ty::OutlivesPredicate( Constraint::VarSubVar(v1, v2) => {
tcx.mk_region(ty::ReVar(v2)).into(), ty::OutlivesPredicate(tcx.mk_re_var(v2).into(), tcx.mk_re_var(v1))
tcx.mk_region(ty::ReVar(v1)), }
),
Constraint::VarSubReg(v1, r2) => { Constraint::VarSubReg(v1, r2) => {
ty::OutlivesPredicate(r2.into(), tcx.mk_region(ty::ReVar(v1))) ty::OutlivesPredicate(r2.into(), tcx.mk_re_var(v1))
} }
Constraint::RegSubVar(r1, v2) => { Constraint::RegSubVar(r1, v2) => {
ty::OutlivesPredicate(tcx.mk_region(ty::ReVar(v2)).into(), r1) ty::OutlivesPredicate(tcx.mk_re_var(v2).into(), r1)
} }
Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1), Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1),
}; };
@ -690,7 +689,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
} }
fn next_placeholder_region(&mut self, placeholder: ty::PlaceholderRegion) -> ty::Region<'tcx> { fn next_placeholder_region(&mut self, placeholder: ty::PlaceholderRegion) -> ty::Region<'tcx> {
self.infcx.tcx.mk_region(ty::RePlaceholder(placeholder)) self.infcx.tcx.mk_re_placeholder(placeholder)
} }
fn generalize_existential(&mut self, universe: ty::UniverseIndex) -> ty::Region<'tcx> { fn generalize_existential(&mut self, universe: ty::UniverseIndex) -> ty::Region<'tcx> {

View file

@ -14,7 +14,7 @@ use rustc_hir::def_id::DefId;
use rustc_middle::ty::error::ExpectedFound; use rustc_middle::ty::error::ExpectedFound;
use rustc_middle::ty::print::{FmtPrinter, Print, RegionHighlightMode}; use rustc_middle::ty::print::{FmtPrinter, Print, RegionHighlightMode};
use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{self, RePlaceholder, ReVar, Region, TyCtxt}; use rustc_middle::ty::{self, RePlaceholder, Region, TyCtxt};
use std::fmt; use std::fmt;
@ -79,7 +79,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
sup_placeholder @ Region(Interned(RePlaceholder(_), _)), sup_placeholder @ Region(Interned(RePlaceholder(_), _)),
_, _,
)) => self.try_report_trait_placeholder_mismatch( )) => self.try_report_trait_placeholder_mismatch(
Some(self.tcx().mk_region(ReVar(*vid))), Some(self.tcx().mk_re_var(*vid)),
cause, cause,
Some(*sub_placeholder), Some(*sub_placeholder),
Some(*sup_placeholder), Some(*sup_placeholder),
@ -95,7 +95,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
_, _,
_, _,
)) => self.try_report_trait_placeholder_mismatch( )) => self.try_report_trait_placeholder_mismatch(
Some(self.tcx().mk_region(ReVar(*vid))), Some(self.tcx().mk_re_var(*vid)),
cause, cause,
Some(*sub_placeholder), Some(*sub_placeholder),
None, None,
@ -111,7 +111,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
sup_placeholder @ Region(Interned(RePlaceholder(_), _)), sup_placeholder @ Region(Interned(RePlaceholder(_), _)),
_, _,
)) => self.try_report_trait_placeholder_mismatch( )) => self.try_report_trait_placeholder_mismatch(
Some(self.tcx().mk_region(ReVar(*vid))), Some(self.tcx().mk_re_var(*vid)),
cause, cause,
None, None,
Some(*sup_placeholder), Some(*sup_placeholder),
@ -127,7 +127,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
sup_placeholder @ Region(Interned(RePlaceholder(_), _)), sup_placeholder @ Region(Interned(RePlaceholder(_), _)),
_, _,
)) => self.try_report_trait_placeholder_mismatch( )) => self.try_report_trait_placeholder_mismatch(
Some(self.tcx().mk_region(ReVar(*vid))), Some(self.tcx().mk_re_var(*vid)),
cause, cause,
None, None,
Some(*sup_placeholder), Some(*sup_placeholder),
@ -141,7 +141,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
SubregionOrigin::Subtype(box TypeTrace { cause, values }), SubregionOrigin::Subtype(box TypeTrace { cause, values }),
sup_placeholder @ Region(Interned(RePlaceholder(_), _)), sup_placeholder @ Region(Interned(RePlaceholder(_), _)),
)) => self.try_report_trait_placeholder_mismatch( )) => self.try_report_trait_placeholder_mismatch(
Some(self.tcx().mk_region(ReVar(*vid))), Some(self.tcx().mk_re_var(*vid)),
cause, cause,
None, None,
Some(*sup_placeholder), Some(*sup_placeholder),

View file

@ -82,10 +82,10 @@ impl<'tcx> InferCtxt<'tcx> {
let delegate = FnMutDelegate { let delegate = FnMutDelegate {
regions: &mut |br: ty::BoundRegion| { regions: &mut |br: ty::BoundRegion| {
self.tcx.mk_region(ty::RePlaceholder(ty::PlaceholderRegion { self.tcx.mk_re_placeholder(ty::PlaceholderRegion {
universe: next_universe, universe: next_universe,
name: br.kind, name: br.kind,
})) })
}, },
types: &mut |bound_ty: ty::BoundTy| { types: &mut |bound_ty: ty::BoundTy| {
self.tcx.mk_placeholder(ty::PlaceholderType { self.tcx.mk_placeholder(ty::PlaceholderType {

View file

@ -382,7 +382,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
// name the placeholder, then the placeholder is // name the placeholder, then the placeholder is
// larger; otherwise, the only ancestor is `'static`. // larger; otherwise, the only ancestor is `'static`.
Err(placeholder) if empty_ui.can_name(placeholder.universe) => { Err(placeholder) if empty_ui.can_name(placeholder.universe) => {
self.tcx().mk_region(RePlaceholder(placeholder)) self.tcx().mk_re_placeholder(placeholder)
} }
Err(_) => self.tcx().lifetimes.re_static, Err(_) => self.tcx().lifetimes.re_static,
}; };
@ -1046,7 +1046,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
ty::ReVar(rid) => match self.values[rid] { ty::ReVar(rid) => match self.values[rid] {
VarValue::Empty(_) => r, VarValue::Empty(_) => r,
VarValue::Value(r) => r, VarValue::Value(r) => r,
VarValue::ErrorValue => tcx.re_error_misc(), VarValue::ErrorValue => tcx.mk_re_error_misc(),
}, },
_ => r, _ => r,
}; };

View file

@ -1103,7 +1103,7 @@ impl<'tcx> InferCtxt<'tcx> {
) -> ty::Region<'tcx> { ) -> ty::Region<'tcx> {
let region_var = let region_var =
self.inner.borrow_mut().unwrap_region_constraints().new_region_var(universe, origin); self.inner.borrow_mut().unwrap_region_constraints().new_region_var(universe, origin);
self.tcx.mk_region(ty::ReVar(region_var)) self.tcx.mk_re_var(region_var)
} }
/// Return the universe that the region `r` was created in. For /// Return the universe that the region `r` was created in. For

View file

@ -280,7 +280,7 @@ impl<'me, 'tcx> LeakCheck<'me, 'tcx> {
placeholder1: ty::PlaceholderRegion, placeholder1: ty::PlaceholderRegion,
placeholder2: ty::PlaceholderRegion, placeholder2: ty::PlaceholderRegion,
) -> TypeError<'tcx> { ) -> TypeError<'tcx> {
self.error(placeholder1, self.tcx.mk_region(ty::RePlaceholder(placeholder2))) self.error(placeholder1, self.tcx.mk_re_placeholder(placeholder2))
} }
fn error( fn error(
@ -413,19 +413,19 @@ impl<'tcx> MiniGraph<'tcx> {
for undo_entry in undo_log { for undo_entry in undo_log {
match undo_entry { match undo_entry {
&AddConstraint(Constraint::VarSubVar(a, b)) => { &AddConstraint(Constraint::VarSubVar(a, b)) => {
each_edge(tcx.mk_region(ReVar(a)), tcx.mk_region(ReVar(b))); each_edge(tcx.mk_re_var(a), tcx.mk_re_var(b));
} }
&AddConstraint(Constraint::RegSubVar(a, b)) => { &AddConstraint(Constraint::RegSubVar(a, b)) => {
each_edge(a, tcx.mk_region(ReVar(b))); each_edge(a, tcx.mk_re_var(b));
} }
&AddConstraint(Constraint::VarSubReg(a, b)) => { &AddConstraint(Constraint::VarSubReg(a, b)) => {
each_edge(tcx.mk_region(ReVar(a)), b); each_edge(tcx.mk_re_var(a), b);
} }
&AddConstraint(Constraint::RegSubReg(a, b)) => { &AddConstraint(Constraint::RegSubReg(a, b)) => {
each_edge(a, b); each_edge(a, b);
} }
&AddGiven(a, b) => { &AddGiven(a, b) => {
each_edge(a, tcx.mk_region(ReVar(b))); each_edge(a, tcx.mk_re_var(b));
} }
&AddVerify(i) => span_bug!( &AddVerify(i) => span_bug!(
verifys[i].origin.span(), verifys[i].origin.span(),

View file

@ -651,7 +651,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
let unified_region = self.unification_table().probe_value(rid); let unified_region = self.unification_table().probe_value(rid);
unified_region.0.unwrap_or_else(|| { unified_region.0.unwrap_or_else(|| {
let root = self.unification_table().find(rid).vid; let root = self.unification_table().find(rid).vid;
tcx.mk_region(ty::ReVar(root)) tcx.mk_re_var(root)
}) })
} }
_ => region, _ => region,
@ -675,7 +675,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
) -> Region<'tcx> { ) -> Region<'tcx> {
let vars = TwoRegions { a, b }; let vars = TwoRegions { a, b };
if let Some(&c) = self.combine_map(t).get(&vars) { if let Some(&c) = self.combine_map(t).get(&vars) {
return tcx.mk_region(ReVar(c)); return tcx.mk_re_var(c);
} }
let a_universe = self.universe(a); let a_universe = self.universe(a);
let b_universe = self.universe(b); let b_universe = self.universe(b);
@ -683,7 +683,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
let c = self.new_region_var(c_universe, MiscVariable(origin.span())); let c = self.new_region_var(c_universe, MiscVariable(origin.span()));
self.combine_map(t).insert(vars, c); self.combine_map(t).insert(vars, c);
self.undo_log.push(AddCombination(t, vars)); self.undo_log.push(AddCombination(t, vars));
let new_r = tcx.mk_region(ReVar(c)); let new_r = tcx.mk_re_var(c);
for old_r in [a, b] { for old_r in [a, b] {
match t { match t {
Glb => self.make_subregion(origin.clone(), new_r, old_r), Glb => self.make_subregion(origin.clone(), new_r, old_r),

View file

@ -95,7 +95,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for OpportunisticRegionResolver<'a, 'tcx
.borrow_mut() .borrow_mut()
.unwrap_region_constraints() .unwrap_region_constraints()
.opportunistic_resolve_var(rid); .opportunistic_resolve_var(rid);
TypeFolder::interner(self).mk_region(ty::ReVar(resolved)) TypeFolder::interner(self).mk_re_var(resolved)
} }
_ => r, _ => r,
} }

View file

@ -353,7 +353,7 @@ impl<'tcx> CanonicalVarValues<'tcx> {
var: ty::BoundVar::from_usize(i), var: ty::BoundVar::from_usize(i),
kind: ty::BrAnon(i as u32, None), kind: ty::BrAnon(i as u32, None),
}; };
tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)).into() tcx.mk_re_late_bound(ty::INNERMOST, br).into()
} }
CanonicalVarKind::Const(_, ty) CanonicalVarKind::Const(_, ty)
| CanonicalVarKind::PlaceholderConst(_, ty) => tcx | CanonicalVarKind::PlaceholderConst(_, ty) => tcx

View file

@ -697,15 +697,15 @@ impl<'tcx> TyCtxt<'tcx> {
/// Constructs a `RegionKind::ReError` lifetime. /// Constructs a `RegionKind::ReError` lifetime.
#[track_caller] #[track_caller]
pub fn re_error(self, reported: ErrorGuaranteed) -> Region<'tcx> { pub fn mk_re_error(self, reported: ErrorGuaranteed) -> Region<'tcx> {
self.mk_region(ty::ReError(reported)) self.intern_region(ty::ReError(reported))
} }
/// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` to ensure it /// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` to ensure it
/// gets used. /// gets used.
#[track_caller] #[track_caller]
pub fn re_error_misc(self) -> Region<'tcx> { pub fn mk_re_error_misc(self) -> Region<'tcx> {
self.re_error_with_message( self.mk_re_error_with_message(
DUMMY_SP, DUMMY_SP,
"RegionKind::ReError constructed but no error reported", "RegionKind::ReError constructed but no error reported",
) )
@ -714,9 +714,9 @@ impl<'tcx> TyCtxt<'tcx> {
/// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` with the given /// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` with the given
/// `msg` to ensure it gets used. /// `msg` to ensure it gets used.
#[track_caller] #[track_caller]
pub fn re_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Region<'tcx> { pub fn mk_re_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Region<'tcx> {
let reported = self.sess.delay_span_bug(span, msg); let reported = self.sess.delay_span_bug(span, msg);
self.re_error(reported) self.mk_re_error(reported)
} }
/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed` /// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`
@ -1517,7 +1517,7 @@ macro_rules! direct_interners {
} }
direct_interners! { direct_interners! {
region: mk_region(RegionKind<'tcx>): Region -> Region<'tcx>, region: intern_region(RegionKind<'tcx>): Region -> Region<'tcx>,
const_: mk_const_internal(ConstData<'tcx>): Const -> Const<'tcx>, const_: mk_const_internal(ConstData<'tcx>): Const -> Const<'tcx>,
const_allocation: intern_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>, const_allocation: intern_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>,
layout: intern_layout(LayoutS<VariantIdx>): Layout -> Layout<'tcx>, layout: intern_layout(LayoutS<VariantIdx>): Layout -> Layout<'tcx>,
@ -1959,7 +1959,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> GenericArg<'tcx> { pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> GenericArg<'tcx> {
match param.kind { match param.kind {
GenericParamDefKind::Lifetime => { GenericParamDefKind::Lifetime => {
self.mk_region(ty::ReEarlyBound(param.to_early_bound_region_data())).into() self.mk_re_early_bound(param.to_early_bound_region_data()).into()
} }
GenericParamDefKind::Type { .. } => self.mk_ty_param(param.index, param.name).into(), GenericParamDefKind::Type { .. } => self.mk_ty_param(param.index, param.name).into(),
GenericParamDefKind::Const { .. } => self GenericParamDefKind::Const { .. } => self
@ -1991,6 +1991,52 @@ impl<'tcx> TyCtxt<'tcx> {
self.mk_alias(ty::Opaque, self.mk_alias_ty(def_id, substs)) self.mk_alias(ty::Opaque, self.mk_alias_ty(def_id, substs))
} }
#[inline]
pub fn mk_re_early_bound(self, early_bound_region: ty::EarlyBoundRegion) -> Region<'tcx> {
self.intern_region(ty::ReEarlyBound(early_bound_region))
}
#[inline]
pub fn mk_re_late_bound(
self,
debruijn: ty::DebruijnIndex,
bound_region: ty::BoundRegion,
) -> Region<'tcx> {
self.intern_region(ty::ReLateBound(debruijn, bound_region))
}
#[inline]
pub fn mk_re_free(self, scope: DefId, bound_region: ty::BoundRegionKind) -> Region<'tcx> {
self.intern_region(ty::ReFree(ty::FreeRegion { scope, bound_region }))
}
#[inline]
pub fn mk_re_var(self, vid: ty::RegionVid) -> Region<'tcx> {
self.intern_region(ty::ReVar(vid))
}
#[inline]
pub fn mk_re_placeholder(self, placeholder: ty::PlaceholderRegion) -> Region<'tcx> {
self.intern_region(ty::RePlaceholder(placeholder))
}
// Avoid this in favour of more specific `mk_re_*` methods, where possible,
// to avoid the cost of the `match`.
pub fn mk_region(self, kind: ty::RegionKind<'tcx>) -> Region<'tcx> {
match kind {
ty::ReEarlyBound(region) => self.mk_re_early_bound(region),
ty::ReLateBound(debruijn, region) => self.mk_re_late_bound(debruijn, region),
ty::ReFree(ty::FreeRegion { scope, bound_region }) => {
self.mk_re_free(scope, bound_region)
}
ty::ReStatic => self.lifetimes.re_static,
ty::ReVar(vid) => self.mk_re_var(vid),
ty::RePlaceholder(region) => self.mk_re_placeholder(region),
ty::ReErased => self.lifetimes.re_erased,
ty::ReError(reported) => self.mk_re_error(reported),
}
}
pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> { pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> {
self.mk_place_elem(place, PlaceElem::Field(f, ty)) self.mk_place_elem(place, PlaceElem::Field(f, ty))
} }

View file

@ -234,7 +234,7 @@ where
// debruijn index. Then we adjust it to the // debruijn index. Then we adjust it to the
// correct depth. // correct depth.
assert_eq!(debruijn1, ty::INNERMOST); assert_eq!(debruijn1, ty::INNERMOST);
self.tcx.mk_region(ty::ReLateBound(debruijn, br)) self.tcx.mk_re_late_bound(debruijn, br)
} else { } else {
region region
} }
@ -349,10 +349,7 @@ impl<'tcx> TyCtxt<'tcx> {
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,
{ {
self.replace_late_bound_regions_uncached(value, |br| { self.replace_late_bound_regions_uncached(value, |br| {
self.mk_region(ty::ReFree(ty::FreeRegion { self.mk_re_free(all_outlive_scope, br.kind)
scope: all_outlive_scope,
bound_region: br.kind,
}))
}) })
} }
@ -365,10 +362,10 @@ impl<'tcx> TyCtxt<'tcx> {
value, value,
FnMutDelegate { FnMutDelegate {
regions: &mut |r: ty::BoundRegion| { regions: &mut |r: ty::BoundRegion| {
self.mk_region(ty::ReLateBound( self.mk_re_late_bound(
ty::INNERMOST, ty::INNERMOST,
ty::BoundRegion { var: shift_bv(r.var), kind: r.kind }, ty::BoundRegion { var: shift_bv(r.var), kind: r.kind },
)) )
}, },
types: &mut |t: ty::BoundTy| { types: &mut |t: ty::BoundTy| {
self.mk_bound(ty::INNERMOST, ty::BoundTy { var: shift_bv(t.var), kind: t.kind }) self.mk_bound(ty::INNERMOST, ty::BoundTy { var: shift_bv(t.var), kind: t.kind })
@ -409,7 +406,7 @@ impl<'tcx> TyCtxt<'tcx> {
}) })
.expect_region(); .expect_region();
let br = ty::BoundRegion { var, kind }; let br = ty::BoundRegion { var, kind };
self.tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)) self.tcx.mk_re_late_bound(ty::INNERMOST, br)
} }
fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> { fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> {
let entry = self.map.entry(bt.var); let entry = self.map.entry(bt.var);
@ -479,8 +476,7 @@ impl<'tcx> ir::TypeFolder<TyCtxt<'tcx>> for Shifter<'tcx> {
match *r { match *r {
ty::ReLateBound(debruijn, br) if debruijn >= self.current_index => { ty::ReLateBound(debruijn, br) if debruijn >= self.current_index => {
let debruijn = debruijn.shifted_in(self.amount); let debruijn = debruijn.shifted_in(self.amount);
let shifted = ty::ReLateBound(debruijn, br); self.tcx.mk_re_late_bound(debruijn, br)
self.tcx.mk_region(shifted)
} }
_ => r, _ => r,
} }
@ -521,7 +517,7 @@ pub fn shift_region<'tcx>(
) -> ty::Region<'tcx> { ) -> ty::Region<'tcx> {
match *region { match *region {
ty::ReLateBound(debruijn, br) if amount > 0 => { ty::ReLateBound(debruijn, br) if amount > 0 => {
tcx.mk_region(ty::ReLateBound(debruijn.shifted_in(amount), br)) tcx.mk_re_late_bound(debruijn.shifted_in(amount), br)
} }
_ => region, _ => region,
} }

View file

@ -100,7 +100,7 @@ impl GenericParamDef {
preceding_substs: &[ty::GenericArg<'tcx>], preceding_substs: &[ty::GenericArg<'tcx>],
) -> ty::GenericArg<'tcx> { ) -> ty::GenericArg<'tcx> {
match &self.kind { match &self.kind {
ty::GenericParamDefKind::Lifetime => tcx.re_error_misc().into(), ty::GenericParamDefKind::Lifetime => tcx.mk_re_error_misc().into(),
ty::GenericParamDefKind::Type { .. } => tcx.ty_error().into(), ty::GenericParamDefKind::Type { .. } => tcx.ty_error().into(),
ty::GenericParamDefKind::Const { .. } => { ty::GenericParamDefKind::Const { .. } => {
tcx.const_error(tcx.bound_type_of(self.def_id).subst(tcx, preceding_substs)).into() tcx.const_error(tcx.bound_type_of(self.def_id).subst(tcx, preceding_substs)).into()

View file

@ -143,7 +143,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
) )
.emit(); .emit();
self.interner().re_error(e) self.interner().mk_re_error(e)
} }
} }
} }

View file

@ -182,7 +182,7 @@ impl<'tcx> RegionHighlightMode<'tcx> {
/// Convenience wrapper for `highlighting_region`. /// Convenience wrapper for `highlighting_region`.
pub fn highlighting_region_vid(&mut self, vid: ty::RegionVid, number: usize) { pub fn highlighting_region_vid(&mut self, vid: ty::RegionVid, number: usize) {
self.highlighting_region(self.tcx.mk_region(ty::ReVar(vid)), number) self.highlighting_region(self.tcx.mk_re_var(vid), number)
} }
/// Returns `Some(n)` with the number to use for the given region, if any. /// Returns `Some(n)` with the number to use for the given region, if any.
@ -2271,7 +2271,7 @@ impl<'a, 'tcx> ty::ir::TypeFolder<TyCtxt<'tcx>> for RegionFolder<'a, 'tcx> {
}; };
if let ty::ReLateBound(debruijn1, br) = *region { if let ty::ReLateBound(debruijn1, br) = *region {
assert_eq!(debruijn1, ty::INNERMOST); assert_eq!(debruijn1, ty::INNERMOST);
self.tcx.mk_region(ty::ReLateBound(self.current_index, br)) self.tcx.mk_re_late_bound(self.current_index, br)
} else { } else {
region region
} }
@ -2383,10 +2383,10 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
if let Some(lt_idx) = lifetime_idx { if let Some(lt_idx) = lifetime_idx {
if lt_idx > binder_level_idx { if lt_idx > binder_level_idx {
let kind = ty::BrNamed(CRATE_DEF_ID.to_def_id(), name); let kind = ty::BrNamed(CRATE_DEF_ID.to_def_id(), name);
return tcx.mk_region(ty::ReLateBound( return tcx.mk_re_late_bound(
ty::INNERMOST, ty::INNERMOST,
ty::BoundRegion { var: br.var, kind }, ty::BoundRegion { var: br.var, kind },
)); );
} }
} }
@ -2398,10 +2398,10 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
if let Some(lt_idx) = lifetime_idx { if let Some(lt_idx) = lifetime_idx {
if lt_idx > binder_level_idx { if lt_idx > binder_level_idx {
let kind = ty::BrNamed(def_id, name); let kind = ty::BrNamed(def_id, name);
return tcx.mk_region(ty::ReLateBound( return tcx.mk_re_late_bound(
ty::INNERMOST, ty::INNERMOST,
ty::BoundRegion { var: br.var, kind }, ty::BoundRegion { var: br.var, kind },
)); );
} }
} }
@ -2411,10 +2411,10 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
if let Some(lt_idx) = lifetime_idx { if let Some(lt_idx) = lifetime_idx {
if lt_idx > binder_level_idx { if lt_idx > binder_level_idx {
let kind = br.kind; let kind = br.kind;
return tcx.mk_region(ty::ReLateBound( return tcx.mk_re_late_bound(
ty::INNERMOST, ty::INNERMOST,
ty::BoundRegion { var: br.var, kind }, ty::BoundRegion { var: br.var, kind },
)); );
} }
} }
@ -2426,7 +2426,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
start_or_continue(&mut self, "for<", ", "); start_or_continue(&mut self, "for<", ", ");
do_continue(&mut self, name); do_continue(&mut self, name);
} }
tcx.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BoundRegion { var: br.var, kind })) tcx.mk_re_late_bound(ty::INNERMOST, ty::BoundRegion { var: br.var, kind })
}; };
let mut folder = RegionFolder { let mut folder = RegionFolder {
tcx, tcx,

View file

@ -1187,7 +1187,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for SkipBindersAt<'tcx> {
if index == self.index { if index == self.index {
Err(()) Err(())
} else { } else {
Ok(self.interner().mk_region(ty::ReLateBound(index.shifted_out(1), bv))) Ok(self.interner().mk_re_late_bound(index.shifted_out(1), bv))
} }
} else { } else {
r.try_super_fold_with(self) r.try_super_fold_with(self)

View file

@ -564,14 +564,14 @@ impl<'tcx> TyCtxt<'tcx> {
self, self,
closure_def_id: DefId, closure_def_id: DefId,
closure_substs: SubstsRef<'tcx>, closure_substs: SubstsRef<'tcx>,
env_region: ty::RegionKind<'tcx>, env_region: ty::Region<'tcx>,
) -> Option<Ty<'tcx>> { ) -> Option<Ty<'tcx>> {
let closure_ty = self.mk_closure(closure_def_id, closure_substs); let closure_ty = self.mk_closure(closure_def_id, closure_substs);
let closure_kind_ty = closure_substs.as_closure().kind_ty(); let closure_kind_ty = closure_substs.as_closure().kind_ty();
let closure_kind = closure_kind_ty.to_opt_closure_kind()?; let closure_kind = closure_kind_ty.to_opt_closure_kind()?;
let env_ty = match closure_kind { let env_ty = match closure_kind {
ty::ClosureKind::Fn => self.mk_imm_ref(self.mk_region(env_region), closure_ty), ty::ClosureKind::Fn => self.mk_imm_ref(env_region, closure_ty),
ty::ClosureKind::FnMut => self.mk_mut_ref(self.mk_region(env_region), closure_ty), ty::ClosureKind::FnMut => self.mk_mut_ref(env_region, closure_ty),
ty::ClosureKind::FnOnce => closure_ty, ty::ClosureKind::FnOnce => closure_ty,
}; };
Some(env_ty) Some(env_ty)

View file

@ -140,7 +140,7 @@ impl<'tcx> Cx<'tcx> {
var: ty::BoundVar::from_usize(bound_vars.len() - 1), var: ty::BoundVar::from_usize(bound_vars.len() - 1),
kind: ty::BrEnv, kind: ty::BrEnv,
}; };
let env_region = ty::ReLateBound(ty::INNERMOST, br); let env_region = self.tcx.mk_re_late_bound(ty::INNERMOST, br);
let closure_env_ty = let closure_env_ty =
self.tcx.closure_env_ty(closure_def_id, closure_substs, env_region).unwrap(); self.tcx.closure_env_ty(closure_def_id, closure_substs, env_region).unwrap();
let liberated_closure_env_ty = self.tcx.erase_late_bound_regions( let liberated_closure_env_ty = self.tcx.erase_late_bound_regions(

View file

@ -527,8 +527,7 @@ fn virtual_call_violation_for_method<'tcx>(
} }
} }
let trait_object_ty = let trait_object_ty = object_ty_for_trait(tcx, trait_def_id, tcx.lifetimes.re_static);
object_ty_for_trait(tcx, trait_def_id, tcx.mk_region(ty::ReStatic));
// e.g., `Rc<dyn Trait>` // e.g., `Rc<dyn Trait>`
let trait_object_receiver = let trait_object_receiver =

View file

@ -767,7 +767,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for BoundVarReplacer<'_, 'tcx> {
let universe = self.universe_for(debruijn); let universe = self.universe_for(debruijn);
let p = ty::PlaceholderRegion { universe, name: br.kind }; let p = ty::PlaceholderRegion { universe, name: br.kind };
self.mapped_regions.insert(p, br); self.mapped_regions.insert(p, br);
self.infcx.tcx.mk_region(ty::RePlaceholder(p)) self.infcx.tcx.mk_re_placeholder(p)
} }
_ => r, _ => r,
} }
@ -888,7 +888,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for PlaceholderReplacer<'_, 'tcx> {
let db = ty::DebruijnIndex::from_usize( let db = ty::DebruijnIndex::from_usize(
self.universe_indices.len() - index + self.current_index.as_usize() - 1, self.universe_indices.len() - index + self.current_index.as_usize() - 1,
); );
self.interner().mk_region(ty::ReLateBound(db, *replace_var)) self.interner().mk_re_late_bound(db, *replace_var)
} }
None => r1, None => r1,
} }

View file

@ -540,13 +540,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let kind = ty::BoundRegionKind::BrNamed(param.def_id, param.name); let kind = ty::BoundRegionKind::BrNamed(param.def_id, param.name);
let bound_var = ty::BoundVariableKind::Region(kind); let bound_var = ty::BoundVariableKind::Region(kind);
bound_vars.push(bound_var); bound_vars.push(bound_var);
tcx.mk_region(ty::ReLateBound( tcx.mk_re_late_bound(
ty::INNERMOST, ty::INNERMOST,
ty::BoundRegion { ty::BoundRegion {
var: ty::BoundVar::from_usize(bound_vars.len() - 1), var: ty::BoundVar::from_usize(bound_vars.len() - 1),
kind, kind,
}, },
)) )
.into() .into()
} }
GenericParamDefKind::Const { .. } => { GenericParamDefKind::Const { .. } => {

View file

@ -3023,7 +3023,7 @@ fn bind_generator_hidden_types_above<'tcx>(
kind: ty::BrAnon(counter, None), kind: ty::BrAnon(counter, None),
}; };
counter += 1; counter += 1;
r = tcx.mk_region(ty::ReLateBound(current_depth, br)); r = tcx.mk_re_late_bound(current_depth, br);
} }
r r
}) })

View file

@ -732,7 +732,7 @@ fn bound_vars_for_item(tcx: TyCtxt<'_>, def_id: DefId) -> SubstsRef<'_> {
var: ty::BoundVar::from_usize(substs.len()), var: ty::BoundVar::from_usize(substs.len()),
kind: ty::BrAnon(substs.len() as u32, None), kind: ty::BrAnon(substs.len() as u32, None),
}; };
tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)).into() tcx.mk_re_late_bound(ty::INNERMOST, br).into()
} }
ty::GenericParamDefKind::Const { .. } => tcx ty::GenericParamDefKind::Const { .. } => tcx

View file

@ -521,8 +521,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'t
impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'tcx>> { impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'tcx>> {
fn lower_into(self, interner: RustInterner<'tcx>) -> Region<'tcx> { fn lower_into(self, interner: RustInterner<'tcx>) -> Region<'tcx> {
let kind = match self.data(interner) { let tcx = interner.tcx;
chalk_ir::LifetimeData::BoundVar(var) => ty::ReLateBound( match self.data(interner) {
chalk_ir::LifetimeData::BoundVar(var) => tcx.mk_re_late_bound(
ty::DebruijnIndex::from_u32(var.debruijn.depth()), ty::DebruijnIndex::from_u32(var.debruijn.depth()),
ty::BoundRegion { ty::BoundRegion {
var: ty::BoundVar::from_usize(var.index), var: ty::BoundVar::from_usize(var.index),
@ -530,15 +531,14 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t
}, },
), ),
chalk_ir::LifetimeData::InferenceVar(_var) => unimplemented!(), chalk_ir::LifetimeData::InferenceVar(_var) => unimplemented!(),
chalk_ir::LifetimeData::Placeholder(p) => ty::RePlaceholder(ty::Placeholder { chalk_ir::LifetimeData::Placeholder(p) => tcx.mk_re_placeholder(ty::Placeholder {
universe: ty::UniverseIndex::from_usize(p.ui.counter), universe: ty::UniverseIndex::from_usize(p.ui.counter),
name: ty::BoundRegionKind::BrAnon(p.idx as u32, None), name: ty::BoundRegionKind::BrAnon(p.idx as u32, None),
}), }),
chalk_ir::LifetimeData::Static => return interner.tcx.lifetimes.re_static, chalk_ir::LifetimeData::Static => tcx.lifetimes.re_static,
chalk_ir::LifetimeData::Erased => return interner.tcx.lifetimes.re_erased, chalk_ir::LifetimeData::Erased => tcx.lifetimes.re_erased,
chalk_ir::LifetimeData::Phantom(void, _) => match *void {}, chalk_ir::LifetimeData::Phantom(void, _) => match *void {},
}; }
interner.tcx.mk_region(kind)
} }
} }
@ -1025,7 +1025,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for NamedBoundVarSubstitutor<'a, 'tcx> {
ty::BrNamed(def_id, _name) => match self.named_parameters.get(&def_id) { ty::BrNamed(def_id, _name) => match self.named_parameters.get(&def_id) {
Some(idx) => { Some(idx) => {
let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(*idx, None) }; let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(*idx, None) };
return self.tcx.mk_region(ty::ReLateBound(index, new_br)); return self.tcx.mk_re_late_bound(index, new_br);
} }
None => panic!("Missing `BrNamed`."), None => panic!("Missing `BrNamed`."),
}, },
@ -1107,7 +1107,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ParamsSubstitutor<'tcx> {
var: ty::BoundVar::from_u32(*idx), var: ty::BoundVar::from_u32(*idx),
kind: ty::BrAnon(*idx, None), kind: ty::BrAnon(*idx, None),
}; };
self.tcx.mk_region(ty::ReLateBound(self.binder_index, br)) self.tcx.mk_re_late_bound(self.binder_index, br)
} }
None => { None => {
let idx = self.named_regions.len() as u32; let idx = self.named_regions.len() as u32;
@ -1116,7 +1116,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ParamsSubstitutor<'tcx> {
kind: ty::BrAnon(idx, None), kind: ty::BrAnon(idx, None),
}; };
self.named_regions.insert(_re.def_id, idx); self.named_regions.insert(_re.def_id, idx);
self.tcx.mk_region(ty::ReLateBound(self.binder_index, br)) self.tcx.mk_re_late_bound(self.binder_index, br)
} }
}, },

View file

@ -70,7 +70,7 @@ fn fn_sig_for_fn_abi<'tcx>(
var: ty::BoundVar::from_usize(bound_vars.len() - 1), var: ty::BoundVar::from_usize(bound_vars.len() - 1),
kind: ty::BoundRegionKind::BrEnv, kind: ty::BoundRegionKind::BrEnv,
}; };
let env_region = ty::ReLateBound(ty::INNERMOST, br); let env_region = tcx.mk_re_late_bound(ty::INNERMOST, br);
let env_ty = tcx.closure_env_ty(def_id, substs, env_region).unwrap(); let env_ty = tcx.closure_env_ty(def_id, substs, env_region).unwrap();
let sig = sig.skip_binder(); let sig = sig.skip_binder();
@ -95,8 +95,7 @@ fn fn_sig_for_fn_abi<'tcx>(
var: ty::BoundVar::from_usize(bound_vars.len() - 1), var: ty::BoundVar::from_usize(bound_vars.len() - 1),
kind: ty::BoundRegionKind::BrEnv, kind: ty::BoundRegionKind::BrEnv,
}; };
let env_region = ty::ReLateBound(ty::INNERMOST, br); let env_ty = tcx.mk_mut_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), ty);
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);
let pin_did = tcx.require_lang_item(LangItem::Pin, None); let pin_did = tcx.require_lang_item(LangItem::Pin, None);
let pin_adt_ref = tcx.adt_def(pin_did); let pin_adt_ref = tcx.adt_def(pin_did);