Ensure no one constructs AliasTy
s themselves
This commit is contained in:
parent
4ffe3bdf99
commit
a5cd3bde95
50 changed files with 104 additions and 106 deletions
|
@ -2321,7 +2321,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
|
||||
/// Given a `ty`, return whether it's an `impl Future<...>`.
|
||||
pub fn ty_is_opaque_future(self, ty: Ty<'_>) -> bool {
|
||||
let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = ty.kind() else { return false };
|
||||
let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = ty.kind() else { return false };
|
||||
let future_trait = self.require_lang_item(LangItem::Future, None);
|
||||
|
||||
self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| {
|
||||
|
@ -2673,7 +2673,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
|
||||
#[inline]
|
||||
pub fn mk_opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
|
||||
self.mk_ty(Alias(ty::Opaque, ty::AliasTy { def_id, substs }))
|
||||
self.mk_ty(Alias(ty::Opaque, self.mk_alias_ty(def_id, substs)))
|
||||
}
|
||||
|
||||
pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> {
|
||||
|
@ -2888,7 +2888,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
substs.collect::<Vec<_>>(),
|
||||
);
|
||||
let substs = self.mk_substs(substs);
|
||||
ty::AliasTy { def_id, substs }
|
||||
ty::AliasTy { def_id, substs, _use_mk_alias_ty_instead: () }
|
||||
}
|
||||
|
||||
pub fn mk_bound_variable_kinds<
|
||||
|
|
|
@ -457,10 +457,10 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> {
|
|||
return ControlFlow::Break(());
|
||||
}
|
||||
|
||||
Alias(Opaque, AliasTy { def_id, substs: _ }) => {
|
||||
Alias(Opaque, AliasTy { def_id, .. }) => {
|
||||
let parent = self.tcx.parent(*def_id);
|
||||
if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent)
|
||||
&& let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, substs: _ }) = self.tcx.type_of(parent).kind()
|
||||
&& let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = self.tcx.type_of(parent).kind()
|
||||
&& parent_opaque_def_id == def_id
|
||||
{
|
||||
// Okay
|
||||
|
|
|
@ -779,8 +779,7 @@ fn foo(&self) -> Self::T { String::new() }
|
|||
ty: Ty<'tcx>,
|
||||
) -> bool {
|
||||
let assoc = self.associated_item(proj_ty.def_id);
|
||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *proj_ty.self_ty().kind()
|
||||
{
|
||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *proj_ty.self_ty().kind() {
|
||||
let opaque_local_def_id = def_id.as_local();
|
||||
let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id {
|
||||
match &self.hir().expect_item(opaque_local_def_id).kind {
|
||||
|
|
|
@ -160,7 +160,7 @@ impl FlagComputation {
|
|||
self.add_projection_ty(data);
|
||||
}
|
||||
|
||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs }) => {
|
||||
&ty::Alias(ty::Opaque, ty::AliasTy { substs, .. }) => {
|
||||
self.add_flags(TypeFlags::HAS_TY_OPAQUE);
|
||||
self.add_substs(substs);
|
||||
}
|
||||
|
|
|
@ -728,7 +728,7 @@ pub trait PrettyPrinter<'tcx>:
|
|||
}
|
||||
}
|
||||
ty::Placeholder(placeholder) => p!(write("Placeholder({:?})", placeholder)),
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
|
||||
// FIXME(eddyb) print this with `print_def_path`.
|
||||
// We use verbose printing in 'NO_QUERIES' mode, to
|
||||
// avoid needing to call `predicates_of`. This should
|
||||
|
@ -743,7 +743,7 @@ pub trait PrettyPrinter<'tcx>:
|
|||
let parent = self.tcx().parent(def_id);
|
||||
match self.tcx().def_kind(parent) {
|
||||
DefKind::TyAlias | DefKind::AssocTy => {
|
||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: d, substs: _ }) =
|
||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: d, .. }) =
|
||||
*self.tcx().type_of(parent).kind()
|
||||
{
|
||||
if d == def_id {
|
||||
|
|
|
@ -557,8 +557,8 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>(
|
|||
}
|
||||
|
||||
(
|
||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: a_substs }),
|
||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: b_substs }),
|
||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: a_substs, .. }),
|
||||
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: b_substs, .. }),
|
||||
) if a_def_id == b_def_id => {
|
||||
if relation.intercrate() {
|
||||
// During coherence, opaque types should be treated as equal to each other, even if their generic params
|
||||
|
|
|
@ -1166,6 +1166,10 @@ pub struct AliasTy<'tcx> {
|
|||
/// `TraitRef` containing this associated type, which is in `tcx.associated_item(def_id).container`,
|
||||
/// aka. `tcx.parent(def_id)`.
|
||||
pub def_id: DefId,
|
||||
|
||||
/// This field exists to prevent the creation of `ProjectionTy` without using
|
||||
/// [TyCtxt::mk_projection_ty].
|
||||
pub(super) _use_mk_alias_ty_instead: (),
|
||||
}
|
||||
|
||||
impl<'tcx> AliasTy<'tcx> {
|
||||
|
|
|
@ -825,7 +825,7 @@ impl<'tcx> TypeFolder<'tcx> for OpaqueTypeExpander<'tcx> {
|
|||
}
|
||||
|
||||
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) = *t.kind() {
|
||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) = *t.kind() {
|
||||
self.expand_opaque_ty(def_id, substs).unwrap_or(t)
|
||||
} else if t.has_opaque_types() {
|
||||
t.super_fold_with(self)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue