Use ty::OpaqueTy everywhere
This commit is contained in:
parent
918ede6474
commit
7f3af72606
55 changed files with 156 additions and 118 deletions
|
@ -117,6 +117,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
|
|||
type BinderListTy = Binder<'tcx, &'tcx List<Ty<'tcx>>>;
|
||||
type ListTy = &'tcx List<Ty<'tcx>>;
|
||||
type ProjectionTy = ty::ProjectionTy<'tcx>;
|
||||
type OpaqueTy = ty::OpaqueTy<'tcx>;
|
||||
type ParamTy = ParamTy;
|
||||
type BoundTy = ty::BoundTy;
|
||||
type PlaceholderType = ty::PlaceholderType;
|
||||
|
@ -2323,7 +2324,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::Opaque(def_id, _) = ty.kind() else { return false };
|
||||
let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = ty.kind() else { return false };
|
||||
let future_trait = self.require_lang_item(LangItem::Future, None);
|
||||
|
||||
self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| {
|
||||
|
@ -2668,7 +2669,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
|
||||
#[inline]
|
||||
pub fn mk_opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
|
||||
self.mk_ty(Opaque(def_id, substs))
|
||||
self.mk_ty(Opaque(ty::OpaqueTy { def_id, substs }))
|
||||
}
|
||||
|
||||
pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> {
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::ops::ControlFlow;
|
|||
|
||||
use crate::ty::{
|
||||
visit::TypeVisitable, Const, ConstKind, DefIdTree, ExistentialPredicate, InferConst, InferTy,
|
||||
PolyTraitPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor,
|
||||
OpaqueTy, PolyTraitPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor,
|
||||
};
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
|
@ -457,11 +457,11 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> {
|
|||
return ControlFlow::Break(());
|
||||
}
|
||||
|
||||
Opaque(did, _) => {
|
||||
let parent = self.tcx.parent(*did);
|
||||
Opaque(OpaqueTy { def_id, substs: _ }) => {
|
||||
let parent = self.tcx.parent(*def_id);
|
||||
if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent)
|
||||
&& let Opaque(parent_did, _) = self.tcx.type_of(parent).kind()
|
||||
&& parent_did == did
|
||||
&& let Opaque(OpaqueTy { def_id: parent_opaque_def_id, substs: _ }) = self.tcx.type_of(parent).kind()
|
||||
&& parent_opaque_def_id == def_id
|
||||
{
|
||||
// Okay
|
||||
} else {
|
||||
|
|
|
@ -779,7 +779,7 @@ fn foo(&self) -> Self::T { String::new() }
|
|||
ty: Ty<'tcx>,
|
||||
) -> bool {
|
||||
let assoc = self.associated_item(proj_ty.item_def_id);
|
||||
if let ty::Opaque(def_id, _) = *proj_ty.self_ty().kind() {
|
||||
if let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = *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::Opaque(_, substs) => {
|
||||
&ty::Opaque(ty::OpaqueTy { def_id: _, 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::Opaque(def_id, substs) => {
|
||||
ty::Opaque(ty::OpaqueTy { 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,9 @@ pub trait PrettyPrinter<'tcx>:
|
|||
let parent = self.tcx().parent(def_id);
|
||||
match self.tcx().def_kind(parent) {
|
||||
DefKind::TyAlias | DefKind::AssocTy => {
|
||||
if let ty::Opaque(d, _) = *self.tcx().type_of(parent).kind() {
|
||||
if let ty::Opaque(ty::OpaqueTy { def_id: d, substs: _ }) =
|
||||
*self.tcx().type_of(parent).kind()
|
||||
{
|
||||
if d == def_id {
|
||||
// If the type alias directly starts with the `impl` of the
|
||||
// opaque type we're printing, then skip the `::{opaque#1}`.
|
||||
|
|
|
@ -564,9 +564,10 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>(
|
|||
Ok(tcx.mk_projection(projection_ty.item_def_id, projection_ty.substs))
|
||||
}
|
||||
|
||||
(&ty::Opaque(a_def_id, a_substs), &ty::Opaque(b_def_id, b_substs))
|
||||
if a_def_id == b_def_id =>
|
||||
{
|
||||
(
|
||||
&ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: a_substs }),
|
||||
&ty::Opaque(ty::OpaqueTy { 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
|
||||
// differ, as they could resolve to the same hidden type, even for different generic params.
|
||||
|
|
|
@ -652,7 +652,9 @@ impl<'tcx> TypeSuperFoldable<'tcx> for Ty<'tcx> {
|
|||
ty::GeneratorWitness(types) => ty::GeneratorWitness(types.try_fold_with(folder)?),
|
||||
ty::Closure(did, substs) => ty::Closure(did, substs.try_fold_with(folder)?),
|
||||
ty::Projection(data) => ty::Projection(data.try_fold_with(folder)?),
|
||||
ty::Opaque(did, substs) => ty::Opaque(did, substs.try_fold_with(folder)?),
|
||||
ty::Opaque(ty::OpaqueTy { def_id, substs }) => {
|
||||
ty::Opaque(ty::OpaqueTy { def_id, substs: substs.try_fold_with(folder)? })
|
||||
}
|
||||
|
||||
ty::Bool
|
||||
| ty::Char
|
||||
|
@ -698,7 +700,7 @@ impl<'tcx> TypeSuperVisitable<'tcx> for Ty<'tcx> {
|
|||
ty::GeneratorWitness(ref types) => types.visit_with(visitor),
|
||||
ty::Closure(_did, ref substs) => substs.visit_with(visitor),
|
||||
ty::Projection(ref data) => data.visit_with(visitor),
|
||||
ty::Opaque(_, ref substs) => substs.visit_with(visitor),
|
||||
ty::Opaque(ty::OpaqueTy { def_id: _, ref substs }) => substs.visit_with(visitor),
|
||||
|
||||
ty::Bool
|
||||
| ty::Char
|
||||
|
|
|
@ -826,7 +826,7 @@ impl<'tcx> TypeFolder<'tcx> for OpaqueTypeExpander<'tcx> {
|
|||
}
|
||||
|
||||
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
||||
if let ty::Opaque(def_id, substs) = *t.kind() {
|
||||
if let ty::Opaque(ty::OpaqueTy { 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)
|
||||
|
|
|
@ -188,7 +188,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>)
|
|||
}));
|
||||
}
|
||||
ty::Adt(_, substs)
|
||||
| ty::Opaque(_, substs)
|
||||
| ty::Opaque(ty::OpaqueTy { def_id: _, substs })
|
||||
| ty::Closure(_, substs)
|
||||
| ty::Generator(_, substs, _)
|
||||
| ty::FnDef(_, substs) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue