Auto merge of #112075 - WaffleLapkin:unmkII, r=lcnr

Replace `tcx.mk_re_*` with `Region::new_*`

Second step in implementing https://github.com/rust-lang/compiler-team/issues/616
r? `@lcnr`
This commit is contained in:
bors 2023-05-30 04:26:59 +00:00
commit 45eec0fe93
42 changed files with 291 additions and 233 deletions

View File

@ -180,24 +180,25 @@ fn report_error(
return;
};
let placeholder_region = tcx.mk_re_placeholder(ty::Placeholder {
universe: adjusted_universe.into(),
bound: placeholder.bound,
});
let placeholder_region = ty::Region::new_placeholder(
tcx,
ty::Placeholder { universe: adjusted_universe.into(), bound: placeholder.bound },
);
let error_region =
if let RegionElement::PlaceholderRegion(error_placeholder) = error_element {
let adjusted_universe =
error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32());
adjusted_universe.map(|adjusted| {
tcx.mk_re_placeholder(ty::Placeholder {
universe: adjusted.into(),
bound: error_placeholder.bound,
})
})
} else {
None
};
let error_region = if let RegionElement::PlaceholderRegion(error_placeholder) =
error_element
{
let adjusted_universe =
error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32());
adjusted_universe.map(|adjusted| {
ty::Region::new_placeholder(
tcx,
ty::Placeholder { universe: adjusted.into(), bound: error_placeholder.bound },
)
})
} else {
None
};
debug!(?placeholder_region);
@ -390,7 +391,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
error_region,
&region_constraints,
|vid| ocx.infcx.region_var_origin(vid),
|vid| ocx.infcx.universe_of_region(ocx.infcx.tcx.mk_re_var(vid)),
|vid| ocx.infcx.universe_of_region(ty::Region::new_var(ocx.infcx.tcx, vid)),
)
}
@ -411,7 +412,7 @@ fn try_extract_error_from_region_constraints<'tcx>(
}
// FIXME: Should this check the universe of the var?
Constraint::VarSubReg(vid, sup) if sup == placeholder_region => {
Some((infcx.tcx.mk_re_var(vid), cause.clone()))
Some((ty::Region::new_var(infcx.tcx, vid), cause.clone()))
}
_ => None,
}

View File

@ -441,7 +441,7 @@ fn for_each_region_constraint<'tcx>(
let subject = match req.subject {
ClosureOutlivesSubject::Region(subject) => format!("{:?}", subject),
ClosureOutlivesSubject::Ty(ty) => {
format!("{:?}", ty.instantiate(tcx, |vid| tcx.mk_re_var(vid)))
format!("{:?}", ty.instantiate(tcx, |vid| ty::Region::new_var(tcx, vid)))
}
};
with_msg(format!("where {}: {:?}", subject, req.outlived_free_region,))?;

View File

