Rename tcx.mk_re_*
=> Region::new_*
This commit is contained in:
parent
498553fc04
commit
e33e20824f
42 changed files with 291 additions and 233 deletions
|
@ -180,24 +180,25 @@ trait TypeOpInfo<'tcx> {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let placeholder_region = tcx.mk_re_placeholder(ty::Placeholder {
|
let placeholder_region = ty::Region::new_placeholder(
|
||||||
universe: adjusted_universe.into(),
|
tcx,
|
||||||
bound: placeholder.bound,
|
ty::Placeholder { universe: adjusted_universe.into(), bound: placeholder.bound },
|
||||||
});
|
);
|
||||||
|
|
||||||
let error_region =
|
let error_region = if let RegionElement::PlaceholderRegion(error_placeholder) =
|
||||||
if let RegionElement::PlaceholderRegion(error_placeholder) = error_element {
|
error_element
|
||||||
let adjusted_universe =
|
{
|
||||||
error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32());
|
let adjusted_universe =
|
||||||
adjusted_universe.map(|adjusted| {
|
error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32());
|
||||||
tcx.mk_re_placeholder(ty::Placeholder {
|
adjusted_universe.map(|adjusted| {
|
||||||
universe: adjusted.into(),
|
ty::Region::new_placeholder(
|
||||||
bound: error_placeholder.bound,
|
tcx,
|
||||||
})
|
ty::Placeholder { universe: adjusted.into(), bound: error_placeholder.bound },
|
||||||
})
|
)
|
||||||
} else {
|
})
|
||||||
None
|
} else {
|
||||||
};
|
None
|
||||||
|
};
|
||||||
|
|
||||||
debug!(?placeholder_region);
|
debug!(?placeholder_region);
|
||||||
|
|
||||||
|
@ -390,7 +391,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
|
||||||
error_region,
|
error_region,
|
||||||
®ion_constraints,
|
®ion_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_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?
|
// 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_re_var(vid), cause.clone()))
|
Some((ty::Region::new_var(infcx.tcx, vid), cause.clone()))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
|
@ -441,7 +441,7 @@ fn for_each_region_constraint<'tcx>(
|
||||||
let subject = match req.subject {
|
let subject = match req.subject {
|
||||||
ClosureOutlivesSubject::Region(subject) => format!("{:?}", subject),
|
ClosureOutlivesSubject::Region(subject) => format!("{:?}", subject),
|
||||||
ClosureOutlivesSubject::Ty(ty) => {
|
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,))?;
|
with_msg(format!("where {}: {:?}", subject, req.outlived_free_region,))?;
|
||||||
|
|
|
@ -1158,7 +1158,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
.universal_regions_outlived_by(r_scc)
|
.universal_regions_outlived_by(r_scc)
|
||||||
.filter(|&u_r| !self.universal_regions.is_local_free_region(u_r))
|
.filter(|&u_r| !self.universal_regions.is_local_free_region(u_r))
|
||||||
.find(|&u_r| self.eval_equal(u_r, r_vid))
|
.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
|
// In the case of a failure, use `ReErased`. We will eventually
|
||||||
// return `None` in this case.
|
// return `None` in this case.
|
||||||
.unwrap_or(tcx.lifetimes.re_erased)
|
.unwrap_or(tcx.lifetimes.re_erased)
|
||||||
|
@ -1355,7 +1355,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_re_var(repr)
|
ty::Region::new_var(tcx, repr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1779,7 +1779,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not, report an error.
|
// 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 {
|
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,
|
||||||
|
|
|
@ -92,7 +92,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
subst_regions.push(vid);
|
subst_regions.push(vid);
|
||||||
infcx.tcx.mk_re_error_with_message(
|
ty::Region::new_error_with_message(
|
||||||
|
infcx.tcx,
|
||||||
concrete_type.span,
|
concrete_type.span,
|
||||||
"opaque type with non-universal region substs",
|
"opaque type with non-universal region substs",
|
||||||
)
|
)
|
||||||
|
|
|
@ -139,7 +139,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_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 {
|
let mut constraints = MirTypeckRegionConstraints {
|
||||||
placeholder_indices: PlaceholderIndices::default(),
|
placeholder_indices: PlaceholderIndices::default(),
|
||||||
placeholder_index_to_region: IndexVec::default(),
|
placeholder_index_to_region: IndexVec::default(),
|
||||||
|
|
|
@ -500,7 +500,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||||
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("c-variadic")))
|
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("c-variadic")))
|
||||||
.as_var();
|
.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 =
|
let va_list_ty =
|
||||||
self.infcx.tcx.type_of(va_list_did).subst(self.infcx.tcx, &[region.into()]);
|
self.infcx.tcx.type_of(va_list_did).subst(self.infcx.tcx, &[region.into()]);
|
||||||
|
|
||||||
|
@ -660,7 +660,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 = 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();
|
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
|
||||||
|
@ -778,7 +778,8 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, '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_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 region_vid = {
|
||||||
let name = match br.kind.get_name() {
|
let name = match br.kind.get_name() {
|
||||||
Some(name) => name,
|
Some(name) => name,
|
||||||
|
@ -889,7 +890,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
|
||||||
where
|
where
|
||||||
T: TypeFoldable<TyCtxt<'tcx>>,
|
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)) {
|
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.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);
|
f(liberated_region);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -239,7 +239,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_re_late_bound(debruijn, br)
|
ty::Region::new_late_bound(tcx, debruijn, br)
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
|
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
|
||||||
|
@ -247,12 +247,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_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)) => {
|
Some(rbv::ResolvedArg::Free(scope, id)) => {
|
||||||
let name = lifetime_name(id.expect_local());
|
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
|
// (*) -- not late-bound, won't change
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,8 @@ 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.mk_re_error_with_message(
|
ty::Region::new_error_with_message(
|
||||||
|
tcx,
|
||||||
lifetime.ident.span,
|
lifetime.ident.span,
|
||||||
"unelided lifetime in signature",
|
"unelided lifetime in signature",
|
||||||
)
|
)
|
||||||
|
@ -485,7 +486,8 @@ 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.mk_re_error_with_message(
|
ty::Region::new_error_with_message(
|
||||||
|
tcx,
|
||||||
self.span,
|
self.span,
|
||||||
"unelided lifetime in signature",
|
"unelided lifetime in signature",
|
||||||
)
|
)
|
||||||
|
@ -1219,15 +1221,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
let substs =
|
let substs =
|
||||||
candidate.skip_binder().substs.extend_to(tcx, assoc_item.def_id, |param, _| {
|
candidate.skip_binder().substs.extend_to(tcx, assoc_item.def_id, |param, _| {
|
||||||
let subst = match param.kind {
|
let subst = match param.kind {
|
||||||
GenericParamDefKind::Lifetime => tcx
|
GenericParamDefKind::Lifetime => ty::Region::new_late_bound(
|
||||||
.mk_re_late_bound(
|
tcx,
|
||||||
ty::INNERMOST,
|
ty::INNERMOST,
|
||||||
ty::BoundRegion {
|
ty::BoundRegion {
|
||||||
var: ty::BoundVar::from_usize(num_bound_vars),
|
var: ty::BoundVar::from_usize(num_bound_vars),
|
||||||
kind: ty::BoundRegionKind::BrNamed(param.def_id, param.name),
|
kind: ty::BoundRegionKind::BrNamed(param.def_id, param.name),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
GenericParamDefKind::Type { .. } => tcx
|
GenericParamDefKind::Type { .. } => tcx
|
||||||
.mk_bound(
|
.mk_bound(
|
||||||
ty::INNERMOST,
|
ty::INNERMOST,
|
||||||
|
@ -1804,7 +1806,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
} else {
|
} else {
|
||||||
err.emit()
|
err.emit()
|
||||||
};
|
};
|
||||||
tcx.mk_re_error(e)
|
ty::Region::new_error(tcx, e)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -472,7 +472,8 @@ 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_re_free(
|
ty::Region::new_free(
|
||||||
|
self.tcx,
|
||||||
fr.scope,
|
fr.scope,
|
||||||
self.mapping.get(&fr.bound_region).copied().unwrap_or(fr.bound_region),
|
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(®ion.into()).map(|r| r.expect_region().kind())
|
let Some(ty::ReEarlyBound(e)) = map.get(®ion.into()).map(|r| r.expect_region().kind())
|
||||||
else {
|
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,
|
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,
|
||||||
|
@ -1933,7 +1934,8 @@ 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_re_late_bound(
|
ty::Region::new_late_bound(
|
||||||
|
tcx,
|
||||||
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 },
|
||||||
)
|
)
|
||||||
|
|
|
@ -183,7 +183,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
|
||||||
}
|
}
|
||||||
RegionResolutionError::SubSupConflict(_, _, _, a, _, b, _) => format!("{b}: {a}"),
|
RegionResolutionError::SubSupConflict(_, _, _, a, _, b, _) => format!("{b}: {a}"),
|
||||||
RegionResolutionError::UpperBoundUniverseConflict(a, _, _, _, b) => {
|
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(
|
guar = Some(
|
||||||
|
|
|
@ -145,11 +145,13 @@ 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_re_late_bound(
|
let region = ty::Region::new_late_bound(
|
||||||
|
tcx,
|
||||||
ty::INNERMOST,
|
ty::INNERMOST,
|
||||||
ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) },
|
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::INNERMOST,
|
||||||
ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrEnv },
|
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) };
|
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) };
|
||||||
(
|
(
|
||||||
1,
|
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()])),
|
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 => {
|
sym::raw_eq => {
|
||||||
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) };
|
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)
|
(1, vec![param_ty; 2], tcx.types.bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -556,11 +556,14 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'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 = tcx.mk_re_early_bound(ty::EarlyBoundRegion {
|
let region_param = ty::Region::new_early_bound(
|
||||||
def_id: region_param.def_id,
|
tcx,
|
||||||
index: region_param.index,
|
ty::EarlyBoundRegion {
|
||||||
name: region_param.name,
|
def_id: region_param.def_id,
|
||||||
});
|
index: region_param.index,
|
||||||
|
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(
|
||||||
|
@ -593,18 +596,24 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'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 = tcx.mk_re_early_bound(ty::EarlyBoundRegion {
|
let region_a_param = ty::Region::new_early_bound(
|
||||||
def_id: region_a_param.def_id,
|
tcx,
|
||||||
index: region_a_param.index,
|
ty::EarlyBoundRegion {
|
||||||
name: region_a_param.name,
|
def_id: region_a_param.def_id,
|
||||||
});
|
index: region_a_param.index,
|
||||||
|
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 = tcx.mk_re_early_bound(ty::EarlyBoundRegion {
|
let region_b_param = ty::Region::new_early_bound(
|
||||||
def_id: region_b_param.def_id,
|
tcx,
|
||||||
index: region_b_param.index,
|
ty::EarlyBoundRegion {
|
||||||
name: region_b_param.name,
|
def_id: region_b_param.def_id,
|
||||||
});
|
index: region_b_param.index,
|
||||||
|
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),
|
||||||
|
|
|
@ -440,7 +440,7 @@ 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_re_early_bound(ty::EarlyBoundRegion {
|
ty::Region::new_early_bound(self.tcx, ty::EarlyBoundRegion {
|
||||||
def_id: item_def_id,
|
def_id: item_def_id,
|
||||||
index: 0,
|
index: 0,
|
||||||
name: Symbol::intern(<_name),
|
name: Symbol::intern(<_name),
|
||||||
|
|
|
@ -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 Some(dup_index) = generics.param_def_id_to_index(tcx, dup_def) else { bug!() };
|
||||||
|
|
||||||
let dup_region = tcx.mk_re_early_bound(ty::EarlyBoundRegion {
|
let dup_region = ty::Region::new_early_bound(
|
||||||
def_id: dup_def,
|
tcx,
|
||||||
index: dup_index,
|
ty::EarlyBoundRegion {
|
||||||
name: duplicate.name.ident().name,
|
def_id: dup_def,
|
||||||
});
|
index: dup_index,
|
||||||
|
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),
|
||||||
|
|
|
@ -269,7 +269,7 @@ pub fn resolve_interior<'a, 'tcx>(
|
||||||
},
|
},
|
||||||
_ => mk_bound_region(ty::BrAnon(None)),
|
_ => 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
|
r
|
||||||
});
|
});
|
||||||
captured_tys.insert(ty).then(|| {
|
captured_tys.insert(ty).then(|| {
|
||||||
|
@ -295,7 +295,11 @@ 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_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:?}"),
|
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}"),
|
||||||
|
|
|
@ -771,7 +771,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(None) };
|
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
|
/// Given a type variable `ty_var` of the given kind, first check
|
||||||
|
|
|
@ -141,7 +141,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
CanonicalVarKind::PlaceholderRegion(ty::PlaceholderRegion { universe, bound }) => {
|
CanonicalVarKind::PlaceholderRegion(ty::PlaceholderRegion { universe, bound }) => {
|
||||||
let universe_mapped = universe_map(universe);
|
let universe_mapped = universe_map(universe);
|
||||||
let placeholder_mapped = ty::PlaceholderRegion { universe: universe_mapped, bound };
|
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
|
CanonicalVarKind::Const(ui, ty) => self
|
||||||
|
|
|
@ -668,14 +668,15 @@ 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) => {
|
Constraint::VarSubVar(v1, v2) => ty::OutlivesPredicate(
|
||||||
ty::OutlivesPredicate(tcx.mk_re_var(v2).into(), tcx.mk_re_var(v1))
|
ty::Region::new_var(tcx, v2).into(),
|
||||||
}
|
ty::Region::new_var(tcx, v1),
|
||||||
|
),
|
||||||
Constraint::VarSubReg(v1, r2) => {
|
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) => {
|
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),
|
Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1),
|
||||||
};
|
};
|
||||||
|
@ -719,7 +720,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_re_placeholder(placeholder)
|
ty::Region::new_placeholder(self.infcx.tcx, placeholder)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generalize_existential(&mut self, universe: ty::UniverseIndex) -> ty::Region<'tcx> {
|
fn generalize_existential(&mut self, universe: ty::UniverseIndex) -> ty::Region<'tcx> {
|
||||||
|
|
|
@ -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_re_var(*vid)),
|
Some(ty::Region::new_var(self.tcx(), *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_re_var(*vid)),
|
Some(ty::Region::new_var(self.tcx(), *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_re_var(*vid)),
|
Some(ty::Region::new_var(self.tcx(), *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_re_var(*vid)),
|
Some(ty::Region::new_var(self.tcx(), *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_re_var(*vid)),
|
Some(ty::Region::new_var(self.tcx(), *vid)),
|
||||||
cause,
|
cause,
|
||||||
None,
|
None,
|
||||||
Some(*sup_placeholder),
|
Some(*sup_placeholder),
|
||||||
|
|
|
@ -82,8 +82,10 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
|
|
||||||
let delegate = FnMutDelegate {
|
let delegate = FnMutDelegate {
|
||||||
regions: &mut |br: ty::BoundRegion| {
|
regions: &mut |br: ty::BoundRegion| {
|
||||||
self.tcx
|
ty::Region::new_placeholder(
|
||||||
.mk_re_placeholder(ty::PlaceholderRegion { universe: next_universe, bound: br })
|
self.tcx,
|
||||||
|
ty::PlaceholderRegion { universe: next_universe, bound: br },
|
||||||
|
)
|
||||||
},
|
},
|
||||||
types: &mut |bound_ty: ty::BoundTy| {
|
types: &mut |bound_ty: ty::BoundTy| {
|
||||||
self.tcx.mk_placeholder(ty::PlaceholderType {
|
self.tcx.mk_placeholder(ty::PlaceholderType {
|
||||||
|
|
|
@ -347,7 +347,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_re_placeholder(placeholder)
|
ty::Region::new_placeholder(self.tcx(), placeholder)
|
||||||
}
|
}
|
||||||
Err(_) => self.tcx().lifetimes.re_static,
|
Err(_) => self.tcx().lifetimes.re_static,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1065,7 +1065,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_re_var(region_var)
|
ty::Region::new_var(self.tcx, region_var)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the universe that the region `r` was created in. For
|
/// Return the universe that the region `r` was created in. For
|
||||||
|
|
|
@ -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_re_placeholder(placeholder2))
|
self.error(placeholder1, ty::Region::new_placeholder(self.tcx, placeholder2))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn error(
|
fn error(
|
||||||
|
@ -413,13 +413,13 @@ 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_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)) => {
|
&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)) => {
|
&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)) => {
|
&AddConstraint(Constraint::RegSubReg(a, b)) => {
|
||||||
each_edge(a, b);
|
each_edge(a, b);
|
||||||
|
|
|
@ -610,13 +610,13 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
||||||
let resolved = ut
|
let resolved = ut
|
||||||
.probe_value(root_vid)
|
.probe_value(root_vid)
|
||||||
.get_value_ignoring_universes()
|
.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.
|
// Don't resolve a variable to a region that it cannot name.
|
||||||
if self.var_universe(vid).can_name(self.universe(resolved)) {
|
if self.var_universe(vid).can_name(self.universe(resolved)) {
|
||||||
resolved
|
resolved
|
||||||
} else {
|
} else {
|
||||||
tcx.mk_re_var(vid)
|
ty::Region::new_var(tcx, vid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,7 +637,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_re_var(c);
|
return ty::Region::new_var(tcx, 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);
|
||||||
|
@ -645,7 +645,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_re_var(c);
|
let new_r = ty::Region::new_var(tcx, 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),
|
||||||
|
|
|
@ -415,7 +415,7 @@ impl<'tcx> CanonicalVarValues<'tcx> {
|
||||||
var: ty::BoundVar::from_usize(i),
|
var: ty::BoundVar::from_usize(i),
|
||||||
kind: ty::BrAnon(None),
|
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::Const(_, ty)
|
||||||
| CanonicalVarKind::PlaceholderConst(_, ty) => tcx
|
| CanonicalVarKind::PlaceholderConst(_, ty) => tcx
|
||||||
|
|
|
@ -413,7 +413,7 @@ impl<'tcx> ClosureOutlivesSubjectTy<'tcx> {
|
||||||
ty::ReVar(vid) => {
|
ty::ReVar(vid) => {
|
||||||
let br =
|
let br =
|
||||||
ty::BoundRegion { var: ty::BoundVar::new(vid.index()), kind: ty::BrAnon(None) };
|
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:?}"),
|
_ => bug!("unexpected region in ClosureOutlivesSubjectTy: {r:?}"),
|
||||||
});
|
});
|
||||||
|
|
|
@ -264,7 +264,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for mir::Place<'tcx> {
|
||||||
|
|
||||||
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Region<'tcx> {
|
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Region<'tcx> {
|
||||||
fn decode(decoder: &mut D) -> Self {
|
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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -713,34 +713,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
self.mk_ty_from_kind(Error(reported))
|
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`
|
/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn const_error(self, ty: Ty<'tcx>, reported: ErrorGuaranteed) -> Const<'tcx> {
|
pub fn const_error(self, ty: Ty<'tcx>, reported: ErrorGuaranteed) -> Const<'tcx> {
|
||||||
|
@ -1519,9 +1491,9 @@ macro_rules! direct_interners {
|
||||||
|
|
||||||
// Functions with a `mk_` prefix are intended for use outside this file and
|
// 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
|
// 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! {
|
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_: intern_const(ConstData<'tcx>): Const -> Const<'tcx>,
|
||||||
const_allocation: pub mk_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>,
|
const_allocation: pub mk_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>,
|
||||||
layout: pub mk_layout(LayoutS): Layout -> Layout<'tcx>,
|
layout: pub mk_layout(LayoutS): Layout -> Layout<'tcx>,
|
||||||
|
@ -1996,7 +1968,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_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::Type { .. } => self.mk_ty_param(param.index, param.name).into(),
|
||||||
GenericParamDefKind::Const { .. } => self
|
GenericParamDefKind::Const { .. } => self
|
||||||
|
@ -2036,65 +2008,6 @@ 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> {
|
|
||||||
// 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> {
|
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))
|
self.mk_place_elem(place, PlaceElem::Field(f, ty))
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,7 +213,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_re_late_bound(debruijn, br)
|
ty::Region::new_late_bound(self.tcx, debruijn, br)
|
||||||
} else {
|
} else {
|
||||||
region
|
region
|
||||||
}
|
}
|
||||||
|
@ -328,7 +328,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
T: TypeFoldable<TyCtxt<'tcx>>,
|
T: TypeFoldable<TyCtxt<'tcx>>,
|
||||||
{
|
{
|
||||||
self.replace_late_bound_regions_uncached(value, |br| {
|
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 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
value,
|
value,
|
||||||
FnMutDelegate {
|
FnMutDelegate {
|
||||||
regions: &mut |r: ty::BoundRegion| {
|
regions: &mut |r: ty::BoundRegion| {
|
||||||
self.mk_re_late_bound(
|
ty::Region::new_late_bound(
|
||||||
|
self,
|
||||||
ty::INNERMOST,
|
ty::INNERMOST,
|
||||||
ty::BoundRegion { var: shift_bv(r.var), kind: r.kind },
|
ty::BoundRegion { var: shift_bv(r.var), kind: r.kind },
|
||||||
)
|
)
|
||||||
|
@ -383,7 +384,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
.or_insert_with(|| ty::BoundVariableKind::Region(ty::BrAnon(None)))
|
.or_insert_with(|| ty::BoundVariableKind::Region(ty::BrAnon(None)))
|
||||||
.expect_region();
|
.expect_region();
|
||||||
let br = ty::BoundRegion { var, kind };
|
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> {
|
fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> {
|
||||||
let entry = self.map.entry(bt.var);
|
let entry = self.map.entry(bt.var);
|
||||||
|
@ -451,7 +452,7 @@ impl<'tcx> 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);
|
||||||
self.tcx.mk_re_late_bound(debruijn, br)
|
ty::Region::new_late_bound(self.tcx, debruijn, br)
|
||||||
}
|
}
|
||||||
_ => r,
|
_ => r,
|
||||||
}
|
}
|
||||||
|
@ -492,7 +493,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_re_late_bound(debruijn.shifted_in(amount), br)
|
ty::Region::new_late_bound(tcx, debruijn.shifted_in(amount), br)
|
||||||
}
|
}
|
||||||
_ => region,
|
_ => region,
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.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::Type { .. } => tcx.ty_error_misc().into(),
|
||||||
ty::GenericParamDefKind::Const { .. } => {
|
ty::GenericParamDefKind::Const { .. } => {
|
||||||
tcx.const_error_misc(tcx.type_of(self.def_id).subst(tcx, preceding_substs)).into()
|
tcx.const_error_misc(tcx.type_of(self.def_id).subst(tcx, preceding_substs)).into()
|
||||||
|
|
|
@ -141,7 +141,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
|
|
||||||
self.interner().mk_re_error(e)
|
ty::Region::new_error(self.interner(), e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,7 +184,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_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.
|
/// Returns `Some(n)` with the number to use for the given region, if any.
|
||||||
|
@ -2303,7 +2303,7 @@ impl<'a, 'tcx> ty::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_re_late_bound(self.current_index, br)
|
ty::Region::new_late_bound(self.tcx, self.current_index, br)
|
||||||
} else {
|
} else {
|
||||||
region
|
region
|
||||||
}
|
}
|
||||||
|
@ -2415,7 +2415,8 @@ 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_re_late_bound(
|
return ty::Region::new_late_bound(
|
||||||
|
tcx,
|
||||||
ty::INNERMOST,
|
ty::INNERMOST,
|
||||||
ty::BoundRegion { var: br.var, kind },
|
ty::BoundRegion { var: br.var, kind },
|
||||||
);
|
);
|
||||||
|
@ -2430,7 +2431,8 @@ 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_re_late_bound(
|
return ty::Region::new_late_bound(
|
||||||
|
tcx,
|
||||||
ty::INNERMOST,
|
ty::INNERMOST,
|
||||||
ty::BoundRegion { var: br.var, kind },
|
ty::BoundRegion { var: br.var, kind },
|
||||||
);
|
);
|
||||||
|
@ -2443,7 +2445,8 @@ 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_re_late_bound(
|
return ty::Region::new_late_bound(
|
||||||
|
tcx,
|
||||||
ty::INNERMOST,
|
ty::INNERMOST,
|
||||||
ty::BoundRegion { var: br.var, kind },
|
ty::BoundRegion { var: br.var, kind },
|
||||||
);
|
);
|
||||||
|
@ -2458,7 +2461,11 @@ 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_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 {
|
let mut folder = RegionFolder {
|
||||||
tcx,
|
tcx,
|
||||||
|
|
|
@ -15,14 +15,14 @@ use hir::def::DefKind;
|
||||||
use polonius_engine::Atom;
|
use polonius_engine::Atom;
|
||||||
use rustc_data_structures::captures::Captures;
|
use rustc_data_structures::captures::Captures;
|
||||||
use rustc_data_structures::intern::Interned;
|
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 as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::LangItem;
|
use rustc_hir::LangItem;
|
||||||
use rustc_index::Idx;
|
use rustc_index::Idx;
|
||||||
use rustc_macros::HashStable;
|
use rustc_macros::HashStable;
|
||||||
use rustc_span::symbol::{kw, sym, Symbol};
|
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::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
|
||||||
use rustc_target::spec::abi::{self, Abi};
|
use rustc_target::spec::abi::{self, Abi};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
@ -1459,6 +1459,103 @@ impl ParamConst {
|
||||||
#[rustc_pass_by_value]
|
#[rustc_pass_by_value]
|
||||||
pub struct Region<'tcx>(pub Interned<'tcx, RegionKind<'tcx>>);
|
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> {
|
impl<'tcx> Deref for Region<'tcx> {
|
||||||
type Target = RegionKind<'tcx>;
|
type Target = RegionKind<'tcx>;
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,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 = 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 =
|
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(
|
||||||
|
|
|
@ -96,7 +96,7 @@ pub(in crate::solve) fn replace_erased_lifetimes_with_bound_vars<'tcx>(
|
||||||
let br =
|
let br =
|
||||||
ty::BoundRegion { var: ty::BoundVar::from_u32(counter), kind: ty::BrAnon(None) };
|
ty::BoundRegion { var: ty::BoundVar::from_u32(counter), kind: ty::BrAnon(None) };
|
||||||
counter += 1;
|
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.
|
// All free regions should be erased here.
|
||||||
r => bug!("unexpected region: {r:?}"),
|
r => bug!("unexpected region: {r:?}"),
|
||||||
|
|
|
@ -255,7 +255,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
let br = ty::BoundRegion { var, kind: BrAnon(None) };
|
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> {
|
fn fold_ty(&mut self, mut t: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
|
|
|
@ -824,7 +824,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, bound: br };
|
let p = ty::PlaceholderRegion { universe, bound: br };
|
||||||
self.mapped_regions.insert(p, br);
|
self.mapped_regions.insert(p, br);
|
||||||
self.infcx.tcx.mk_re_placeholder(p)
|
ty::Region::new_placeholder(self.infcx.tcx, p)
|
||||||
}
|
}
|
||||||
_ => r,
|
_ => r,
|
||||||
}
|
}
|
||||||
|
@ -945,7 +945,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_re_late_bound(db, *replace_var)
|
ty::Region::new_late_bound(self.interner(), db, *replace_var)
|
||||||
}
|
}
|
||||||
None => r1,
|
None => r1,
|
||||||
}
|
}
|
||||||
|
|
|
@ -550,7 +550,8 @@ 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_re_late_bound(
|
ty::Region::new_late_bound(
|
||||||
|
tcx,
|
||||||
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),
|
||||||
|
|
|
@ -3027,7 +3027,7 @@ fn bind_generator_hidden_types_above<'tcx>(
|
||||||
kind: ty::BrAnon(None),
|
kind: ty::BrAnon(None),
|
||||||
};
|
};
|
||||||
counter += 1;
|
counter += 1;
|
||||||
tcx.mk_re_late_bound(current_depth, br)
|
ty::Region::new_late_bound(tcx, current_depth, br)
|
||||||
}
|
}
|
||||||
r => bug!("unexpected region: {r:?}"),
|
r => bug!("unexpected region: {r:?}"),
|
||||||
})
|
})
|
||||||
|
|
|
@ -727,7 +727,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(None),
|
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
|
ty::GenericParamDefKind::Const { .. } => tcx
|
||||||
|
|
|
@ -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> {
|
fn lower_into(self, interner: RustInterner<'tcx>) -> Region<'tcx> {
|
||||||
let tcx = interner.tcx;
|
let tcx = interner.tcx;
|
||||||
match self.data(interner) {
|
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::DebruijnIndex::from_u32(var.debruijn.depth()),
|
||||||
ty::BoundRegion {
|
ty::BoundRegion {
|
||||||
var: ty::BoundVar::from_usize(var.index),
|
var: ty::BoundVar::from_usize(var.index),
|
||||||
|
@ -550,13 +551,16 @@ 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) => tcx.mk_re_placeholder(ty::Placeholder {
|
chalk_ir::LifetimeData::Placeholder(p) => ty::Region::new_placeholder(
|
||||||
universe: ty::UniverseIndex::from_usize(p.ui.counter),
|
tcx,
|
||||||
bound: ty::BoundRegion {
|
ty::Placeholder {
|
||||||
var: ty::BoundVar::from_usize(p.idx),
|
universe: ty::UniverseIndex::from_usize(p.ui.counter),
|
||||||
kind: ty::BoundRegionKind::BrAnon(None),
|
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::Static => tcx.lifetimes.re_static,
|
||||||
chalk_ir::LifetimeData::Erased => 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 {},
|
||||||
|
@ -1051,7 +1055,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(_) => {
|
Some(_) => {
|
||||||
let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(None) };
|
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`."),
|
None => panic!("Missing `BrNamed`."),
|
||||||
},
|
},
|
||||||
|
@ -1142,7 +1146,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ParamsSubstitutor<'tcx> {
|
||||||
var: ty::BoundVar::from_u32(*idx),
|
var: ty::BoundVar::from_u32(*idx),
|
||||||
kind: ty::BrAnon(None),
|
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 => {
|
None => {
|
||||||
let idx = self.named_regions.len() as u32;
|
let idx = self.named_regions.len() as u32;
|
||||||
|
@ -1151,7 +1155,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ParamsSubstitutor<'tcx> {
|
||||||
kind: ty::BrAnon(None),
|
kind: ty::BrAnon(None),
|
||||||
};
|
};
|
||||||
self.named_regions.insert(_re.def_id, idx);
|
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)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,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 = 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 env_ty = tcx.closure_env_ty(def_id, substs, env_region).unwrap();
|
||||||
|
|
||||||
let sig = sig.skip_binder();
|
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),
|
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
|
||||||
kind: ty::BoundRegionKind::BrEnv,
|
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_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);
|
||||||
|
|
|
@ -287,12 +287,13 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
|
||||||
let shifted_alias_ty = self.tcx.fold_regions(unshifted_alias_ty, |re, depth| {
|
let shifted_alias_ty = self.tcx.fold_regions(unshifted_alias_ty, |re, depth| {
|
||||||
if let ty::ReLateBound(index, bv) = re.kind() {
|
if let ty::ReLateBound(index, bv) = re.kind() {
|
||||||
if depth != ty::INNERMOST {
|
if depth != ty::INNERMOST {
|
||||||
return self.tcx.mk_re_error_with_message(
|
return ty::Region::new_error_with_message(
|
||||||
|
self.tcx,
|
||||||
DUMMY_SP,
|
DUMMY_SP,
|
||||||
"we shouldn't walk non-predicate binders with `impl Trait`...",
|
"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 {
|
} else {
|
||||||
re
|
re
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue