mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 14:01:51 +00:00
Auto merge of #108020 - nnethercote:opt-mk_region, r=compiler-errors
Optimize `mk_region` PR #107869 avoiding some interning under `mk_ty` by special-casing `Ty` variants with simple (integer) bodies. This PR does something similar for regions. r? `@compiler-errors`
This commit is contained in:
commit
c5d1b3ea96
@ -180,20 +180,20 @@ trait TypeOpInfo<'tcx> {
|
||||
return;
|
||||
};
|
||||
|
||||
let placeholder_region = tcx.mk_region(ty::RePlaceholder(ty::Placeholder {
|
||||
let placeholder_region = tcx.mk_re_placeholder(ty::Placeholder {
|
||||
name: placeholder.name,
|
||||
universe: adjusted_universe.into(),
|
||||
}));
|
||||
});
|
||||
|
||||
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_region(ty::RePlaceholder(ty::Placeholder {
|
||||
tcx.mk_re_placeholder(ty::Placeholder {
|
||||
name: error_placeholder.name,
|
||||
universe: adjusted.into(),
|
||||
}))
|
||||
})
|
||||
})
|
||||
} else {
|
||||
None
|
||||
@ -390,7 +390,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
|
||||
error_region,
|
||||
®ion_constraints,
|
||||
|vid| ocx.infcx.region_var_origin(vid),
|
||||
|vid| ocx.infcx.universe_of_region(ocx.infcx.tcx.mk_region(ty::ReVar(vid))),
|
||||
|vid| ocx.infcx.universe_of_region(ocx.infcx.tcx.mk_re_var(vid)),
|
||||
)
|
||||
}
|
||||
|
||||
@ -411,7 +411,7 @@ fn try_extract_error_from_region_constraints<'tcx>(
|
||||
}
|
||||
// FIXME: Should this check the universe of the var?
|
||||
Constraint::VarSubReg(vid, sup) if sup == placeholder_region => {
|
||||
Some((infcx.tcx.mk_region(ty::ReVar(vid)), cause.clone()))
|
||||
Some((infcx.tcx.mk_re_var(vid), cause.clone()))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
|
@ -1297,7 +1297,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
let vid = self.to_region_vid(r);
|
||||
let scc = self.constraint_sccs.scc(vid);
|
||||
let repr = self.scc_representatives[scc];
|
||||
tcx.mk_region(ty::ReVar(repr))
|
||||
tcx.mk_re_var(repr)
|
||||
})
|
||||
}
|
||||
|
||||
@ -1719,7 +1719,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
}
|
||||
|
||||
// If not, report an error.
|
||||
let member_region = infcx.tcx.mk_region(ty::ReVar(member_region_vid));
|
||||
let member_region = infcx.tcx.mk_re_var(member_region_vid);
|
||||
errors_buffer.push(RegionErrorKind::UnexpectedHiddenRegion {
|
||||
span: m_c.definition_span,
|
||||
hidden_ty: m_c.hidden_ty,
|
||||
|
@ -91,7 +91,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
}
|
||||
None => {
|
||||
subst_regions.push(vid);
|
||||
infcx.tcx.re_error_with_message(
|
||||
infcx.tcx.mk_re_error_with_message(
|
||||
concrete_type.span,
|
||||
"opaque type with non-universal region substs",
|
||||
)
|
||||
|
@ -137,7 +137,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
|
||||
upvars: &[Upvar<'tcx>],
|
||||
use_polonius: bool,
|
||||
) -> MirTypeckResults<'tcx> {
|
||||
let implicit_region_bound = infcx.tcx.mk_region(ty::ReVar(universal_regions.fr_fn_body));
|
||||
let implicit_region_bound = infcx.tcx.mk_re_var(universal_regions.fr_fn_body);
|
||||
let mut constraints = MirTypeckRegionConstraints {
|
||||
placeholder_indices: PlaceholderIndices::default(),
|
||||
placeholder_index_to_region: IndexVec::default(),
|
||||
|
@ -480,10 +480,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
LangItem::VaList,
|
||||
Some(self.infcx.tcx.def_span(self.mir_def.did)),
|
||||
);
|
||||
let region = self
|
||||
.infcx
|
||||
.tcx
|
||||
.mk_region(ty::ReVar(self.infcx.next_nll_region_var(FR).to_region_vid()));
|
||||
let region =
|
||||
self.infcx.tcx.mk_re_var(self.infcx.next_nll_region_var(FR).to_region_vid());
|
||||
let va_list_ty = self
|
||||
.infcx
|
||||
.tcx
|
||||
@ -636,7 +634,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
|
||||
kind: ty::BrEnv,
|
||||
};
|
||||
let env_region = ty::ReLateBound(ty::INNERMOST, br);
|
||||
let env_region = tcx.mk_re_late_bound(ty::INNERMOST, br);
|
||||
let closure_ty = tcx.closure_env_ty(def_id, substs, env_region).unwrap();
|
||||
|
||||
// The "inputs" of the closure in the
|
||||
@ -748,10 +746,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
||||
{
|
||||
let (value, _map) = self.tcx.replace_late_bound_regions(value, |br| {
|
||||
debug!(?br);
|
||||
let liberated_region = self.tcx.mk_region(ty::ReFree(ty::FreeRegion {
|
||||
scope: all_outlive_scope.to_def_id(),
|
||||
bound_region: br.kind,
|
||||
}));
|
||||
let liberated_region = self.tcx.mk_re_free(all_outlive_scope.to_def_id(), br.kind);
|
||||
let region_vid = self.next_nll_region_var(origin);
|
||||
indices.insert_late_bound_region(liberated_region, region_vid.to_region_vid());
|
||||
debug!(?liberated_region, ?region_vid);
|
||||
@ -843,7 +838,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
tcx.fold_regions(value, |region, _| tcx.mk_region(ty::ReVar(self.to_region_vid(region))))
|
||||
tcx.fold_regions(value, |region, _| tcx.mk_re_var(self.to_region_vid(region)))
|
||||
}
|
||||
}
|
||||
|
||||
@ -883,8 +878,7 @@ fn for_each_late_bound_region_in_item<'tcx>(
|
||||
|
||||
for bound_var in tcx.late_bound_vars(tcx.hir().local_def_id_to_hir_id(mir_def_id)) {
|
||||
let ty::BoundVariableKind::Region(bound_region) = bound_var else { continue; };
|
||||
let liberated_region = tcx
|
||||
.mk_region(ty::ReFree(ty::FreeRegion { scope: mir_def_id.to_def_id(), bound_region }));
|
||||
let liberated_region = tcx.mk_re_free(mir_def_id.to_def_id(), bound_region);
|
||||
f(liberated_region);
|
||||
}
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
var: ty::BoundVar::from_u32(index),
|
||||
kind: ty::BrNamed(def_id, name),
|
||||
};
|
||||
tcx.mk_region(ty::ReLateBound(debruijn, br))
|
||||
tcx.mk_re_late_bound(debruijn, br)
|
||||
}
|
||||
|
||||
Some(rl::Region::EarlyBound(def_id)) => {
|
||||
@ -242,15 +242,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
let item_def_id = tcx.hir().ty_param_owner(def_id.expect_local());
|
||||
let generics = tcx.generics_of(item_def_id);
|
||||
let index = generics.param_def_id_to_index[&def_id];
|
||||
tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name }))
|
||||
tcx.mk_re_early_bound(ty::EarlyBoundRegion { def_id, index, name })
|
||||
}
|
||||
|
||||
Some(rl::Region::Free(scope, id)) => {
|
||||
let name = lifetime_name(id.expect_local());
|
||||
tcx.mk_region(ty::ReFree(ty::FreeRegion {
|
||||
scope,
|
||||
bound_region: ty::BrNamed(id, name),
|
||||
}))
|
||||
tcx.mk_re_free(scope, ty::BrNamed(id, name))
|
||||
|
||||
// (*) -- not late-bound, won't change
|
||||
}
|
||||
@ -263,7 +260,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
// elision. `resolve_lifetime` should have
|
||||
// reported an error in this case -- but if
|
||||
// not, let's error out.
|
||||
tcx.re_error_with_message(lifetime.ident.span, "unelided lifetime in signature")
|
||||
tcx.mk_re_error_with_message(
|
||||
lifetime.ident.span,
|
||||
"unelided lifetime in signature",
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -477,7 +477,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
debug!(?param, "unelided lifetime in signature");
|
||||
|
||||
// This indicates an illegal lifetime in a non-assoc-trait position
|
||||
tcx.re_error_with_message(self.span, "unelided lifetime in signature")
|
||||
tcx.mk_re_error_with_message(
|
||||
self.span,
|
||||
"unelided lifetime in signature",
|
||||
)
|
||||
})
|
||||
.into(),
|
||||
GenericParamDefKind::Type { has_default, .. } => {
|
||||
@ -1622,7 +1625,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
} else {
|
||||
err.emit()
|
||||
};
|
||||
tcx.re_error(e)
|
||||
tcx.mk_re_error(e)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
@ -464,14 +464,10 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateBound<'_, 'tcx> {
|
||||
|
||||
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
||||
if let ty::ReFree(fr) = *r {
|
||||
self.tcx.mk_region(ty::ReFree(ty::FreeRegion {
|
||||
bound_region: self
|
||||
.mapping
|
||||
.get(&fr.bound_region)
|
||||
.copied()
|
||||
.unwrap_or(fr.bound_region),
|
||||
..fr
|
||||
}))
|
||||
self.tcx.mk_re_free(
|
||||
fr.scope,
|
||||
self.mapping.get(&fr.bound_region).copied().unwrap_or(fr.bound_region),
|
||||
)
|
||||
} else {
|
||||
r
|
||||
}
|
||||
@ -777,13 +773,13 @@ 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())
|
||||
else {
|
||||
return tcx.re_error_with_message(return_span, "expected ReFree to map to ReEarlyBound")
|
||||
return tcx.mk_re_error_with_message(return_span, "expected ReFree to map to ReEarlyBound")
|
||||
};
|
||||
tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
|
||||
tcx.mk_re_early_bound(ty::EarlyBoundRegion {
|
||||
def_id: e.def_id,
|
||||
name: e.name,
|
||||
index: (e.index as usize - num_trait_substs + num_impl_substs) as u32,
|
||||
}))
|
||||
})
|
||||
});
|
||||
debug!(%ty);
|
||||
collected_tys.insert(def_id, ty);
|
||||
@ -1920,10 +1916,10 @@ 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_region(ty::ReLateBound(
|
||||
tcx.mk_re_late_bound(
|
||||
ty::INNERMOST,
|
||||
ty::BoundRegion { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind },
|
||||
))
|
||||
)
|
||||
.into()
|
||||
}
|
||||
GenericParamDefKind::Const { .. } => {
|
||||
|
@ -149,14 +149,14 @@ 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_region(ty::ReLateBound(
|
||||
let region = tcx.mk_re_late_bound(
|
||||
ty::INNERMOST,
|
||||
ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0, None) },
|
||||
));
|
||||
let env_region = tcx.mk_region(ty::ReLateBound(
|
||||
);
|
||||
let env_region = tcx.mk_re_late_bound(
|
||||
ty::INNERMOST,
|
||||
ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrEnv },
|
||||
));
|
||||
);
|
||||
let va_list_ty = tcx.bound_type_of(did).subst(tcx, &[region.into()]);
|
||||
(tcx.mk_ref(env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty)
|
||||
})
|
||||
@ -377,9 +377,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
||||
ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0, None) };
|
||||
(
|
||||
1,
|
||||
vec![
|
||||
tcx.mk_imm_ref(tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)), param(0)),
|
||||
],
|
||||
vec![tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0))],
|
||||
tcx.mk_projection(discriminant_def_id, tcx.mk_substs([param(0).into()].iter())),
|
||||
)
|
||||
}
|
||||
@ -430,8 +428,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
||||
sym::raw_eq => {
|
||||
let br =
|
||||
ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0, None) };
|
||||
let param_ty =
|
||||
tcx.mk_imm_ref(tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)), param(0));
|
||||
let param_ty = tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0));
|
||||
(1, vec![param_ty; 2], tcx.types.bool)
|
||||
}
|
||||
|
||||
|
@ -607,12 +607,11 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'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_region(ty::RegionKind::ReEarlyBound(ty::EarlyBoundRegion {
|
||||
def_id: region_param.def_id,
|
||||
index: region_param.index,
|
||||
name: region_param.name,
|
||||
}));
|
||||
let region_param = tcx.mk_re_early_bound(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(
|
||||
@ -645,20 +644,18 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'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_region(ty::RegionKind::ReEarlyBound(ty::EarlyBoundRegion {
|
||||
def_id: region_a_param.def_id,
|
||||
index: region_a_param.index,
|
||||
name: region_a_param.name,
|
||||
}));
|
||||
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,
|
||||
});
|
||||
// Same for the region.
|
||||
let region_b_param = gat_generics.param_at(*region_b_idx, tcx);
|
||||
let region_b_param =
|
||||
tcx.mk_region(ty::RegionKind::ReEarlyBound(ty::EarlyBoundRegion {
|
||||
def_id: region_b_param.def_id,
|
||||
index: region_b_param.index,
|
||||
name: region_b_param.name,
|
||||
}));
|
||||
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,
|
||||
});
|
||||
// The predicate we expect to see.
|
||||
let clause = ty::PredicateKind::Clause(ty::Clause::RegionOutlives(
|
||||
ty::OutlivesPredicate(region_a_param, region_b_param),
|
||||
|
@ -458,13 +458,11 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
|
||||
self.tcx.replace_late_bound_regions_uncached(
|
||||
poly_trait_ref,
|
||||
|_| {
|
||||
self.tcx.mk_region(ty::ReEarlyBound(
|
||||
ty::EarlyBoundRegion {
|
||||
def_id: item_def_id,
|
||||
index: 0,
|
||||
name: Symbol::intern(<_name),
|
||||
},
|
||||
))
|
||||
self.tcx.mk_re_early_bound(ty::EarlyBoundRegion {
|
||||
def_id: item_def_id,
|
||||
index: 0,
|
||||
name: Symbol::intern(<_name),
|
||||
})
|
||||
}
|
||||
),
|
||||
),
|
||||
|
@ -284,11 +284,11 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
||||
|
||||
let Some(dup_index) = generics.param_def_id_to_index(tcx, dup_def) else { bug!() };
|
||||
|
||||
let dup_region = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
|
||||
let dup_region = tcx.mk_re_early_bound(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),
|
||||
|
@ -1269,10 +1269,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// ```
|
||||
let ref_ty = match mutability {
|
||||
hir::Mutability::Mut => {
|
||||
self.tcx.mk_mut_ref(self.tcx.mk_region(ty::ReStatic), checked_ty)
|
||||
self.tcx.mk_mut_ref(self.tcx.lifetimes.re_static, checked_ty)
|
||||
}
|
||||
hir::Mutability::Not => {
|
||||
self.tcx.mk_imm_ref(self.tcx.mk_region(ty::ReStatic), checked_ty)
|
||||
self.tcx.mk_imm_ref(self.tcx.lifetimes.re_static, checked_ty)
|
||||
}
|
||||
};
|
||||
if self.can_coerce(ref_ty, expected) {
|
||||
|
@ -271,7 +271,7 @@ pub fn resolve_interior<'a, 'tcx>(
|
||||
},
|
||||
_ => mk_bound_region(None),
|
||||
};
|
||||
let r = fcx.tcx.mk_region(ty::ReLateBound(current_depth, br));
|
||||
let r = fcx.tcx.mk_re_late_bound(current_depth, br);
|
||||
r
|
||||
});
|
||||
if captured_tys.insert(ty) {
|
||||
@ -302,7 +302,7 @@ 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_region(ty::ReLateBound(ty::INNERMOST, ty::BoundRegion { var, kind }))
|
||||
fcx.tcx.mk_re_late_bound(ty::INNERMOST, ty::BoundRegion { var, kind })
|
||||
},
|
||||
types: &mut |b| bug!("unexpected bound ty in binder: {b:?}"),
|
||||
consts: &mut |b, ty| bug!("unexpected bound ct in binder: {b:?} {ty}"),
|
||||
@ -364,7 +364,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
|
||||
let ty = tcx.mk_ref(
|
||||
// Use `ReErased` as `resolve_interior` is going to replace all the
|
||||
// regions anyway.
|
||||
tcx.mk_region(ty::ReErased),
|
||||
tcx.lifetimes.re_erased,
|
||||
ty::TypeAndMut { ty, mutbl: hir::Mutability::Not },
|
||||
);
|
||||
self.interior_visitor.record(
|
||||
|
@ -363,7 +363,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
|
||||
opportunistically resolved to {:?}",
|
||||
vid, resolved_vid
|
||||
);
|
||||
let r = self.tcx.reuse_or_mk_region(r, ty::ReVar(resolved_vid));
|
||||
let r = self.tcx.mk_re_var(resolved_vid);
|
||||
self.canonicalize_mode.canonicalize_free_region(self, r)
|
||||
}
|
||||
|
||||
@ -737,8 +737,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
|
||||
) -> ty::Region<'tcx> {
|
||||
let var = self.canonical_var(info, r.into());
|
||||
let br = ty::BoundRegion { var, kind: ty::BrAnon(var.as_u32(), None) };
|
||||
let region = ty::ReLateBound(self.binder_index, br);
|
||||
self.interner().mk_region(region)
|
||||
self.interner().mk_re_late_bound(self.binder_index, br)
|
||||
}
|
||||
|
||||
/// Given a type variable `ty_var` of the given kind, first check
|
||||
|
@ -137,7 +137,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
CanonicalVarKind::PlaceholderRegion(ty::PlaceholderRegion { universe, name }) => {
|
||||
let universe_mapped = universe_map(universe);
|
||||
let placeholder_mapped = ty::PlaceholderRegion { universe: universe_mapped, name };
|
||||
self.tcx.mk_region(ty::RePlaceholder(placeholder_mapped)).into()
|
||||
self.tcx.mk_re_placeholder(placeholder_mapped).into()
|
||||
}
|
||||
|
||||
CanonicalVarKind::Const(ui, ty) => self
|
||||
|
@ -642,15 +642,14 @@ 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_region(ty::ReVar(v2)).into(),
|
||||
tcx.mk_region(ty::ReVar(v1)),
|
||||
),
|
||||
Constraint::VarSubVar(v1, v2) => {
|
||||
ty::OutlivesPredicate(tcx.mk_re_var(v2).into(), tcx.mk_re_var(v1))
|
||||
}
|
||||
Constraint::VarSubReg(v1, r2) => {
|
||||
ty::OutlivesPredicate(r2.into(), tcx.mk_region(ty::ReVar(v1)))
|
||||
ty::OutlivesPredicate(r2.into(), tcx.mk_re_var(v1))
|
||||
}
|
||||
Constraint::RegSubVar(r1, v2) => {
|
||||
ty::OutlivesPredicate(tcx.mk_region(ty::ReVar(v2)).into(), r1)
|
||||
ty::OutlivesPredicate(tcx.mk_re_var(v2).into(), r1)
|
||||
}
|
||||
Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1),
|
||||
};
|
||||
@ -690,7 +689,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
|
||||
}
|
||||
|
||||
fn next_placeholder_region(&mut self, placeholder: ty::PlaceholderRegion) -> ty::Region<'tcx> {
|
||||
self.infcx.tcx.mk_region(ty::RePlaceholder(placeholder))
|
||||
self.infcx.tcx.mk_re_placeholder(placeholder)
|
||||
}
|
||||
|
||||
fn generalize_existential(&mut self, universe: ty::UniverseIndex) -> ty::Region<'tcx> {
|
||||
|
@ -14,7 +14,7 @@ use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::ty::error::ExpectedFound;
|
||||
use rustc_middle::ty::print::{FmtPrinter, Print, RegionHighlightMode};
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::{self, RePlaceholder, ReVar, Region, TyCtxt};
|
||||
use rustc_middle::ty::{self, RePlaceholder, Region, TyCtxt};
|
||||
|
||||
use std::fmt;
|
||||
|
||||
@ -79,7 +79,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||
sup_placeholder @ Region(Interned(RePlaceholder(_), _)),
|
||||
_,
|
||||
)) => self.try_report_trait_placeholder_mismatch(
|
||||
Some(self.tcx().mk_region(ReVar(*vid))),
|
||||
Some(self.tcx().mk_re_var(*vid)),
|
||||
cause,
|
||||
Some(*sub_placeholder),
|
||||
Some(*sup_placeholder),
|
||||
@ -95,7 +95,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||
_,
|
||||
_,
|
||||
)) => self.try_report_trait_placeholder_mismatch(
|
||||
Some(self.tcx().mk_region(ReVar(*vid))),
|
||||
Some(self.tcx().mk_re_var(*vid)),
|
||||
cause,
|
||||
Some(*sub_placeholder),
|
||||
None,
|
||||
@ -111,7 +111,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||
sup_placeholder @ Region(Interned(RePlaceholder(_), _)),
|
||||
_,
|
||||
)) => self.try_report_trait_placeholder_mismatch(
|
||||
Some(self.tcx().mk_region(ReVar(*vid))),
|
||||
Some(self.tcx().mk_re_var(*vid)),
|
||||
cause,
|
||||
None,
|
||||
Some(*sup_placeholder),
|
||||
@ -127,7 +127,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||
sup_placeholder @ Region(Interned(RePlaceholder(_), _)),
|
||||
_,
|
||||
)) => self.try_report_trait_placeholder_mismatch(
|
||||
Some(self.tcx().mk_region(ReVar(*vid))),
|
||||
Some(self.tcx().mk_re_var(*vid)),
|
||||
cause,
|
||||
None,
|
||||
Some(*sup_placeholder),
|
||||
@ -141,7 +141,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
|
||||
SubregionOrigin::Subtype(box TypeTrace { cause, values }),
|
||||
sup_placeholder @ Region(Interned(RePlaceholder(_), _)),
|
||||
)) => self.try_report_trait_placeholder_mismatch(
|
||||
Some(self.tcx().mk_region(ReVar(*vid))),
|
||||
Some(self.tcx().mk_re_var(*vid)),
|
||||
cause,
|
||||
None,
|
||||
Some(*sup_placeholder),
|
||||
|
@ -82,10 +82,10 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
|
||||
let delegate = FnMutDelegate {
|
||||
regions: &mut |br: ty::BoundRegion| {
|
||||
self.tcx.mk_region(ty::RePlaceholder(ty::PlaceholderRegion {
|
||||
self.tcx.mk_re_placeholder(ty::PlaceholderRegion {
|
||||
universe: next_universe,
|
||||
name: br.kind,
|
||||
}))
|
||||
})
|
||||
},
|
||||
types: &mut |bound_ty: ty::BoundTy| {
|
||||
self.tcx.mk_placeholder(ty::PlaceholderType {
|
||||
|
@ -382,7 +382,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
|
||||
// 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_region(RePlaceholder(placeholder))
|
||||
self.tcx().mk_re_placeholder(placeholder)
|
||||
}
|
||||
Err(_) => self.tcx().lifetimes.re_static,
|
||||
};
|
||||
@ -1046,7 +1046,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
|
||||
ty::ReVar(rid) => match self.values[rid] {
|
||||
VarValue::Empty(_) => r,
|
||||
VarValue::Value(r) => r,
|
||||
VarValue::ErrorValue => tcx.re_error_misc(),
|
||||
VarValue::ErrorValue => tcx.mk_re_error_misc(),
|
||||
},
|
||||
_ => r,
|
||||
};
|
||||
|
@ -1093,7 +1093,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
) -> ty::Region<'tcx> {
|
||||
let region_var =
|
||||
self.inner.borrow_mut().unwrap_region_constraints().new_region_var(universe, origin);
|
||||
self.tcx.mk_region(ty::ReVar(region_var))
|
||||
self.tcx.mk_re_var(region_var)
|
||||
}
|
||||
|
||||
/// Return the universe that the region `r` was created in. For
|
||||
|
@ -280,7 +280,7 @@ impl<'me, 'tcx> LeakCheck<'me, 'tcx> {
|
||||
placeholder1: ty::PlaceholderRegion,
|
||||
placeholder2: ty::PlaceholderRegion,
|
||||
) -> TypeError<'tcx> {
|
||||
self.error(placeholder1, self.tcx.mk_region(ty::RePlaceholder(placeholder2)))
|
||||
self.error(placeholder1, self.tcx.mk_re_placeholder(placeholder2))
|
||||
}
|
||||
|
||||
fn error(
|
||||
@ -413,19 +413,19 @@ impl<'tcx> MiniGraph<'tcx> {
|
||||
for undo_entry in undo_log {
|
||||
match undo_entry {
|
||||
&AddConstraint(Constraint::VarSubVar(a, b)) => {
|
||||
each_edge(tcx.mk_region(ReVar(a)), tcx.mk_region(ReVar(b)));
|
||||
each_edge(tcx.mk_re_var(a), tcx.mk_re_var(b));
|
||||
}
|
||||
&AddConstraint(Constraint::RegSubVar(a, b)) => {
|
||||
each_edge(a, tcx.mk_region(ReVar(b)));
|
||||
each_edge(a, tcx.mk_re_var(b));
|
||||
}
|
||||
&AddConstraint(Constraint::VarSubReg(a, b)) => {
|
||||
each_edge(tcx.mk_region(ReVar(a)), b);
|
||||
each_edge(tcx.mk_re_var(a), b);
|
||||
}
|
||||
&AddConstraint(Constraint::RegSubReg(a, b)) => {
|
||||
each_edge(a, b);
|
||||
}
|
||||
&AddGiven(a, b) => {
|
||||
each_edge(a, tcx.mk_region(ReVar(b)));
|
||||
each_edge(a, tcx.mk_re_var(b));
|
||||
}
|
||||
&AddVerify(i) => span_bug!(
|
||||
verifys[i].origin.span(),
|
||||
|
@ -651,7 +651,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
||||
let unified_region = self.unification_table().probe_value(rid);
|
||||
unified_region.0.unwrap_or_else(|| {
|
||||
let root = self.unification_table().find(rid).vid;
|
||||
tcx.reuse_or_mk_region(region, ty::ReVar(root))
|
||||
tcx.mk_re_var(root)
|
||||
})
|
||||
}
|
||||
_ => region,
|
||||
@ -675,7 +675,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
||||
) -> Region<'tcx> {
|
||||
let vars = TwoRegions { a, b };
|
||||
if let Some(&c) = self.combine_map(t).get(&vars) {
|
||||
return tcx.mk_region(ReVar(c));
|
||||
return tcx.mk_re_var(c);
|
||||
}
|
||||
let a_universe = self.universe(a);
|
||||
let b_universe = self.universe(b);
|
||||
@ -683,7 +683,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
||||
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_region(ReVar(c));
|
||||
let new_r = tcx.mk_re_var(c);
|
||||
for old_r in [a, b] {
|
||||
match t {
|
||||
Glb => self.make_subregion(origin.clone(), new_r, old_r),
|
||||
|
@ -95,7 +95,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for OpportunisticRegionResolver<'a, 'tcx
|
||||
.borrow_mut()
|
||||
.unwrap_region_constraints()
|
||||
.opportunistic_resolve_var(rid);
|
||||
TypeFolder::interner(self).reuse_or_mk_region(r, ty::ReVar(resolved))
|
||||
TypeFolder::interner(self).mk_re_var(resolved)
|
||||
}
|
||||
_ => r,
|
||||
}
|
||||
|
@ -353,7 +353,7 @@ impl<'tcx> CanonicalVarValues<'tcx> {
|
||||
var: ty::BoundVar::from_usize(i),
|
||||
kind: ty::BrAnon(i as u32, None),
|
||||
};
|
||||
tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)).into()
|
||||
tcx.mk_re_late_bound(ty::INNERMOST, br).into()
|
||||
}
|
||||
CanonicalVarKind::Const(_, ty)
|
||||
| CanonicalVarKind::PlaceholderConst(_, ty) => tcx
|
||||
|
@ -243,11 +243,20 @@ impl<'tcx> CtxtInterners<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
// For these preinterned values, an alternative would be to have
|
||||
// variable-length vectors that grow as needed. But that turned out to be
|
||||
// slightly more complex and no faster.
|
||||
|
||||
const NUM_PREINTERNED_TY_VARS: u32 = 100;
|
||||
const NUM_PREINTERNED_FRESH_TYS: u32 = 20;
|
||||
const NUM_PREINTERNED_FRESH_INT_TYS: u32 = 3;
|
||||
const NUM_PREINTERNED_FRESH_FLOAT_TYS: u32 = 3;
|
||||
|
||||
// This number may seem high, but it is reached in all but the smallest crates.
|
||||
const NUM_PREINTERNED_RE_VARS: u32 = 500;
|
||||
const NUM_PREINTERNED_RE_LATE_BOUNDS_I: u32 = 2;
|
||||
const NUM_PREINTERNED_RE_LATE_BOUNDS_V: u32 = 20;
|
||||
|
||||
pub struct CommonTypes<'tcx> {
|
||||
pub unit: Ty<'tcx>,
|
||||
pub bool: Ty<'tcx>,
|
||||
@ -295,6 +304,14 @@ pub struct CommonLifetimes<'tcx> {
|
||||
|
||||
/// Erased region, used outside of type inference.
|
||||
pub re_erased: Region<'tcx>,
|
||||
|
||||
/// Pre-interned `ReVar(ty::RegionVar(n))` for small values of `n`.
|
||||
pub re_vars: Vec<Region<'tcx>>,
|
||||
|
||||
/// Pre-interned values of the form:
|
||||
/// `ReLateBound(DebruijnIndex(i), BoundRegion { var: v, kind: BrAnon(v, None) })
|
||||
/// for small values of `i` and `v`.
|
||||
pub re_late_bounds: Vec<Vec<Region<'tcx>>>,
|
||||
}
|
||||
|
||||
pub struct CommonConsts<'tcx> {
|
||||
@ -358,7 +375,31 @@ impl<'tcx> CommonLifetimes<'tcx> {
|
||||
))
|
||||
};
|
||||
|
||||
CommonLifetimes { re_static: mk(ty::ReStatic), re_erased: mk(ty::ReErased) }
|
||||
let re_vars =
|
||||
(0..NUM_PREINTERNED_RE_VARS).map(|n| mk(ty::ReVar(ty::RegionVid::from(n)))).collect();
|
||||
|
||||
let re_late_bounds = (0..NUM_PREINTERNED_RE_LATE_BOUNDS_I)
|
||||
.map(|i| {
|
||||
(0..NUM_PREINTERNED_RE_LATE_BOUNDS_V)
|
||||
.map(|v| {
|
||||
mk(ty::ReLateBound(
|
||||
ty::DebruijnIndex::from(i),
|
||||
ty::BoundRegion {
|
||||
var: ty::BoundVar::from(v),
|
||||
kind: ty::BrAnon(v, None),
|
||||
},
|
||||
))
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.collect();
|
||||
|
||||
CommonLifetimes {
|
||||
re_static: mk(ty::ReStatic),
|
||||
re_erased: mk(ty::ReErased),
|
||||
re_vars,
|
||||
re_late_bounds,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -697,15 +738,15 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
|
||||
/// Constructs a `RegionKind::ReError` lifetime.
|
||||
#[track_caller]
|
||||
pub fn re_error(self, reported: ErrorGuaranteed) -> Region<'tcx> {
|
||||
self.mk_region(ty::ReError(reported))
|
||||
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 re_error_misc(self) -> Region<'tcx> {
|
||||
self.re_error_with_message(
|
||||
pub fn mk_re_error_misc(self) -> Region<'tcx> {
|
||||
self.mk_re_error_with_message(
|
||||
DUMMY_SP,
|
||||
"RegionKind::ReError constructed but no error reported",
|
||||
)
|
||||
@ -714,9 +755,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
/// Constructs a `RegionKind::ReError` lifetime and registers a `delay_span_bug` with the given
|
||||
/// `msg` to ensure it gets used.
|
||||
#[track_caller]
|
||||
pub fn re_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Region<'tcx> {
|
||||
pub fn mk_re_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Region<'tcx> {
|
||||
let reported = self.sess.delay_span_bug(span, msg);
|
||||
self.re_error(reported)
|
||||
self.mk_re_error(reported)
|
||||
}
|
||||
|
||||
/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`
|
||||
@ -1517,7 +1558,7 @@ macro_rules! direct_interners {
|
||||
}
|
||||
|
||||
direct_interners! {
|
||||
region: mk_region(RegionKind<'tcx>): Region -> Region<'tcx>,
|
||||
region: intern_region(RegionKind<'tcx>): Region -> Region<'tcx>,
|
||||
const_: mk_const_internal(ConstData<'tcx>): Const -> Const<'tcx>,
|
||||
const_allocation: intern_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>,
|
||||
layout: intern_layout(LayoutS): Layout -> Layout<'tcx>,
|
||||
@ -1631,13 +1672,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Same a `self.mk_region(kind)`, but avoids accessing the interners if
|
||||
/// `*r == kind`.
|
||||
#[inline]
|
||||
pub fn reuse_or_mk_region(self, r: Region<'tcx>, kind: RegionKind<'tcx>) -> Region<'tcx> {
|
||||
if *r == kind { r } else { self.mk_region(kind) }
|
||||
}
|
||||
|
||||
// Avoid this in favour of more specific `mk_*` methods, where possible.
|
||||
#[allow(rustc::usage_of_ty_tykind)]
|
||||
#[inline]
|
||||
@ -1966,7 +2000,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> GenericArg<'tcx> {
|
||||
match param.kind {
|
||||
GenericParamDefKind::Lifetime => {
|
||||
self.mk_region(ty::ReEarlyBound(param.to_early_bound_region_data())).into()
|
||||
self.mk_re_early_bound(param.to_early_bound_region_data()).into()
|
||||
}
|
||||
GenericParamDefKind::Type { .. } => self.mk_ty_param(param.index, param.name).into(),
|
||||
GenericParamDefKind::Const { .. } => self
|
||||
@ -1998,6 +2032,66 @@ impl<'tcx> TyCtxt<'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(v, None) } = bound_region
|
||||
&& var.as_u32() == v
|
||||
&& let Some(inner) = self.lifetimes.re_late_bounds.get(debruijn.as_usize())
|
||||
&& let Some(re) = inner.get(v 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(self, kind: ty::RegionKind<'tcx>) -> Region<'tcx> {
|
||||
match kind {
|
||||
ty::ReEarlyBound(region) => self.mk_re_early_bound(region),
|
||||
ty::ReLateBound(debruijn, region) => self.mk_re_late_bound(debruijn, region),
|
||||
ty::ReFree(ty::FreeRegion { scope, bound_region }) => {
|
||||
self.mk_re_free(scope, bound_region)
|
||||
}
|
||||
ty::ReStatic => self.lifetimes.re_static,
|
||||
ty::ReVar(vid) => self.mk_re_var(vid),
|
||||
ty::RePlaceholder(region) => self.mk_re_placeholder(region),
|
||||
ty::ReErased => self.lifetimes.re_erased,
|
||||
ty::ReError(reported) => self.mk_re_error(reported),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> {
|
||||
self.mk_place_elem(place, PlaceElem::Field(f, ty))
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ where
|
||||
// debruijn index. Then we adjust it to the
|
||||
// correct depth.
|
||||
assert_eq!(debruijn1, ty::INNERMOST);
|
||||
self.tcx.reuse_or_mk_region(region, ty::ReLateBound(debruijn, br))
|
||||
self.tcx.mk_re_late_bound(debruijn, br)
|
||||
} else {
|
||||
region
|
||||
}
|
||||
@ -349,10 +349,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
self.replace_late_bound_regions_uncached(value, |br| {
|
||||
self.mk_region(ty::ReFree(ty::FreeRegion {
|
||||
scope: all_outlive_scope,
|
||||
bound_region: br.kind,
|
||||
}))
|
||||
self.mk_re_free(all_outlive_scope, br.kind)
|
||||
})
|
||||
}
|
||||
|
||||
@ -365,10 +362,10 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
value,
|
||||
FnMutDelegate {
|
||||
regions: &mut |r: ty::BoundRegion| {
|
||||
self.mk_region(ty::ReLateBound(
|
||||
self.mk_re_late_bound(
|
||||
ty::INNERMOST,
|
||||
ty::BoundRegion { var: shift_bv(r.var), kind: r.kind },
|
||||
))
|
||||
)
|
||||
},
|
||||
types: &mut |t: ty::BoundTy| {
|
||||
self.mk_bound(ty::INNERMOST, ty::BoundTy { var: shift_bv(t.var), kind: t.kind })
|
||||
@ -409,7 +406,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
})
|
||||
.expect_region();
|
||||
let br = ty::BoundRegion { var, kind };
|
||||
self.tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br))
|
||||
self.tcx.mk_re_late_bound(ty::INNERMOST, br)
|
||||
}
|
||||
fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> {
|
||||
let entry = self.map.entry(bt.var);
|
||||
@ -479,8 +476,7 @@ impl<'tcx> ir::TypeFolder<TyCtxt<'tcx>> for Shifter<'tcx> {
|
||||
match *r {
|
||||
ty::ReLateBound(debruijn, br) if debruijn >= self.current_index => {
|
||||
let debruijn = debruijn.shifted_in(self.amount);
|
||||
let shifted = ty::ReLateBound(debruijn, br);
|
||||
self.tcx.mk_region(shifted)
|
||||
self.tcx.mk_re_late_bound(debruijn, br)
|
||||
}
|
||||
_ => r,
|
||||
}
|
||||
@ -521,7 +517,7 @@ pub fn shift_region<'tcx>(
|
||||
) -> ty::Region<'tcx> {
|
||||
match *region {
|
||||
ty::ReLateBound(debruijn, br) if amount > 0 => {
|
||||
tcx.mk_region(ty::ReLateBound(debruijn.shifted_in(amount), br))
|
||||
tcx.mk_re_late_bound(debruijn.shifted_in(amount), br)
|
||||
}
|
||||
_ => region,
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ impl GenericParamDef {
|
||||
preceding_substs: &[ty::GenericArg<'tcx>],
|
||||
) -> ty::GenericArg<'tcx> {
|
||||
match &self.kind {
|
||||
ty::GenericParamDefKind::Lifetime => tcx.re_error_misc().into(),
|
||||
ty::GenericParamDefKind::Lifetime => tcx.mk_re_error_misc().into(),
|
||||
ty::GenericParamDefKind::Type { .. } => tcx.ty_error().into(),
|
||||
ty::GenericParamDefKind::Const { .. } => {
|
||||
tcx.const_error(tcx.bound_type_of(self.def_id).subst(tcx, preceding_substs)).into()
|
||||
|
@ -143,7 +143,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
|
||||
)
|
||||
.emit();
|
||||
|
||||
self.interner().re_error(e)
|
||||
self.interner().mk_re_error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ impl<'tcx> RegionHighlightMode<'tcx> {
|
||||
|
||||
/// Convenience wrapper for `highlighting_region`.
|
||||
pub fn highlighting_region_vid(&mut self, vid: ty::RegionVid, number: usize) {
|
||||
self.highlighting_region(self.tcx.mk_region(ty::ReVar(vid)), number)
|
||||
self.highlighting_region(self.tcx.mk_re_var(vid), number)
|
||||
}
|
||||
|
||||
/// Returns `Some(n)` with the number to use for the given region, if any.
|
||||
@ -2271,7 +2271,7 @@ impl<'a, 'tcx> ty::ir::TypeFolder<TyCtxt<'tcx>> for RegionFolder<'a, 'tcx> {
|
||||
};
|
||||
if let ty::ReLateBound(debruijn1, br) = *region {
|
||||
assert_eq!(debruijn1, ty::INNERMOST);
|
||||
self.tcx.mk_region(ty::ReLateBound(self.current_index, br))
|
||||
self.tcx.mk_re_late_bound(self.current_index, br)
|
||||
} else {
|
||||
region
|
||||
}
|
||||
@ -2383,10 +2383,10 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
|
||||
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_region(ty::ReLateBound(
|
||||
return tcx.mk_re_late_bound(
|
||||
ty::INNERMOST,
|
||||
ty::BoundRegion { var: br.var, kind },
|
||||
));
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2398,10 +2398,10 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
|
||||
if let Some(lt_idx) = lifetime_idx {
|
||||
if lt_idx > binder_level_idx {
|
||||
let kind = ty::BrNamed(def_id, name);
|
||||
return tcx.mk_region(ty::ReLateBound(
|
||||
return tcx.mk_re_late_bound(
|
||||
ty::INNERMOST,
|
||||
ty::BoundRegion { var: br.var, kind },
|
||||
));
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2411,10 +2411,10 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
|
||||
if let Some(lt_idx) = lifetime_idx {
|
||||
if lt_idx > binder_level_idx {
|
||||
let kind = br.kind;
|
||||
return tcx.mk_region(ty::ReLateBound(
|
||||
return tcx.mk_re_late_bound(
|
||||
ty::INNERMOST,
|
||||
ty::BoundRegion { var: br.var, kind },
|
||||
));
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2426,7 +2426,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
|
||||
start_or_continue(&mut self, "for<", ", ");
|
||||
do_continue(&mut self, name);
|
||||
}
|
||||
tcx.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BoundRegion { var: br.var, kind }))
|
||||
tcx.mk_re_late_bound(ty::INNERMOST, ty::BoundRegion { var: br.var, kind })
|
||||
};
|
||||
let mut folder = RegionFolder {
|
||||
tcx,
|
||||
|
@ -1187,7 +1187,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for SkipBindersAt<'tcx> {
|
||||
if index == self.index {
|
||||
Err(())
|
||||
} else {
|
||||
Ok(self.interner().mk_region(ty::ReLateBound(index.shifted_out(1), bv)))
|
||||
Ok(self.interner().mk_re_late_bound(index.shifted_out(1), bv))
|
||||
}
|
||||
} else {
|
||||
r.try_super_fold_with(self)
|
||||
|
@ -564,14 +564,14 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
self,
|
||||
closure_def_id: DefId,
|
||||
closure_substs: SubstsRef<'tcx>,
|
||||
env_region: ty::RegionKind<'tcx>,
|
||||
env_region: ty::Region<'tcx>,
|
||||
) -> Option<Ty<'tcx>> {
|
||||
let closure_ty = self.mk_closure(closure_def_id, closure_substs);
|
||||
let closure_kind_ty = closure_substs.as_closure().kind_ty();
|
||||
let closure_kind = closure_kind_ty.to_opt_closure_kind()?;
|
||||
let env_ty = match closure_kind {
|
||||
ty::ClosureKind::Fn => self.mk_imm_ref(self.mk_region(env_region), closure_ty),
|
||||
ty::ClosureKind::FnMut => self.mk_mut_ref(self.mk_region(env_region), closure_ty),
|
||||
ty::ClosureKind::Fn => self.mk_imm_ref(env_region, closure_ty),
|
||||
ty::ClosureKind::FnMut => self.mk_mut_ref(env_region, closure_ty),
|
||||
ty::ClosureKind::FnOnce => closure_ty,
|
||||
};
|
||||
Some(env_ty)
|
||||
|
@ -140,7 +140,7 @@ impl<'tcx> Cx<'tcx> {
|
||||
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
|
||||
kind: ty::BrEnv,
|
||||
};
|
||||
let env_region = ty::ReLateBound(ty::INNERMOST, br);
|
||||
let env_region = self.tcx.mk_re_late_bound(ty::INNERMOST, br);
|
||||
let closure_env_ty =
|
||||
self.tcx.closure_env_ty(closure_def_id, closure_substs, env_region).unwrap();
|
||||
let liberated_closure_env_ty = self.tcx.erase_late_bound_regions(
|
||||
|
@ -3,7 +3,7 @@ use crate::MirPass;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_middle::mir::interpret::AllocId;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::{self, AdtDef, Const, ParamEnv, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, AdtDef, ParamEnv, Ty, TyCtxt};
|
||||
use rustc_session::Session;
|
||||
use rustc_target::abi::{HasDataLayout, Size, TagEncoding, Variants};
|
||||
|
||||
@ -141,10 +141,7 @@ impl EnumSizeOpt {
|
||||
self.candidate(tcx, param_env, ty, &mut alloc_cache)?;
|
||||
let alloc = tcx.global_alloc(alloc_id).unwrap_memory();
|
||||
|
||||
let tmp_ty = tcx.mk_ty(ty::Array(
|
||||
tcx.types.usize,
|
||||
Const::from_target_usize(tcx, num_variants as u64),
|
||||
));
|
||||
let tmp_ty = tcx.mk_array(tcx.types.usize, num_variants as u64);
|
||||
|
||||
let size_array_local = local_decls.push(LocalDecl::new(tmp_ty, span));
|
||||
let store_live = Statement {
|
||||
|
@ -527,8 +527,7 @@ fn virtual_call_violation_for_method<'tcx>(
|
||||
}
|
||||
}
|
||||
|
||||
let trait_object_ty =
|
||||
object_ty_for_trait(tcx, trait_def_id, tcx.mk_region(ty::ReStatic));
|
||||
let trait_object_ty = object_ty_for_trait(tcx, trait_def_id, tcx.lifetimes.re_static);
|
||||
|
||||
// e.g., `Rc<dyn Trait>`
|
||||
let trait_object_receiver =
|
||||
|
@ -767,7 +767,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for BoundVarReplacer<'_, 'tcx> {
|
||||
let universe = self.universe_for(debruijn);
|
||||
let p = ty::PlaceholderRegion { universe, name: br.kind };
|
||||
self.mapped_regions.insert(p, br);
|
||||
self.infcx.tcx.mk_region(ty::RePlaceholder(p))
|
||||
self.infcx.tcx.mk_re_placeholder(p)
|
||||
}
|
||||
_ => r,
|
||||
}
|
||||
@ -888,7 +888,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for PlaceholderReplacer<'_, 'tcx> {
|
||||
let db = ty::DebruijnIndex::from_usize(
|
||||
self.universe_indices.len() - index + self.current_index.as_usize() - 1,
|
||||
);
|
||||
self.interner().mk_region(ty::ReLateBound(db, *replace_var))
|
||||
self.interner().mk_re_late_bound(db, *replace_var)
|
||||
}
|
||||
None => r1,
|
||||
}
|
||||
|
@ -540,13 +540,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, '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_region(ty::ReLateBound(
|
||||
tcx.mk_re_late_bound(
|
||||
ty::INNERMOST,
|
||||
ty::BoundRegion {
|
||||
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
|
||||
kind,
|
||||
},
|
||||
))
|
||||
)
|
||||
.into()
|
||||
}
|
||||
GenericParamDefKind::Const { .. } => {
|
||||
|
@ -3023,7 +3023,7 @@ fn bind_generator_hidden_types_above<'tcx>(
|
||||
kind: ty::BrAnon(counter, None),
|
||||
};
|
||||
counter += 1;
|
||||
r = tcx.mk_region(ty::ReLateBound(current_depth, br));
|
||||
r = tcx.mk_re_late_bound(current_depth, br);
|
||||
}
|
||||
r
|
||||
})
|
||||
|
@ -732,7 +732,7 @@ fn bound_vars_for_item(tcx: TyCtxt<'_>, def_id: DefId) -> SubstsRef<'_> {
|
||||
var: ty::BoundVar::from_usize(substs.len()),
|
||||
kind: ty::BrAnon(substs.len() as u32, None),
|
||||
};
|
||||
tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)).into()
|
||||
tcx.mk_re_late_bound(ty::INNERMOST, br).into()
|
||||
}
|
||||
|
||||
ty::GenericParamDefKind::Const { .. } => tcx
|
||||
|
@ -521,8 +521,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'t
|
||||
|
||||
impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'tcx>> {
|
||||
fn lower_into(self, interner: RustInterner<'tcx>) -> Region<'tcx> {
|
||||
let kind = match self.data(interner) {
|
||||
chalk_ir::LifetimeData::BoundVar(var) => ty::ReLateBound(
|
||||
let tcx = interner.tcx;
|
||||
match self.data(interner) {
|
||||
chalk_ir::LifetimeData::BoundVar(var) => tcx.mk_re_late_bound(
|
||||
ty::DebruijnIndex::from_u32(var.debruijn.depth()),
|
||||
ty::BoundRegion {
|
||||
var: ty::BoundVar::from_usize(var.index),
|
||||
@ -530,15 +531,14 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t
|
||||
},
|
||||
),
|
||||
chalk_ir::LifetimeData::InferenceVar(_var) => unimplemented!(),
|
||||
chalk_ir::LifetimeData::Placeholder(p) => ty::RePlaceholder(ty::Placeholder {
|
||||
chalk_ir::LifetimeData::Placeholder(p) => tcx.mk_re_placeholder(ty::Placeholder {
|
||||
universe: ty::UniverseIndex::from_usize(p.ui.counter),
|
||||
name: ty::BoundRegionKind::BrAnon(p.idx as u32, None),
|
||||
}),
|
||||
chalk_ir::LifetimeData::Static => return interner.tcx.lifetimes.re_static,
|
||||
chalk_ir::LifetimeData::Erased => return interner.tcx.lifetimes.re_erased,
|
||||
chalk_ir::LifetimeData::Static => tcx.lifetimes.re_static,
|
||||
chalk_ir::LifetimeData::Erased => tcx.lifetimes.re_erased,
|
||||
chalk_ir::LifetimeData::Phantom(void, _) => match *void {},
|
||||
};
|
||||
interner.tcx.mk_region(kind)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1025,7 +1025,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for NamedBoundVarSubstitutor<'a, 'tcx> {
|
||||
ty::BrNamed(def_id, _name) => match self.named_parameters.get(&def_id) {
|
||||
Some(idx) => {
|
||||
let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(*idx, None) };
|
||||
return self.tcx.mk_region(ty::ReLateBound(index, new_br));
|
||||
return self.tcx.mk_re_late_bound(index, new_br);
|
||||
}
|
||||
None => panic!("Missing `BrNamed`."),
|
||||
},
|
||||
@ -1107,7 +1107,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ParamsSubstitutor<'tcx> {
|
||||
var: ty::BoundVar::from_u32(*idx),
|
||||
kind: ty::BrAnon(*idx, None),
|
||||
};
|
||||
self.tcx.mk_region(ty::ReLateBound(self.binder_index, br))
|
||||
self.tcx.mk_re_late_bound(self.binder_index, br)
|
||||
}
|
||||
None => {
|
||||
let idx = self.named_regions.len() as u32;
|
||||
@ -1116,7 +1116,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ParamsSubstitutor<'tcx> {
|
||||
kind: ty::BrAnon(idx, None),
|
||||
};
|
||||
self.named_regions.insert(_re.def_id, idx);
|
||||
self.tcx.mk_region(ty::ReLateBound(self.binder_index, br))
|
||||
self.tcx.mk_re_late_bound(self.binder_index, br)
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -70,7 +70,7 @@ fn fn_sig_for_fn_abi<'tcx>(
|
||||
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
|
||||
kind: ty::BoundRegionKind::BrEnv,
|
||||
};
|
||||
let env_region = ty::ReLateBound(ty::INNERMOST, br);
|
||||
let env_region = tcx.mk_re_late_bound(ty::INNERMOST, br);
|
||||
let env_ty = tcx.closure_env_ty(def_id, substs, env_region).unwrap();
|
||||
|
||||
let sig = sig.skip_binder();
|
||||
@ -95,8 +95,7 @@ fn fn_sig_for_fn_abi<'tcx>(
|
||||
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
|
||||
kind: ty::BoundRegionKind::BrEnv,
|
||||
};
|
||||
let env_region = ty::ReLateBound(ty::INNERMOST, br);
|
||||
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);
|
||||
let env_ty = tcx.mk_mut_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), ty);
|
||||
|
||||
let pin_did = tcx.require_lang_item(LangItem::Pin, None);
|
||||
let pin_adt_ref = tcx.adt_def(pin_did);
|
||||
|
Loading…
Reference in New Issue
Block a user