@ -1158,7 +1158,7 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
.universal_regions_outlived_by(r_scc)
.filter(|&u_r| !self.universal_regions.is_local_free_region(u_r))
.find(|&u_r| self.eval_equal(u_r, r_vid))
.map(|u_r| tcx.mk_re_var(u_r))
.map(|u_r| ty::Region::new_var(tcx, u_r))
// In the case of a failure, use `ReErased`. We will eventually
// return `None` in this case.
.unwrap_or(tcx.lifetimes.re_erased)
@ -1355,7 +1355,7 @@ fn normalize_to_scc_representatives<T>(&self, tcx: TyCtxt<'tcx>, value: T) -> T
let vid = self.to_region_vid(r);
let scc = self.constraint_sccs.scc(vid);
let repr = self.scc_representatives[scc];
tcx.mk_re_var(repr)
ty::Region::new_var(tcx, repr)
})
}
@ -1779,7 +1779,7 @@ fn check_member_constraints(
}
// If not, report an error.
let member_region = infcx.tcx.mk_re_var(member_region_vid);
let member_region = ty::Region::new_var(infcx.tcx, member_region_vid);
errors_buffer.push(RegionErrorKind::UnexpectedHiddenRegion {
span: m_c.definition_span,
hidden_ty: m_c.hidden_ty,

View File

@ -92,7 +92,8 @@ pub(crate) fn infer_opaque_types(
}
None => {
subst_regions.push(vid);
infcx.tcx.mk_re_error_with_message(
ty::Region::new_error_with_message(
infcx.tcx,
concrete_type.span,
"opaque type with non-universal region substs",
)

View File

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

View File

@ -500,7 +500,7 @@ fn build(self) -> UniversalRegions<'tcx> {
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("c-variadic")))
.as_var();
let region = self.infcx.tcx.mk_re_var(reg_vid);
let region = ty::Region::new_var(self.infcx.tcx, reg_vid);
let va_list_ty =
self.infcx.tcx.type_of(va_list_did).subst(self.infcx.tcx, &[region.into()]);
@ -660,7 +660,7 @@ fn compute_inputs_and_output(
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
kind: ty::BrEnv,
};
let env_region = tcx.mk_re_late_bound(ty::INNERMOST, br);
let env_region = ty::Region::new_late_bound(tcx, ty::INNERMOST, br);
let closure_ty = tcx.closure_env_ty(def_id, substs, env_region).unwrap();
// The "inputs" of the closure in the
@ -778,7 +778,8 @@ fn replace_bound_regions_with_nll_infer_vars<T>(
{
let (value, _map) = self.tcx.replace_late_bound_regions(value, |br| {
debug!(?br);
let liberated_region = self.tcx.mk_re_free(all_outlive_scope.to_def_id(), br.kind);
let liberated_region =
ty::Region::new_free(self.tcx, all_outlive_scope.to_def_id(), br.kind);
let region_vid = {
let name = match br.kind.get_name() {
Some(name) => name,
@ -889,7 +890,7 @@ pub fn fold_to_region_vids<T>(&self, tcx: TyCtxt<'tcx>, value: T) -> T
where
T: TypeFoldable<TyCtxt<'tcx>>,
{
tcx.fold_regions(value, |region, _| tcx.mk_re_var(self.to_region_vid(region)))
tcx.fold_regions(value, |region, _| ty::Region::new_var(tcx, self.to_region_vid(region)))
}
}
@ -929,7 +930,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)) {
let ty::BoundVariableKind::Region(bound_region) = bound_var else { continue; };
let liberated_region = tcx.mk_re_free(mir_def_id.to_def_id(), bound_region);
let liberated_region = ty::Region::new_free(tcx, mir_def_id.to_def_id(), bound_region);
f(liberated_region);
}
}

View File

@ -239,7 +239,7 @@ pub fn ast_region_to_region(
var: ty::BoundVar::from_u32(index),
kind: ty::BrNamed(def_id, name),
};
tcx.mk_re_late_bound(debruijn, br)
ty::Region::new_late_bound(tcx, debruijn, br)
}
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
@ -247,12 +247,12 @@ pub fn ast_region_to_region(
let item_def_id = tcx.hir().ty_param_owner(def_id.expect_local());
let generics = tcx.generics_of(item_def_id);
let index = generics.param_def_id_to_index[&def_id];
tcx.mk_re_early_bound(ty::EarlyBoundRegion { def_id, index, name })
ty::Region::new_early_bound(tcx, ty::EarlyBoundRegion { def_id, index, name })
}
Some(rbv::ResolvedArg::Free(scope, id)) => {
let name = lifetime_name(id.expect_local());
tcx.mk_re_free(scope, ty::BrNamed(id, name))
ty::Region::new_free(tcx, scope, ty::BrNamed(id, name))
// (*) -- not late-bound, won't change
}
@ -269,7 +269,8 @@ pub fn ast_region_to_region(
// elision. `resolve_lifetime` should have
// reported an error in this case -- but if
// not, let's error out.
tcx.mk_re_error_with_message(
ty::Region::new_error_with_message(
tcx,
lifetime.ident.span,
"unelided lifetime in signature",
)
@ -485,7 +486,8 @@ fn inferred_kind(
debug!(?param, "unelided lifetime in signature");
// This indicates an illegal lifetime in a non-assoc-trait position
tcx.mk_re_error_with_message(
ty::Region::new_error_with_message(
tcx,
self.span,
"unelided lifetime in signature",
)
@ -1219,15 +1221,15 @@ fn add_predicates_for_ast_type_binding(
let substs =
candidate.skip_binder().substs.extend_to(tcx, assoc_item.def_id, |param, _| {
let subst = match param.kind {
GenericParamDefKind::Lifetime => tcx
.mk_re_late_bound(
ty::INNERMOST,
ty::BoundRegion {
var: ty::BoundVar::from_usize(num_bound_vars),
kind: ty::BoundRegionKind::BrNamed(param.def_id, param.name),
},
)
.into(),
GenericParamDefKind::Lifetime => ty::Region::new_late_bound(
tcx,
ty::INNERMOST,
ty::BoundRegion {
var: ty::BoundVar::from_usize(num_bound_vars),
kind: ty::BoundRegionKind::BrNamed(param.def_id, param.name),
},
)
.into(),
GenericParamDefKind::Type { .. } => tcx
.mk_bound(
ty::INNERMOST,
@ -1804,7 +1806,7 @@ trait here instead: `trait NewTrait: {} {{}}`",
} else {
err.emit()
};
tcx.mk_re_error(e)
ty::Region::new_error(tcx, e)
})
}
})

View File

@ -472,7 +472,8 @@ fn interner(&self) -> TyCtxt<'tcx> {
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
if let ty::ReFree(fr) = *r {
self.tcx.mk_re_free(
ty::Region::new_free(
self.tcx,
fr.scope,
self.mapping.get(&fr.bound_region).copied().unwrap_or(fr.bound_region),
)
@ -786,9 +787,9 @@ 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())
else {
return tcx.mk_re_error_with_message(return_span, "expected ReFree to map to ReEarlyBound")
return ty::Region::new_error_with_message(tcx, return_span, "expected ReFree to map to ReEarlyBound")
};
tcx.mk_re_early_bound(ty::EarlyBoundRegion {
ty::Region::new_early_bound(tcx, ty::EarlyBoundRegion {
def_id: e.def_id,
name: e.name,
index: (e.index as usize - num_trait_substs + num_impl_substs) as u32,
@ -1933,7 +1934,8 @@ pub(super) fn check_type_bounds<'tcx>(
let kind = ty::BoundRegionKind::BrNamed(param.def_id, param.name);
let bound_var = ty::BoundVariableKind::Region(kind);
bound_vars.push(bound_var);
tcx.mk_re_late_bound(
ty::Region::new_late_bound(
tcx,
ty::INNERMOST,
ty::BoundRegion { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind },
)

View File

@ -183,7 +183,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
}
RegionResolutionError::SubSupConflict(_, _, _, a, _, b, _) => format!("{b}: {a}"),
RegionResolutionError::UpperBoundUniverseConflict(a, _, _, _, b) => {
format!("{b}: {a}", a = tcx.mk_re_var(a))
format!("{b}: {a}", a = ty::Region::new_var(tcx, a))
}
};
guar = Some(

View File

@ -145,11 +145,13 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
]);
let mk_va_list_ty = |mutbl| {
tcx.lang_items().va_list().map(|did| {
let region = tcx.mk_re_late_bound(
let region = ty::Region::new_late_bound(
tcx,
ty::INNERMOST,
ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) },
);
let env_region = tcx.mk_re_late_bound(
let env_region = ty::Region::new_late_bound(
tcx,
ty::INNERMOST,
ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrEnv },
);
@ -393,7 +395,12 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) };
(
1,
vec![tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0))],
vec![
tcx.mk_imm_ref(
ty::Region::new_late_bound(tcx, ty::INNERMOST, br),
param(0),
),
],
tcx.mk_projection(discriminant_def_id, tcx.mk_substs(&[param(0).into()])),
)
}
@ -443,7 +450,8 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
sym::raw_eq => {
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) };
let param_ty = tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0));
let param_ty =
tcx.mk_imm_ref(ty::Region::new_late_bound(tcx, ty::INNERMOST, br), param(0));
(1, vec![param_ty; 2], tcx.types.bool)
}

View File

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

View File

@ -440,7 +440,7 @@ fn projected_ty_from_poly_trait_ref(
self.tcx.replace_late_bound_regions_uncached(
poly_trait_ref,
|_| {
self.tcx.mk_re_early_bound(ty::EarlyBoundRegion {
ty::Region::new_early_bound(self.tcx, ty::EarlyBoundRegion {
def_id: item_def_id,
index: 0,
name: Symbol::intern(&lt_name),

View File

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

View File

@ -269,7 +269,7 @@ pub fn resolve_interior<'a, 'tcx>(
},
_ => mk_bound_region(ty::BrAnon(None)),
};
let r = fcx.tcx.mk_re_late_bound(current_depth, br);
let r = ty::Region::new_late_bound(fcx.tcx, current_depth, br);
r
});
captured_tys.insert(ty).then(|| {
@ -295,7 +295,11 @@ pub fn resolve_interior<'a, 'tcx>(
let var = ty::BoundVar::from_usize(bound_vars.len());
bound_vars.push(ty::BoundVariableKind::Region(kind));
counter += 1;
fcx.tcx.mk_re_late_bound(ty::INNERMOST, ty::BoundRegion { var, kind })
ty::Region::new_late_bound(
fcx.tcx,
ty::INNERMOST,
ty::BoundRegion { var, kind },
)
},
types: &mut |b| bug!("unexpected bound ty in binder: {b:?}"),
consts: &mut |b, ty| bug!("unexpected bound ct in binder: {b:?} {ty}"),

View File

@ -771,7 +771,7 @@ fn canonical_var_for_region(
) -> ty::Region<'tcx> {
let var = self.canonical_var(info, r.into());
let br = ty::BoundRegion { var, kind: ty::BrAnon(None) };
self.interner().mk_re_late_bound(self.binder_index, br)
ty::Region::new_late_bound(self.interner(), self.binder_index, br)
}
/// Given a type variable `ty_var` of the given kind, first check

View File

@ -141,7 +141,7 @@ pub fn instantiate_canonical_var(
CanonicalVarKind::PlaceholderRegion(ty::PlaceholderRegion { universe, bound }) => {
let universe_mapped = universe_map(universe);
let placeholder_mapped = ty::PlaceholderRegion { universe: universe_mapped, bound };
self.tcx.mk_re_placeholder(placeholder_mapped).into()
ty::Region::new_placeholder(self.tcx, placeholder_mapped).into()
}
CanonicalVarKind::Const(ui, ty) => self

View File

@ -668,14 +668,15 @@ pub fn make_query_region_constraints<'tcx>(
let constraint = match *k {
// Swap regions because we are going from sub (<=) to outlives
// (>=).
Constraint::VarSubVar(v1, v2) => {
ty::OutlivesPredicate(tcx.mk_re_var(v2).into(), tcx.mk_re_var(v1))
}
Constraint::VarSubVar(v1, v2) => ty::OutlivesPredicate(
ty::Region::new_var(tcx, v2).into(),
ty::Region::new_var(tcx, v1),
),
Constraint::VarSubReg(v1, r2) => {
ty::OutlivesPredicate(r2.into(), tcx.mk_re_var(v1))
ty::OutlivesPredicate(r2.into(), ty::Region::new_var(tcx, v1))
}
Constraint::RegSubVar(r1, v2) => {
ty::OutlivesPredicate(tcx.mk_re_var(v2).into(), r1)
ty::OutlivesPredicate(ty::Region::new_var(tcx, v2).into(), r1)
}
Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1),
};
@ -719,7 +720,7 @@ fn next_existential_region_var(
}
fn next_placeholder_region(&mut self, placeholder: ty::PlaceholderRegion) -> ty::Region<'tcx> {
self.infcx.tcx.mk_re_placeholder(placeholder)
ty::Region::new_placeholder(self.infcx.tcx, placeholder)
}
fn generalize_existential(&mut self, universe: ty::UniverseIndex) -> ty::Region<'tcx> {

View File

@ -79,7 +79,7 @@ pub(super) fn try_report_placeholder_conflict(
sup_placeholder @ Region(Interned(RePlaceholder(_), _)),
_,
)) => self.try_report_trait_placeholder_mismatch(
Some(self.tcx().mk_re_var(*vid)),
Some(ty::Region::new_var(self.tcx(), *vid)),
cause,
Some(*sub_placeholder),
Some(*sup_placeholder),
@ -95,7 +95,7 @@ pub(super) fn try_report_placeholder_conflict(
_,
_,
)) => self.try_report_trait_placeholder_mismatch(
Some(self.tcx().mk_re_var(*vid)),
Some(ty::Region::new_var(self.tcx(), *vid)),
cause,
Some(*sub_placeholder),
None,
@ -111,7 +111,7 @@ pub(super) fn try_report_placeholder_conflict(
sup_placeholder @ Region(Interned(RePlaceholder(_), _)),
_,
)) => self.try_report_trait_placeholder_mismatch(
Some(self.tcx().mk_re_var(*vid)),
Some(ty::Region::new_var(self.tcx(), *vid)),
cause,
None,
Some(*sup_placeholder),
@ -127,7 +127,7 @@ pub(super) fn try_report_placeholder_conflict(
sup_placeholder @ Region(Interned(RePlaceholder(_), _)),
_,
)) => self.try_report_trait_placeholder_mismatch(
Some(self.tcx().mk_re_var(*vid)),
Some(ty::Region::new_var(self.tcx(), *vid)),
cause,
None,
Some(*sup_placeholder),
@ -141,7 +141,7 @@ pub(super) fn try_report_placeholder_conflict(
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
sup_placeholder @ Region(Interned(RePlaceholder(_), _)),
)) => self.try_report_trait_placeholder_mismatch(
Some(self.tcx().mk_re_var(*vid)),
Some(ty::Region::new_var(self.tcx(), *vid)),
cause,
None,
Some(*sup_placeholder),

View File

@ -82,8 +82,10 @@ pub fn instantiate_binder_with_placeholders<T>(&self, binder: ty::Binder<'tcx, T
let delegate = FnMutDelegate {
regions: &mut |br: ty::BoundRegion| {
self.tcx
.mk_re_placeholder(ty::PlaceholderRegion { universe: next_universe, bound: br })
ty::Region::new_placeholder(
self.tcx,
ty::PlaceholderRegion { universe: next_universe, bound: br },
)
},
types: &mut |bound_ty: ty::BoundTy| {
self.tcx.mk_placeholder(ty::PlaceholderType {

View File

@ -347,7 +347,7 @@ fn expand_node(
// name the placeholder, then the placeholder is
// larger; otherwise, the only ancestor is `'static`.
Err(placeholder) if empty_ui.can_name(placeholder.universe) => {
self.tcx().mk_re_placeholder(placeholder)
ty::Region::new_placeholder(self.tcx(), placeholder)
}
Err(_) => self.tcx().lifetimes.re_static,
};

View File

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

View File

@ -280,7 +280,7 @@ fn placeholder_error(
placeholder1: ty::PlaceholderRegion,
placeholder2: ty::PlaceholderRegion,
) -> TypeError<'tcx> {
self.error(placeholder1, self.tcx.mk_re_placeholder(placeholder2))
self.error(placeholder1, ty::Region::new_placeholder(self.tcx, placeholder2))
}
fn error(
@ -413,13 +413,13 @@ fn iterate_undo_log<'a>(
for undo_entry in undo_log {
match undo_entry {
&AddConstraint(Constraint::VarSubVar(a, b)) => {
each_edge(tcx.mk_re_var(a), tcx.mk_re_var(b));
each_edge(ty::Region::new_var(tcx, a), ty::Region::new_var(tcx, b));
}
&AddConstraint(Constraint::RegSubVar(a, b)) => {
each_edge(a, tcx.mk_re_var(b));
each_edge(a, ty::Region::new_var(tcx, b));
}
&AddConstraint(Constraint::VarSubReg(a, b)) => {
each_edge(tcx.mk_re_var(a), b);
each_edge(ty::Region::new_var(tcx, a), b);
}
&AddConstraint(Constraint::RegSubReg(a, b)) => {
each_edge(a, b);

View File

@ -610,13 +610,13 @@ pub fn opportunistic_resolve_var(
let resolved = ut
.probe_value(root_vid)
.get_value_ignoring_universes()
.unwrap_or_else(|| tcx.mk_re_var(root_vid));
.unwrap_or_else(|| ty::Region::new_var(tcx, root_vid));
// Don't resolve a variable to a region that it cannot name.
if self.var_universe(vid).can_name(self.universe(resolved)) {
resolved
} else {
tcx.mk_re_var(vid)
ty::Region::new_var(tcx, vid)
}
}
@ -637,7 +637,7 @@ fn combine_vars(
) -> Region<'tcx> {
let vars = TwoRegions { a, b };
if let Some(&c) = self.combine_map(t).get(&vars) {
return tcx.mk_re_var(c);
return ty::Region::new_var(tcx, c);
}
let a_universe = self.universe(a);
let b_universe = self.universe(b);
@ -645,7 +645,7 @@ fn combine_vars(
let c = self.new_region_var(c_universe, MiscVariable(origin.span()));
self.combine_map(t).insert(vars, c);
self.undo_log.push(AddCombination(t, vars));
let new_r = tcx.mk_re_var(c);
let new_r = ty::Region::new_var(tcx, c);
for old_r in [a, b] {
match t {
Glb => self.make_subregion(origin.clone(), new_r, old_r),

View File

@ -415,7 +415,7 @@ pub fn make_identity(
var: ty::BoundVar::from_usize(i),
kind: ty::BrAnon(None),
};
tcx.mk_re_late_bound(ty::INNERMOST, br).into()
ty::Region::new_late_bound(tcx, ty::INNERMOST, br).into()
}
CanonicalVarKind::Const(_, ty)
| CanonicalVarKind::PlaceholderConst(_, ty) => tcx

View File

@ -413,7 +413,7 @@ pub fn bind(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self {
ty::ReVar(vid) => {
let br =
ty::BoundRegion { var: ty::BoundVar::new(vid.index()), kind: ty::BrAnon(None) };
tcx.mk_re_late_bound(depth, br)
ty::Region::new_late_bound(tcx, depth, br)
}
_ => bug!("unexpected region in ClosureOutlivesSubjectTy: {r:?}"),
});

View File

@ -264,7 +264,7 @@ fn decode(decoder: &mut D) -> Self {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Region<'tcx> {
fn decode(decoder: &mut D) -> Self {
decoder.interner().mk_region_from_kind(Decodable::decode(decoder))
ty::Region::new_from_kind(decoder.interner(), Decodable::decode(decoder))
}
}

View File

@ -723,34 +723,6 @@ pub fn ty_error_with_message<S: Into<MultiSpan>>(
self.mk_ty_from_kind(Error(reported))
}
/// Constructs a `RegionKind::ReError` lifetime.
#[track_caller]
pub fn mk_re_error(self, reported: ErrorGuaranteed) -> Region<'tcx> {
self.intern_region(ty::ReError(reported))
}
/// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` to ensure it
/// gets used.
#[track_caller]
pub fn mk_re_error_misc(self) -> Region<'tcx> {
self.mk_re_error_with_message(
DUMMY_SP,
"RegionKind::ReError constructed but no error reported",
)
}
/// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` with the given
/// `msg` to ensure it gets used.
#[track_caller]
pub fn mk_re_error_with_message<S: Into<MultiSpan>>(
self,
span: S,
msg: &'static str,
) -> Region<'tcx> {
let reported = self.sess.delay_span_bug(span, msg);
self.mk_re_error(reported)
}
/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`
#[track_caller]
pub fn const_error(self, ty: Ty<'tcx>, reported: ErrorGuaranteed) -> Const<'tcx> {
@ -1529,9 +1501,9 @@ impl<'tcx> TyCtxt<'tcx> {
// Functions with a `mk_` prefix are intended for use outside this file and
// crate. Functions with an `intern_` prefix are intended for use within this
// file only, and have a corresponding `mk_` function.
// crate only, and have a corresponding `mk_` function.
direct_interners! {
region: intern_region(RegionKind<'tcx>): Region -> Region<'tcx>,
region: pub(crate) intern_region(RegionKind<'tcx>): Region -> Region<'tcx>,
const_: intern_const(ConstData<'tcx>): Const -> Const<'tcx>,
const_allocation: pub mk_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>,
layout: pub mk_layout(LayoutS): Layout -> Layout<'tcx>,
@ -2006,7 +1978,7 @@ pub fn mk_ty_param(self, index: u32, name: Symbol) -> Ty<'tcx> {
pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> GenericArg<'tcx> {
match param.kind {
GenericParamDefKind::Lifetime => {
self.mk_re_early_bound(param.to_early_bound_region_data()).into()
ty::Region::new_early_bound(self, param.to_early_bound_region_data()).into()
}
GenericParamDefKind::Type { .. } => self.mk_ty_param(param.index, param.name).into(),
GenericParamDefKind::Const { .. } => self
@ -2046,65 +2018,6 @@ pub fn mk_opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
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> {
// Use a pre-interned one when possible.
if let ty::BoundRegion { var, kind: ty::BrAnon(None) } = bound_region
&& let Some(inner) = self.lifetimes.re_late_bounds.get(debruijn.as_usize())
&& let Some(re) = inner.get(var.as_usize()).copied()
{
re
} else {
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, v: ty::RegionVid) -> Region<'tcx> {
// Use a pre-interned one when possible.
self.lifetimes
.re_vars
.get(v.as_usize())
.copied()
.unwrap_or_else(|| self.intern_region(ty::ReVar(v)))
}
#[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_from_kind(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: FieldIdx, ty: Ty<'tcx>) -> Place<'tcx> {
self.mk_place_elem(place, PlaceElem::Field(f, ty))
}

View File

@ -213,7 +213,7 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
// debruijn index. Then we adjust it to the
// correct depth.
assert_eq!(debruijn1, ty::INNERMOST);
self.tcx.mk_re_late_bound(debruijn, br)
ty::Region::new_late_bound(self.tcx, debruijn, br)
} else {
region
}
@ -328,7 +328,7 @@ pub fn liberate_late_bound_regions<T>(
T: TypeFoldable<TyCtxt<'tcx>>,
{
self.replace_late_bound_regions_uncached(value, |br| {
self.mk_re_free(all_outlive_scope, br.kind)
ty::Region::new_free(self, all_outlive_scope, br.kind)
})
}
@ -341,7 +341,8 @@ pub fn shift_bound_var_indices<T>(self, bound_vars: usize, value: T) -> T
value,
FnMutDelegate {
regions: &mut |r: ty::BoundRegion| {
self.mk_re_late_bound(
ty::Region::new_late_bound(
self,
ty::INNERMOST,
ty::BoundRegion { var: shift_bv(r.var), kind: r.kind },
)
@ -383,7 +384,7 @@ fn replace_region(&mut self, br: ty::BoundRegion) -> ty::Region<'tcx> {
.or_insert_with(|| ty::BoundVariableKind::Region(ty::BrAnon(None)))
.expect_region();
let br = ty::BoundRegion { var, kind };
self.tcx.mk_re_late_bound(ty::INNERMOST, br)
ty::Region::new_late_bound(self.tcx, ty::INNERMOST, br)
}
fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> {
let entry = self.map.entry(bt.var);
@ -451,7 +452,7 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r {
ty::ReLateBound(debruijn, br) if debruijn >= self.current_index => {
let debruijn = debruijn.shifted_in(self.amount);
self.tcx.mk_re_late_bound(debruijn, br)
ty::Region::new_late_bound(self.tcx, debruijn, br)
}
_ => r,
}
@ -492,7 +493,7 @@ pub fn shift_region<'tcx>(
) -> ty::Region<'tcx> {
match *region {
ty::ReLateBound(debruijn, br) if amount > 0 => {
tcx.mk_re_late_bound(debruijn.shifted_in(amount), br)
ty::Region::new_late_bound(tcx, debruijn.shifted_in(amount), br)
}
_ => region,
}

View File

@ -100,7 +100,7 @@ pub fn to_error<'tcx>(
preceding_substs: &[ty::GenericArg<'tcx>],
) -> ty::GenericArg<'tcx> {
match &self.kind {
ty::GenericParamDefKind::Lifetime => tcx.mk_re_error_misc().into(),
ty::GenericParamDefKind::Lifetime => ty::Region::new_error_misc(tcx).into(),
ty::GenericParamDefKind::Type { .. } => tcx.ty_error_misc().into(),
ty::GenericParamDefKind::Const { .. } => {
tcx.const_error_misc(tcx.type_of(self.def_id).subst(tcx, preceding_substs)).into()

View File

@ -141,7 +141,7 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
)
.emit();
self.interner().mk_re_error(e)
ty::Region::new_error(self.interner(), e)
}
}
}

View File

@ -184,7 +184,7 @@ pub fn highlighting_region(&mut self, region: ty::Region<'tcx>, number: usize) {
/// Convenience wrapper for `highlighting_region`.
pub fn highlighting_region_vid(&mut self, vid: ty::RegionVid, number: usize) {
self.highlighting_region(self.tcx.mk_re_var(vid), number)
self.highlighting_region(ty::Region::new_var(self.tcx, vid), number)
}
/// Returns `Some(n)` with the number to use for the given region, if any.
@ -2303,7 +2303,7 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
};
if let ty::ReLateBound(debruijn1, br) = *region {
assert_eq!(debruijn1, ty::INNERMOST);
self.tcx.mk_re_late_bound(self.current_index, br)
ty::Region::new_late_bound(self.tcx, self.current_index, br)
} else {
region
}
@ -2415,7 +2415,8 @@ fn name_by_region_index(
if let Some(lt_idx) = lifetime_idx {
if lt_idx > binder_level_idx {
let kind = ty::BrNamed(CRATE_DEF_ID.to_def_id(), name);
return tcx.mk_re_late_bound(
return ty::Region::new_late_bound(
tcx,
ty::INNERMOST,
ty::BoundRegion { var: br.var, kind },
);
@ -2430,7 +2431,8 @@ fn name_by_region_index(
if let Some(lt_idx) = lifetime_idx {
if lt_idx > binder_level_idx {
let kind = ty::BrNamed(def_id, name);
return tcx.mk_re_late_bound(
return ty::Region::new_late_bound(
tcx,
ty::INNERMOST,
ty::BoundRegion { var: br.var, kind },
);
@ -2443,7 +2445,8 @@ fn name_by_region_index(
if let Some(lt_idx) = lifetime_idx {
if lt_idx > binder_level_idx {
let kind = br.kind;
return tcx.mk_re_late_bound(
return ty::Region::new_late_bound(
tcx,
ty::INNERMOST,
ty::BoundRegion { var: br.var, kind },
);
@ -2458,7 +2461,11 @@ fn name_by_region_index(
start_or_continue(&mut self, "for<", ", ");
do_continue(&mut self, name);
}
tcx.mk_re_late_bound(ty::INNERMOST, ty::BoundRegion { var: br.var, kind })
ty::Region::new_late_bound(
tcx,
ty::INNERMOST,
ty::BoundRegion { var: br.var, kind },
)
};
let mut folder = RegionFolder {
tcx,

View File

@ -15,14 +15,14 @@
use polonius_engine::Atom;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::intern::Interned;
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
use rustc_errors::{DiagnosticArgValue, ErrorGuaranteed, IntoDiagnosticArg, MultiSpan};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::LangItem;
use rustc_index::Idx;
use rustc_macros::HashStable;
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::Span;
use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
use rustc_target::spec::abi::{self, Abi};
use std::borrow::Cow;
@ -1459,6 +1459,103 @@ pub fn for_def(def: &ty::GenericParamDef) -> ParamConst {
#[rustc_pass_by_value]
pub struct Region<'tcx>(pub Interned<'tcx, RegionKind<'tcx>>);
impl<'tcx> Region<'tcx> {
#[inline]
pub fn new_early_bound(
tcx: TyCtxt<'tcx>,
early_bound_region: ty::EarlyBoundRegion,
) -> Region<'tcx> {
tcx.intern_region(ty::ReEarlyBound(early_bound_region))
}
#[inline]
pub fn new_late_bound(
tcx: TyCtxt<'tcx>,
debruijn: ty::DebruijnIndex,
bound_region: ty::BoundRegion,
) -> Region<'tcx> {
// Use a pre-interned one when possible.
if let ty::BoundRegion { var, kind: ty::BrAnon(None) } = bound_region
&& let Some(inner) = tcx.lifetimes.re_late_bounds.get(debruijn.as_usize())
&& let Some(re) = inner.get(var.as_usize()).copied()
{
re
} else {
tcx.intern_region(ty::ReLateBound(debruijn, bound_region))
}
}
#[inline]
pub fn new_free(
tcx: TyCtxt<'tcx>,
scope: DefId,
bound_region: ty::BoundRegionKind,
) -> Region<'tcx> {
tcx.intern_region(ty::ReFree(ty::FreeRegion { scope, bound_region }))
}
#[inline]
pub fn new_var(tcx: TyCtxt<'tcx>, v: ty::RegionVid) -> Region<'tcx> {
// Use a pre-interned one when possible.
tcx.lifetimes
.re_vars
.get(v.as_usize())
.copied()
.unwrap_or_else(|| tcx.intern_region(ty::ReVar(v)))
}
#[inline]
pub fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderRegion) -> Region<'tcx> {
tcx.intern_region(ty::RePlaceholder(placeholder))
}
/// Constructs a `RegionKind::ReError` region.
#[track_caller]
pub fn new_error(tcx: TyCtxt<'tcx>, reported: ErrorGuaranteed) -> Region<'tcx> {
tcx.intern_region(ty::ReError(reported))
}
/// Constructs a `RegionKind::ReError` region and registers a `delay_span_bug` to ensure it
/// gets used.
#[track_caller]
pub fn new_error_misc(tcx: TyCtxt<'tcx>) -> Region<'tcx> {
Region::new_error_with_message(
tcx,
DUMMY_SP,
"RegionKind::ReError constructed but no error reported",
)
}
/// Constructs a `RegionKind::ReError` region and registers a `delay_span_bug` with the given
/// `msg` to ensure it gets used.
#[track_caller]
pub fn new_error_with_message<S: Into<MultiSpan>>(
tcx: TyCtxt<'tcx>,
span: S,
msg: &'static str,
) -> Region<'tcx> {
let reported = tcx.sess.delay_span_bug(span, msg);
Region::new_error(tcx, reported)
}
/// Avoid this in favour of more specific `new_*` methods, where possible,
/// 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::ReLateBound(debruijn, region) => Region::new_late_bound(tcx, debruijn, region),
ty::ReFree(ty::FreeRegion { scope, bound_region }) => {
Region::new_free(tcx, scope, bound_region)
}
ty::ReStatic => tcx.lifetimes.re_static,
ty::ReVar(vid) => Region::new_var(tcx, vid),
ty::RePlaceholder(region) => Region::new_placeholder(tcx, region),
ty::ReErased => tcx.lifetimes.re_erased,
ty::ReError(reported) => Region::new_error(tcx, reported),
}
}
}
impl<'tcx> Deref for Region<'tcx> {
type Target = RegionKind<'tcx>;

View File

@ -142,7 +142,7 @@ fn closure_env_param(&self, owner_def: LocalDefId, owner_id: HirId) -> Option<Pa
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
kind: ty::BrEnv,
};
let env_region = self.tcx.mk_re_late_bound(ty::INNERMOST, br);
let env_region = ty::Region::new_late_bound(self.tcx, ty::INNERMOST, br);
let closure_env_ty =
self.tcx.closure_env_ty(closure_def_id, closure_substs, env_region).unwrap();
let liberated_closure_env_ty = self.tcx.erase_late_bound_regions(

View File

@ -96,7 +96,7 @@ pub(in crate::solve) fn replace_erased_lifetimes_with_bound_vars<'tcx>(
let br =
ty::BoundRegion { var: ty::BoundVar::from_u32(counter), kind: ty::BrAnon(None) };
counter += 1;
tcx.mk_re_late_bound(current_depth, br)
ty::Region::new_late_bound(tcx, current_depth, br)
}
// All free regions should be erased here.
r => bug!("unexpected region: {r:?}"),

View File

@ -255,7 +255,7 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
}),
);
let br = ty::BoundRegion { var, kind: BrAnon(None) };
self.interner().mk_re_late_bound(self.binder_index, br)
ty::Region::new_late_bound(self.interner(), self.binder_index, br)
}
fn fold_ty(&mut self, mut t: Ty<'tcx>) -> Ty<'tcx> {

View File

@ -824,7 +824,7 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
let universe = self.universe_for(debruijn);
let p = ty::PlaceholderRegion { universe, bound: br };
self.mapped_regions.insert(p, br);
self.infcx.tcx.mk_re_placeholder(p)
ty::Region::new_placeholder(self.infcx.tcx, p)
}
_ => r,
}
@ -945,7 +945,7 @@ fn fold_region(&mut self, r0: ty::Region<'tcx>) -> ty::Region<'tcx> {
let db = ty::DebruijnIndex::from_usize(
self.universe_indices.len() - index + self.current_index.as_usize() - 1,
);
self.interner().mk_re_late_bound(db, *replace_var)
ty::Region::new_late_bound(self.interner(), db, *replace_var)
}
None => r1,
}

View File

@ -550,7 +550,8 @@ fn confirm_object_candidate(
let kind = ty::BoundRegionKind::BrNamed(param.def_id, param.name);
let bound_var = ty::BoundVariableKind::Region(kind);
bound_vars.push(bound_var);
tcx.mk_re_late_bound(
ty::Region::new_late_bound(
tcx,
ty::INNERMOST,
ty::BoundRegion {
var: ty::BoundVar::from_usize(bound_vars.len() - 1),

View File

@ -3027,7 +3027,7 @@ fn bind_generator_hidden_types_above<'tcx>(
kind: ty::BrAnon(None),
};
counter += 1;
tcx.mk_re_late_bound(current_depth, br)
ty::Region::new_late_bound(tcx, current_depth, br)
}
r => bug!("unexpected region: {r:?}"),
})

View File

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

View File

@ -542,7 +542,8 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t
fn lower_into(self, interner: RustInterner<'tcx>) -> Region<'tcx> {
let tcx = interner.tcx;
match self.data(interner) {
chalk_ir::LifetimeData::BoundVar(var) => tcx.mk_re_late_bound(
chalk_ir::LifetimeData::BoundVar(var) => ty::Region::new_late_bound(
tcx,
ty::DebruijnIndex::from_u32(var.debruijn.depth()),
ty::BoundRegion {
var: ty::BoundVar::from_usize(var.index),
@ -550,13 +551,16 @@ fn lower_into(self, interner: RustInterner<'tcx>) -> Region<'tcx> {
},
),
chalk_ir::LifetimeData::InferenceVar(_var) => unimplemented!(),
chalk_ir::LifetimeData::Placeholder(p) => tcx.mk_re_placeholder(ty::Placeholder {
universe: ty::UniverseIndex::from_usize(p.ui.counter),
bound: ty::BoundRegion {
var: ty::BoundVar::from_usize(p.idx),
kind: ty::BoundRegionKind::BrAnon(None),
chalk_ir::LifetimeData::Placeholder(p) => ty::Region::new_placeholder(
tcx,
ty::Placeholder {
universe: ty::UniverseIndex::from_usize(p.ui.counter),
bound: ty::BoundRegion {
var: ty::BoundVar::from_usize(p.idx),
kind: ty::BoundRegionKind::BrAnon(None),
},
},
}),
),
chalk_ir::LifetimeData::Static => tcx.lifetimes.re_static,
chalk_ir::LifetimeData::Erased => tcx.lifetimes.re_erased,
chalk_ir::LifetimeData::Phantom(void, _) => match *void {},
@ -1051,7 +1055,7 @@ fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
ty::BrNamed(def_id, _name) => match self.named_parameters.get(&def_id) {
Some(_) => {
let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(None) };
return self.tcx.mk_re_late_bound(index, new_br);
return ty::Region::new_late_bound(self.tcx, index, new_br);
}
None => panic!("Missing `BrNamed`."),
},
@ -1142,7 +1146,7 @@ fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
var: ty::BoundVar::from_u32(*idx),
kind: ty::BrAnon(None),
};
self.tcx.mk_re_late_bound(self.binder_index, br)
ty::Region::new_late_bound(self.tcx, self.binder_index, br)
}
None => {
let idx = self.named_regions.len() as u32;
@ -1151,7 +1155,7 @@ fn fold_region(&mut self, r: Region<'tcx>) -> Region<'tcx> {
kind: ty::BrAnon(None),
};
self.named_regions.insert(_re.def_id, idx);
self.tcx.mk_re_late_bound(self.binder_index, br)
ty::Region::new_late_bound(self.tcx, self.binder_index, br)
}
},

View File

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

View File

@ -287,12 +287,13 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) -> std::ops::ControlFlow<Self::BreakTy> {
let shifted_alias_ty = self.tcx.fold_regions(unshifted_alias_ty, |re, depth| {
if let ty::ReLateBound(index, bv) = re.kind() {
if depth != ty::INNERMOST {
return self.tcx.mk_re_error_with_message(
return ty::Region::new_error_with_message(
self.tcx,
DUMMY_SP,
"we shouldn't walk non-predicate binders with `impl Trait`...",
);
}
self.tcx.mk_re_late_bound(index.shifted_out_to_binder(self.depth), bv)
ty::Region::new_late_bound(self.tcx, index.shifted_out_to_binder(self.depth), bv)
} else {
re
}