1
Fork 0

Combine projection and opaque into alias

This commit is contained in:
Michael Goulet 2022-11-26 21:51:55 +00:00
parent c13bd83528
commit 61adaf8187
104 changed files with 387 additions and 381 deletions

View file

@ -697,7 +697,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
.map_bound(|p| p.predicates),
None,
),
ty::Opaque(ty::AliasTy { def_id, substs }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
find_fn_kind_from_did(tcx.bound_explicit_item_bounds(*def_id), Some(*substs))
}
ty::Closure(_, substs) => match substs.as_closure().kind() {

View file

@ -504,7 +504,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty;
if let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = *output_ty.kind() {
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *output_ty.kind() {
output_ty = self.infcx.tcx.type_of(def_id)
};

View file

@ -411,9 +411,9 @@ fn push_debuginfo_type_name<'tcx>(
ty::Error(_)
| ty::Infer(_)
| ty::Placeholder(..)
| ty::Projection(..)
| ty::Alias(ty::Projection, ..)
| ty::Bound(..)
| ty::Opaque(..)
| ty::Alias(ty::Opaque, ..)
| ty::GeneratorWitness(..) => {
bug!(
"debuginfo: Trying to create type name for \

View file

@ -142,12 +142,12 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
| ty::Foreign(..)
| ty::Infer(ty::FreshIntTy(_))
| ty::Infer(ty::FreshFloatTy(_))
| ty::Projection(..)
| ty::Alias(ty::Projection, ..)
| ty::Param(_)
| ty::Bound(..)
| ty::Placeholder(..)
// FIXME(oli-obk): we could look behind opaque types
| ty::Opaque(..)
| ty::Alias(ty::Opaque, ..)
| ty::Infer(_)
// FIXME(oli-obk): we can probably encode closures just like structs
| ty::Closure(..)
@ -307,11 +307,11 @@ pub fn valtree_to_const_value<'tcx>(
| ty::Foreign(..)
| ty::Infer(ty::FreshIntTy(_))
| ty::Infer(ty::FreshFloatTy(_))
| ty::Projection(..)
| ty::Alias(ty::Projection, ..)
| ty::Param(_)
| ty::Bound(..)
| ty::Placeholder(..)
| ty::Opaque(..)
| ty::Alias(ty::Opaque, ..)
| ty::Infer(_)
| ty::Closure(..)
| ty::Generator(..)

View file

@ -82,8 +82,8 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
ty::Adt(ref adt, _) => {
ConstValue::from_machine_usize(adt.variants().len() as u64, &tcx)
}
ty::Projection(_)
| ty::Opaque(ty::AliasTy { def_id: _, substs: _ })
ty::Alias(ty::Projection, _)
| ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs: _ })
| ty::Param(_)
| ty::Placeholder(_)
| ty::Infer(_) => throw_inval!(TooGeneric),

View file

@ -601,8 +601,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
| ty::Placeholder(..)
| ty::Bound(..)
| ty::Param(..)
| ty::Opaque(..)
| ty::Projection(..)
| ty::Alias(ty::Opaque, ..)
| ty::Alias(ty::Projection, ..)
| ty::GeneratorWitness(..) => bug!("Encountered invalid type {:?}", ty),
}
}

View file

@ -241,7 +241,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
};
let kind = match parent_ty.ty.kind() {
&ty::Opaque(ty::AliasTy { def_id, substs }) => {
&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
self.tcx.bound_type_of(def_id).subst(self.tcx, substs).kind()
}
kind => kind,
@ -652,7 +652,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
self.fail(location, "`SetDiscriminant`is not allowed until deaggregation");
}
let pty = place.ty(&self.body.local_decls, self.tcx).ty.kind();
if !matches!(pty, ty::Adt(..) | ty::Generator(..) | ty::Opaque(..)) {
if !matches!(pty, ty::Adt(..) | ty::Generator(..) | ty::Alias(ty::Opaque, ..)) {
self.fail(
location,
format!(

View file

@ -58,8 +58,8 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
// Types with identity (print the module path).
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs)
| ty::FnDef(def_id, substs)
| ty::Opaque(ty::AliasTy { def_id, substs })
| ty::Projection(ty::AliasTy { def_id, substs })
| ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs })
| ty::Alias(ty::Projection, ty::AliasTy { def_id, substs })
| ty::Closure(def_id, substs)
| ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs),
ty::Foreign(def_id) => self.print_def_path(def_id, &[]),

View file

@ -1241,7 +1241,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
//
// Calling `skip_binder` is okay, because `add_bounds` expects the `param_ty`
// parameter to have a skipped binder.
let param_ty = tcx.mk_ty(ty::Projection(projection_ty.skip_binder()));
let param_ty = tcx.mk_ty(ty::Alias(ty::Projection, projection_ty.skip_binder()));
self.add_bounds(param_ty, ast_bounds.iter(), bounds, candidate.bound_vars());
}
}

View file

@ -1440,7 +1440,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) -> E
impl<'tcx> ty::visit::TypeVisitor<'tcx> for OpaqueTypeCollector {
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
match *t.kind() {
ty::Opaque(ty::AliasTy { def_id: def, substs: _ }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, substs: _ }) => {
self.0.push(def);
ControlFlow::CONTINUE
}

View file

@ -571,7 +571,7 @@ impl<'tcx> TypeFolder<'tcx> for ImplTraitInTraitCollector<'_, 'tcx> {
}
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
if let ty::Projection(proj) = ty.kind()
if let ty::Alias(ty::Projection, proj) = ty.kind()
&& self.tcx().def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder
{
if let Some((ty, _)) = self.types.get(&proj.def_id) {
@ -1734,7 +1734,7 @@ pub fn check_type_bounds<'tcx>(
let normalize_param_env = {
let mut predicates = param_env.caller_bounds().iter().collect::<Vec<_>>();
match impl_ty_value.kind() {
ty::Projection(proj)
ty::Alias(ty::Projection, proj)
if proj.def_id == trait_ty.def_id && proj.substs == rebased_substs =>
{
// Don't include this predicate if the projected type is

View file

@ -759,7 +759,7 @@ impl<'tcx> TypeVisitor<'tcx> for GATSubstCollector<'tcx> {
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
match t.kind() {
ty::Projection(p) if p.def_id == self.gat => {
ty::Alias(ty::Projection, p) if p.def_id == self.gat => {
for (idx, subst) in p.substs.iter().enumerate() {
match subst.unpack() {
GenericArgKind::Lifetime(lt) if !lt.is_late_bound() => {
@ -1592,7 +1592,7 @@ fn check_return_position_impl_trait_in_trait_bounds<'tcx>(
{
for arg in fn_output.walk() {
if let ty::GenericArgKind::Type(ty) = arg.unpack()
&& let ty::Projection(proj) = ty.kind()
&& let ty::Alias(ty::Projection, proj) = ty.kind()
&& tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder
&& tcx.impl_trait_in_trait_parent(proj.def_id) == fn_def_id.to_def_id()
{

View file

@ -223,7 +223,7 @@ impl<'tcx> InherentCollect<'tcx> {
| ty::Tuple(..) => {
self.check_primitive_impl(item.owner_id.def_id, self_ty, items, ty.span)
}
ty::Projection(..) | ty::Opaque(..) | ty::Param(_) => {
ty::Alias(ty::Projection, ..) | ty::Alias(ty::Opaque, ..) | ty::Param(_) => {
let mut err = struct_span_err!(
self.tcx.sess,
ty.span,

View file

@ -1749,7 +1749,7 @@ fn is_late_bound_map(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<&FxIndexSet<
ty::Param(param_ty) => {
self.arg_is_constrained[param_ty.index as usize] = true;
}
ty::Projection(_) => return ControlFlow::Continue(()),
ty::Alias(ty::Projection, _) => return ControlFlow::Continue(()),
_ => (),
}
t.super_visit_with(self)

View file

@ -411,7 +411,7 @@ pub(super) fn explicit_predicates_of<'tcx>(
// substs are the same as the trait's.
// * It must be an associated type for this trait (*not* a
// supertrait).
if let ty::Projection(projection) = ty.kind() {
if let ty::Alias(ty::Projection, projection) = ty.kind() {
projection.substs == trait_identity_substs
&& tcx.associated_item(projection.def_id).container_id(tcx) == def_id
} else {

View file

@ -52,7 +52,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
// Using the ItemCtxt convert the HIR for the unresolved assoc type into a
// ty which is a fully resolved projection.
// For the code example above, this would mean converting Self::Assoc<3>
// into a ty::Projection(<Self as Foo>::Assoc<3>)
// into a ty::Alias(ty::Projection, <Self as Foo>::Assoc<3>)
let item_hir_id = tcx
.hir()
.parent_iter(hir_id)
@ -68,7 +68,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
// the def_id that this query was called with. We filter to only type and const args here
// as a precaution for if it's ever allowed to elide lifetimes in GAT's. It currently isn't
// but it can't hurt to be safe ^^
if let ty::Projection(projection) = ty.kind() {
if let ty::Alias(ty::Projection, projection) = ty.kind() {
let generics = tcx.generics_of(projection.def_id);
let arg_index = segment

View file

@ -59,7 +59,7 @@ struct ParameterCollector {
impl<'tcx> TypeVisitor<'tcx> for ParameterCollector {
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
match *t.kind() {
ty::Projection(..) if !self.include_nonconstraining => {
ty::Alias(ty::Projection, ..) if !self.include_nonconstraining => {
// projections are not injective
return ControlFlow::CONTINUE;
}

View file

@ -196,7 +196,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
}
}
ty::Projection(obj) => {
ty::Alias(ty::Projection, obj) => {
// This corresponds to `<T as Foo<'a>>::Bar`. In this case, we should use the
// explicit predicates as well.
debug!("Projection");

View file

@ -249,11 +249,11 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
self.add_constraints_from_substs(current, def.did(), substs, variance);
}
ty::Projection(ref data) => {
ty::Alias(ty::Projection, ref data) => {
self.add_constraints_from_invariant_substs(current, data.substs, variance);
}
ty::Opaque(ty::AliasTy { def_id: _, substs }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs }) => {
self.add_constraints_from_invariant_substs(current, substs, variance);
}

View file

@ -112,8 +112,8 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
// FIXME(alias): merge these
match t.kind() {
ty::Opaque(ty::AliasTy { def_id, substs }) => self.visit_opaque(*def_id, substs),
ty::Projection(proj)
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => self.visit_opaque(*def_id, substs),
ty::Alias(ty::Projection, proj)
if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder =>
{
self.visit_opaque(proj.def_id, proj.substs)

View file

@ -212,7 +212,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.can_coerce(arm_ty, ret_ty)
&& prior_arm.map_or(true, |(_, ty, _)| self.can_coerce(ty, ret_ty))
// The match arms need to unify for the case of `impl Trait`.
&& !matches!(ret_ty.kind(), ty::Opaque(..))
&& !matches!(ret_ty.kind(), ty::Alias(ty::Opaque, ..))
}
_ => false,
};
@ -518,7 +518,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let substs = sig.output().walk().find_map(|arg| {
if let ty::GenericArgKind::Type(ty) = arg.unpack()
&& let ty::Opaque(ty::AliasTy { def_id, substs }) = *ty.kind()
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) = *ty.kind()
&& def_id == rpit_def_id
{
Some(substs)

View file

@ -118,8 +118,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Pointers to foreign types are thin, despite being unsized
ty::Foreign(..) => Some(PointerKind::Thin),
// We should really try to normalize here.
ty::Projection(pi) => Some(PointerKind::OfProjection(pi)),
ty::Opaque(ty::AliasTy { def_id, substs }) => {
ty::Alias(ty::Projection, pi) => Some(PointerKind::OfProjection(pi)),
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
Some(PointerKind::OfOpaque(def_id, substs))
}
ty::Param(p) => Some(PointerKind::OfParam(p)),

View file

@ -167,9 +167,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expected_ty: Ty<'tcx>,
) -> (Option<ExpectedSig<'tcx>>, Option<ty::ClosureKind>) {
match *expected_ty.kind() {
ty::Opaque(ty::AliasTy { def_id, substs }) => self.deduce_signature_from_predicates(
self.tcx.bound_explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs),
),
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => self
.deduce_signature_from_predicates(
self.tcx.bound_explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs),
),
ty::Dynamic(ref object_type, ..) => {
let sig = object_type.projection_bounds().find_map(|pb| {
let pb = pb.with_self_ty(self.tcx, self.tcx.types.trait_object_dummy_self);
@ -677,13 +678,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
get_future_output(obligation.predicate, obligation.cause.span)
})?
}
ty::Opaque(ty::AliasTy { def_id, substs }) => self
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => self
.tcx
.bound_explicit_item_bounds(def_id)
.subst_iter_copied(self.tcx, substs)
.find_map(|(p, s)| get_future_output(p, s))?,
ty::Error(_) => return None,
ty::Projection(proj)
ty::Alias(ty::Projection, proj)
if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder =>
{
self.tcx

View file

@ -1805,7 +1805,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
{
let ty = <dyn AstConv<'_>>::ast_ty_to_ty(fcx, ty);
// Get the `impl Trait`'s `DefId`.
if let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = ty.kind()
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = ty.kind()
// Get the `impl Trait`'s `Item` so that we can get its trait bounds and
// get the `Trait`'s `DefId`.
&& let hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, .. }) =

View file

@ -2391,7 +2391,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::Param(param_ty) => {
self.point_at_param_definition(&mut err, param_ty);
}
ty::Opaque(ty::AliasTy { def_id: _, substs: _ }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs: _ }) => {
self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs());
}
_ => {}

View file

@ -716,7 +716,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if formal_ret.has_infer_types() {
for ty in ret_ty.walk() {
if let ty::subst::GenericArgKind::Type(ty) = ty.unpack()
&& let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = *ty.kind()
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *ty.kind()
&& let Some(def_id) = def_id.as_local()
&& self.opaque_type_origin(def_id, DUMMY_SP).is_some() {
return None;

View file

@ -2124,7 +2124,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
}
ty::Opaque(ty::AliasTy { def_id: new_def_id, substs: _ })
ty::Alias(ty::Opaque, ty::AliasTy { def_id: new_def_id, substs: _ })
| ty::Closure(new_def_id, _)
| ty::FnDef(new_def_id, _) => {
def_id = new_def_id;
@ -2217,7 +2217,7 @@ fn find_param_in_ty<'tcx>(ty: Ty<'tcx>, param_to_point_at: ty::GenericArg<'tcx>)
if arg == param_to_point_at {
return true;
} else if let ty::GenericArgKind::Type(ty) = arg.unpack()
&& let ty::Projection(..) = ty.kind()
&& let ty::Alias(ty::Projection, ..) = ty.kind()
{
// This logic may seem a bit strange, but typically when
// we have a projection type in a function signature, the

View file

@ -174,7 +174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let fn_sig = substs.as_closure().sig();
Some((DefIdOrName::DefId(def_id), fn_sig.output(), fn_sig.inputs().map_bound(|inputs| &inputs[1..])))
}
ty::Opaque(ty::AliasTy { def_id, substs }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| {
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder()
&& Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output()

View file

@ -563,7 +563,7 @@ fn check_must_not_suspend_ty<'tcx>(
}
ty::Adt(def, _) => check_must_not_suspend_def(fcx.tcx, def.did(), hir_id, data),
// FIXME: support adding the attribute to TAITs
ty::Opaque(ty::AliasTy { def_id: def, substs: _ }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, substs: _ }) => {
let mut has_emitted = false;
for &(predicate, _) in fcx.tcx.explicit_item_bounds(def) {
// We only look at the `DefId`, so it is safe to skip the binder here.

View file

@ -1969,7 +1969,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
| ty::Float(_)
| ty::Adt(_, _)
| ty::Str
| ty::Projection(_)
| ty::Alias(ty::Projection, _)
| ty::Param(_) => format!("{deref_ty}"),
// we need to test something like <&[_]>::len or <(&[u32])>::len
// and Vec::function();

View file

@ -546,7 +546,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
impl<'tcx> ty::TypeVisitor<'tcx> for RecursionChecker {
type BreakTy = ();
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
if let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = *t.kind() {
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *t.kind() {
if def_id == self.def_id.to_def_id() {
return ControlFlow::Break(());
}

View file

@ -453,10 +453,10 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
| ty::Dynamic(..)
| ty::Never
| ty::Tuple(..)
| ty::Projection(..)
| ty::Alias(ty::Projection, ..)
| ty::Foreign(..)
| ty::Param(..)
| ty::Opaque(..) => {
| ty::Alias(ty::Opaque, ..) => {
if t.flags().intersects(self.needs_canonical_flags) {
t.super_fold_with(self)
} else {

View file

@ -675,7 +675,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
// relatable.
Ok(t)
}
ty::Opaque(ty::AliasTy { def_id, substs }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
let s = self.relate(substs, substs)?;
Ok(if s == substs { t } else { self.infcx.tcx.mk_opaque(def_id, s) })
}

View file

@ -101,13 +101,13 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
}
(
&ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }),
&ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }),
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }),
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }),
) if a_def_id == b_def_id => {
self.fields.infcx.super_combine_tys(self, a, b)?;
}
(&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _)
| (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ }))
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _)
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }))
if self.fields.define_opaque_types && def_id.is_local() =>
{
self.fields.obligations.extend(

View file

@ -340,8 +340,8 @@ impl<'tcx> InferCtxt<'tcx> {
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
// FIXME(alias): Merge these
let (def_id, substs) = match *ty.kind() {
ty::Opaque(ty::AliasTy { def_id, substs }) => (def_id, substs),
ty::Projection(data)
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => (def_id, substs),
ty::Alias(ty::Projection, data)
if self.tcx.def_kind(data.def_id) == DefKind::ImplTraitPlaceholder =>
{
(data.def_id, data.substs)
@ -1732,7 +1732,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let sort_string = |ty: Ty<'tcx>, path: Option<PathBuf>| {
// FIXME(alias): Merge these
let mut s = match (extra, ty.kind()) {
(true, ty::Opaque(ty::AliasTy { def_id, .. })) => {
(true, ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) => {
let sm = self.tcx.sess.source_map();
let pos = sm.lookup_char_pos(self.tcx.def_span(*def_id).lo());
format!(
@ -1742,7 +1742,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
pos.col.to_usize() + 1,
)
}
(true, ty::Projection(proj))
(true, ty::Alias(ty::Projection, proj))
if self.tcx.def_kind(proj.def_id)
== DefKind::ImplTraitPlaceholder =>
{
@ -2385,10 +2385,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// fn get_later<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
// suggest:
// fn get_later<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
ty::Closure(_, _substs)
| ty::Opaque(ty::AliasTy { def_id: _, substs: _substs })
if return_impl_trait =>
{
ty::Closure(..) | ty::Alias(ty::Opaque, ..) if return_impl_trait => {
new_binding_suggestion(&mut err, type_param_span);
}
_ => {
@ -2770,7 +2767,9 @@ impl TyCategory {
pub fn from_ty(tcx: TyCtxt<'_>, ty: Ty<'_>) -> Option<(Self, DefId)> {
match *ty.kind() {
ty::Closure(def_id, _) => Some((Self::Closure, def_id)),
ty::Opaque(ty::AliasTy { def_id, substs: _ }) => Some((Self::Opaque, def_id)),
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => {
Some((Self::Opaque, def_id))
}
ty::Generator(def_id, ..) => {
Some((Self::Generator(tcx.generator_kind(def_id).unwrap()), def_id))
}

View file

@ -852,7 +852,10 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
match inner.unpack() {
GenericArgKind::Lifetime(_) => {}
GenericArgKind::Type(ty) => {
if matches!(ty.kind(), ty::Opaque(..) | ty::Closure(..) | ty::Generator(..)) {
if matches!(
ty.kind(),
ty::Alias(ty::Opaque, ..) | ty::Closure(..) | ty::Generator(..)
) {
// Opaque types can't be named by the user right now.
//
// Both the generic arguments of closures and generators can

View file

@ -487,12 +487,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
StatementAsExpression::CorrectType
}
(
ty::Opaque(ty::AliasTy { def_id: last_def_id, substs: _ }),
ty::Opaque(ty::AliasTy { def_id: exp_def_id, substs: _ }),
ty::Alias(ty::Opaque, ty::AliasTy { def_id: last_def_id, substs: _ }),
ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, substs: _ }),
) if last_def_id == exp_def_id => StatementAsExpression::CorrectType,
(
ty::Opaque(ty::AliasTy { def_id: last_def_id, substs: last_bounds }),
ty::Opaque(ty::AliasTy { def_id: exp_def_id, substs: exp_bounds }),
ty::Alias(ty::Opaque, ty::AliasTy { def_id: last_def_id, substs: last_bounds }),
ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, substs: exp_bounds }),
) => {
debug!(
"both opaque, likely future {:?} {:?} {:?} {:?}",

View file

@ -205,12 +205,11 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
| ty::Dynamic(..)
| ty::Never
| ty::Tuple(..)
| ty::Projection(..)
| ty::Alias(..)
| ty::Foreign(..)
| ty::Param(..)
| ty::Closure(..)
| ty::GeneratorWitness(..)
| ty::Opaque(..) => t.super_fold_with(self),
| ty::GeneratorWitness(..) => t.super_fold_with(self),
ty::Placeholder(..) | ty::Bound(..) => bug!("unexpected type {:?}", t),
}

View file

@ -106,11 +106,11 @@ where
}
(
&ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }),
&ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }),
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }),
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }),
) if a_def_id == b_def_id => infcx.super_combine_tys(this, a, b),
(&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _)
| (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ }))
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _)
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }))
if this.define_opaque_types() && def_id.is_local() =>
{
this.add_obligations(

View file

@ -281,7 +281,7 @@ where
use rustc_span::DUMMY_SP;
match *value_ty.kind() {
ty::Projection(other_projection_ty) => {
ty::Alias(ty::Projection, other_projection_ty) => {
let var = self.infcx.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::MiscVariable,
span: DUMMY_SP,
@ -335,7 +335,9 @@ where
return Ok(value_ty);
}
ty::Projection(projection_ty) if D::normalization() == NormalizationStrategy::Lazy => {
ty::Alias(ty::Projection, projection_ty)
if D::normalization() == NormalizationStrategy::Lazy =>
{
return Ok(self.relate_projection_ty(projection_ty, self.infcx.tcx.mk_ty_var(vid)));
}
@ -406,8 +408,8 @@ where
}
};
let (a, b) = match (a.kind(), b.kind()) {
(&ty::Opaque(..), _) => (a, generalize(b, false)?),
(_, &ty::Opaque(..)) => (generalize(a, true)?, b),
(&ty::Alias(ty::Opaque, ..), _) => (a, generalize(b, false)?),
(_, &ty::Alias(ty::Opaque, ..)) => (generalize(a, true)?, b),
_ => unreachable!(),
};
let cause = ObligationCause::dummy_with_span(self.delegate.span());
@ -609,8 +611,8 @@ where
(&ty::Infer(ty::TyVar(vid)), _) => self.relate_ty_var((vid, b)),
(
&ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }),
&ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }),
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }),
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }),
) if a_def_id == b_def_id => infcx.super_combine_tys(self, a, b).or_else(|err| {
self.tcx().sess.delay_span_bug(
self.delegate.span(),
@ -618,20 +620,20 @@ where
);
if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) }
}),
(&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _)
| (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ }))
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _)
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }))
if def_id.is_local() =>
{
self.relate_opaques(a, b)
}
(&ty::Projection(projection_ty), _)
(&ty::Alias(ty::Projection, projection_ty), _)
if D::normalization() == NormalizationStrategy::Lazy =>
{
Ok(self.relate_projection_ty(projection_ty, b))
}
(_, &ty::Projection(projection_ty))
(_, &ty::Alias(ty::Projection, projection_ty))
if D::normalization() == NormalizationStrategy::Lazy =>
{
Ok(self.relate_projection_ty(projection_ty, a))

View file

@ -66,7 +66,7 @@ impl<'tcx> InferCtxt<'tcx> {
lt_op: |lt| lt,
ct_op: |ct| ct,
ty_op: |ty| match *ty.kind() {
ty::Opaque(ty::AliasTy { def_id, substs: _substs })
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ })
if replace_opaque_type(def_id) =>
{
let def_span = self.tcx.def_span(def_id);
@ -106,7 +106,7 @@ impl<'tcx> InferCtxt<'tcx> {
}
let (a, b) = if a_is_expected { (a, b) } else { (b, a) };
let process = |a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected| match *a.kind() {
ty::Opaque(ty::AliasTy { def_id, substs }) if def_id.is_local() => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) if def_id.is_local() => {
let def_id = def_id.expect_local();
let origin = match self.defining_use_anchor {
DefiningAnchor::Bind(_) => {
@ -149,7 +149,9 @@ impl<'tcx> InferCtxt<'tcx> {
DefiningAnchor::Bubble => self.opaque_ty_origin_unchecked(def_id, cause.span),
DefiningAnchor::Error => return None,
};
if let ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }) = *b.kind() {
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }) =
*b.kind()
{
// We could accept this, but there are various ways to handle this situation, and we don't
// want to make a decision on it right now. Likely this case is so super rare anyway, that
// no one encounters it in practice.
@ -478,7 +480,7 @@ where
substs.as_generator().resume_ty().visit_with(self);
}
ty::Opaque(ty::AliasTy { def_id, ref substs }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, ref substs }) => {
// Skip lifetime paramters that are not captures.
let variances = self.tcx.variances_of(*def_id);
@ -489,7 +491,7 @@ where
}
}
ty::Projection(proj)
ty::Alias(ty::Projection, proj)
if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder =>
{
// Skip lifetime paramters that are not captures.
@ -566,7 +568,7 @@ impl<'tcx> InferCtxt<'tcx> {
// We can't normalize associated types from `rustc_infer`,
// but we can eagerly register inference variables for them.
// FIXME(RPITIT): Don't replace RPITITs with inference vars.
ty::Projection(projection_ty)
ty::Alias(ty::Projection, projection_ty)
if !projection_ty.has_escaping_bound_vars()
&& tcx.def_kind(projection_ty.def_id)
!= DefKind::ImplTraitPlaceholder =>
@ -581,13 +583,13 @@ impl<'tcx> InferCtxt<'tcx> {
}
// Replace all other mentions of the same opaque type with the hidden type,
// as the bounds must hold on the hidden type after all.
ty::Opaque(ty::AliasTy { def_id: def_id2, substs: substs2 })
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def_id2, substs: substs2 })
if def_id.to_def_id() == def_id2 && substs == substs2 =>
{
hidden_ty
}
// FIXME(RPITIT): This can go away when we move to associated types
ty::Projection(proj)
ty::Alias(ty::Projection, proj)
if def_id.to_def_id() == proj.def_id && substs == proj.substs =>
{
hidden_ty

View file

@ -130,7 +130,7 @@ fn compute_components<'tcx>(
// outlives any other lifetime, which is unsound.
// See https://github.com/rust-lang/rust/issues/84305 for
// more details.
ty::Opaque(ty::AliasTy { def_id, substs }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
out.push(Component::Opaque(def_id, substs));
},
@ -142,7 +142,7 @@ fn compute_components<'tcx>(
// trait-ref. Therefore, if we see any higher-ranked regions,
// we simply fallback to the most restrictive rule, which
// requires that `Pi: 'a` for all `i`.
ty::Projection(ref data) => {
ty::Alias(ty::Projection, ref data) => {
if !data.has_escaping_bound_vars() {
// best case: no escaping regions, so push the
// projection and skip the subtree (thus generating no

View file

@ -338,7 +338,7 @@ where
substs,
true,
|ty| match *ty.kind() {
ty::Opaque(ty::AliasTy { def_id, substs }) => (def_id, substs),
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => (def_id, substs),
_ => bug!("expected only projection types from env, not {:?}", ty),
},
);
@ -359,7 +359,9 @@ where
projection_ty.substs,
false,
|ty| match ty.kind() {
ty::Projection(projection_ty) => (projection_ty.def_id, projection_ty.substs),
ty::Alias(ty::Projection, projection_ty) => {
(projection_ty.def_id, projection_ty.substs)
}
_ => bug!("expected only projection types from env, not {:?}", ty),
},
);

View file

@ -131,14 +131,14 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
}
(
&ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }),
&ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }),
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }),
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }),
) if a_def_id == b_def_id => {
self.fields.infcx.super_combine_tys(self, a, b)?;
Ok(a)
}
(&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _)
| (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ }))
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _)
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }))
if self.fields.define_opaque_types && def_id.is_local() =>
{
self.fields.obligations.extend(

View file

@ -3016,8 +3016,8 @@ impl ClashingExternDeclarations {
| (Closure(..), Closure(..))
| (Generator(..), Generator(..))
| (GeneratorWitness(..), GeneratorWitness(..))
| (Projection(..), Projection(..))
| (Opaque(..), Opaque(..)) => false,
| (Alias(ty::Projection, ..), Alias(ty::Projection, ..))
| (Alias(ty::Opaque, ..), Alias(ty::Opaque, ..)) => false,
// These definitely should have been caught above.
(Bool, Bool) | (Char, Char) | (Never, Never) | (Str, Str) => unreachable!(),

View file

@ -117,7 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
// then we can emit a suggestion to add the bound.
let add_bound = match (proj_term.kind(), assoc_pred.kind().skip_binder()) {
(
ty::Opaque(ty::AliasTy { def_id, substs: _ }),
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }),
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)),
) => Some(AddBound {
suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(),

View file

@ -1139,18 +1139,20 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
// While opaque types are checked for earlier, if a projection in a struct field
// normalizes to an opaque type, then it will reach this branch.
ty::Opaque(..) => {
ty::Alias(ty::Opaque, ..) => {
FfiUnsafe { ty, reason: fluent::lint_improper_ctypes_opaque, help: None }
}
// `extern "C" fn` functions can have type parameters, which may or may not be FFI-safe,
// so they are currently ignored for the purposes of this lint.
ty::Param(..) | ty::Projection(..) if matches!(self.mode, CItemKind::Definition) => {
ty::Param(..) | ty::Alias(ty::Projection, ..)
if matches!(self.mode, CItemKind::Definition) =>
{
FfiSafe
}
ty::Param(..)
| ty::Projection(..)
| ty::Alias(ty::Projection, ..)
| ty::Infer(..)
| ty::Bound(..)
| ty::Error(_)
@ -1205,7 +1207,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
return ControlFlow::CONTINUE;
}
if let ty::Opaque(..) = ty.kind() {
if let ty::Alias(ty::Opaque, ..) = ty.kind() {
ControlFlow::Break(ty)
} else {
ty.super_visit_with(self)

View file

@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
if let hir::ExprKind::Match(await_expr, _arms, hir::MatchSource::AwaitDesugar) = expr.kind
&& let ty = cx.typeck_results().expr_ty(&await_expr)
&& let ty::Opaque(ty::AliasTy { def_id: future_def_id, substs: _ }) = ty.kind()
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id: future_def_id, substs: _ }) = ty.kind()
&& cx.tcx.ty_is_opaque_future(ty)
// FIXME: This also includes non-async fns that return `impl Future`.
&& let async_fn_def_id = cx.tcx.parent(*future_def_id)
@ -251,7 +251,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
.map(|inner| MustUsePath::Boxed(Box::new(inner)))
}
ty::Adt(def, _) => is_def_must_use(cx, def.did(), span),
ty::Opaque(ty::AliasTy { def_id: def, substs: _ }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, substs: _ }) => {
elaborate_predicates_with_span(
cx.tcx,
cx.tcx.explicit_item_bounds(def).iter().cloned(),

View file

@ -1111,7 +1111,7 @@ fn should_encode_trait_impl_trait_tys<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) ->
// associated types.
tcx.fn_sig(trait_item_def_id).skip_binder().output().walk().any(|arg| {
if let ty::GenericArgKind::Type(ty) = arg.unpack()
&& let ty::Projection(data) = ty.kind()
&& let ty::Alias(ty::Projection, data) = ty.kind()
&& tcx.def_kind(data.def_id) == DefKind::ImplTraitPlaceholder
{
true

View file

@ -115,8 +115,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
type ListBinderExistentialPredicate = &'tcx List<PolyExistentialPredicate<'tcx>>;
type BinderListTy = Binder<'tcx, &'tcx List<Ty<'tcx>>>;
type ListTy = &'tcx List<Ty<'tcx>>;
type ProjectionTy = ty::AliasTy<'tcx>;
type OpaqueTy = ty::AliasTy<'tcx>;
type AliasTy = ty::AliasTy<'tcx>;
type ParamTy = ParamTy;
type BoundTy = ty::BoundTy;
type PlaceholderType = ty::PlaceholderType;
@ -2145,8 +2144,7 @@ impl<'tcx> TyCtxt<'tcx> {
Bound,
Param,
Infer,
Projection,
Opaque,
Alias,
Foreign
)?;
@ -2323,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::Opaque(ty::AliasTy { def_id, substs: _ }) = ty.kind() else { return false };
let ty::Alias(ty::Opaque, ty::AliasTy { 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, _)| {
@ -2598,7 +2596,7 @@ impl<'tcx> TyCtxt<'tcx> {
substs.len(),
"wrong number of generic parameters for {item_def_id:?}: {substs:?}",
);
self.mk_ty(Projection(AliasTy { def_id: item_def_id, substs }))
self.mk_ty(Alias(ty::Projection, AliasTy { def_id: item_def_id, substs }))
}
#[inline]
@ -2668,7 +2666,7 @@ impl<'tcx> TyCtxt<'tcx> {
#[inline]
pub fn mk_opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
self.mk_ty(Opaque(ty::AliasTy { def_id, substs }))
self.mk_ty(Alias(ty::Opaque, ty::AliasTy { def_id, substs }))
}
pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> {

View file

@ -4,7 +4,7 @@ use std::ops::ControlFlow;
use crate::ty::{
visit::TypeVisitable, AliasTy, Const, ConstKind, DefIdTree, ExistentialPredicate, InferConst,
InferTy, PolyTraitPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor,
InferTy, Opaque, PolyTraitPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor,
};
use rustc_data_structures::fx::FxHashMap;
@ -457,10 +457,10 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> {
return ControlFlow::Break(());
}
Opaque(AliasTy { def_id, substs: _ }) => {
Alias(Opaque, AliasTy { 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(AliasTy { def_id: parent_opaque_def_id, substs: _ }) = self.tcx.type_of(parent).kind()
&& let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, substs: _ }) = self.tcx.type_of(parent).kind()
&& parent_opaque_def_id == def_id
{
// Okay

View file

@ -337,9 +337,9 @@ impl<'tcx> Ty<'tcx> {
ty::Infer(ty::FreshTy(_)) => "fresh type".into(),
ty::Infer(ty::FreshIntTy(_)) => "fresh integral type".into(),
ty::Infer(ty::FreshFloatTy(_)) => "fresh floating-point type".into(),
ty::Projection(_) => "associated type".into(),
ty::Alias(ty::Projection, _) => "associated type".into(),
ty::Param(p) => format!("type parameter `{}`", p).into(),
ty::Opaque(..) => "opaque type".into(),
ty::Alias(ty::Opaque, ..) => "opaque type".into(),
ty::Error(_) => "type error".into(),
}
}
@ -375,9 +375,9 @@ impl<'tcx> Ty<'tcx> {
ty::Tuple(..) => "tuple".into(),
ty::Placeholder(..) => "higher-ranked type".into(),
ty::Bound(..) => "bound type variable".into(),
ty::Projection(_) => "associated type".into(),
ty::Alias(ty::Projection, _) => "associated type".into(),
ty::Param(_) => "type parameter".into(),
ty::Opaque(..) => "opaque type".into(),
ty::Alias(ty::Opaque, ..) => "opaque type".into(),
}
}
}
@ -400,7 +400,7 @@ impl<'tcx> TyCtxt<'tcx> {
diag.note("no two closures, even if identical, have the same type");
diag.help("consider boxing your closure and/or using it as a trait object");
}
(ty::Opaque(..), ty::Opaque(..)) => {
(ty::Alias(ty::Opaque, ..), ty::Alias(ty::Opaque, ..)) => {
// Issue #63167
diag.note("distinct uses of `impl Trait` result in different opaque types");
}
@ -439,10 +439,10 @@ impl<'tcx> TyCtxt<'tcx> {
#traits-as-parameters",
);
}
(ty::Projection(_), ty::Projection(_)) => {
(ty::Alias(ty::Projection, _), ty::Alias(ty::Projection, _)) => {
diag.note("an associated type was expected, but a different one was found");
}
(ty::Param(p), ty::Projection(proj)) | (ty::Projection(proj), ty::Param(p))
(ty::Param(p), ty::Alias(ty::Projection, proj)) | (ty::Alias(ty::Projection, proj), ty::Param(p))
if self.def_kind(proj.def_id) != DefKind::ImplTraitPlaceholder =>
{
let generics = self.generics_of(body_owner_def_id);
@ -493,8 +493,8 @@ impl<'tcx> TyCtxt<'tcx> {
diag.note("you might be missing a type parameter or trait bound");
}
}
(ty::Param(p), ty::Dynamic(..) | ty::Opaque(..))
| (ty::Dynamic(..) | ty::Opaque(..), ty::Param(p)) => {
(ty::Param(p), ty::Dynamic(..) | ty::Alias(ty::Opaque, ..))
| (ty::Dynamic(..) | ty::Alias(ty::Opaque, ..), ty::Param(p)) => {
let generics = self.generics_of(body_owner_def_id);
let p_span = self.def_span(generics.type_param(p, self).def_id);
if !sp.contains(p_span) {
@ -553,7 +553,7 @@ impl<T> Trait<T> for X {
diag.span_label(p_span, "this type parameter");
}
}
(ty::Projection(proj_ty), _) if self.def_kind(proj_ty.def_id) != DefKind::ImplTraitPlaceholder => {
(ty::Alias(ty::Projection, proj_ty), _) if self.def_kind(proj_ty.def_id) != DefKind::ImplTraitPlaceholder => {
self.expected_projection(
diag,
proj_ty,
@ -562,7 +562,7 @@ impl<T> Trait<T> for X {
cause.code(),
);
}
(_, ty::Projection(proj_ty)) if self.def_kind(proj_ty.def_id) != DefKind::ImplTraitPlaceholder => {
(_, ty::Alias(ty::Projection, proj_ty)) if self.def_kind(proj_ty.def_id) != DefKind::ImplTraitPlaceholder => {
let msg = format!(
"consider constraining the associated type `{}` to `{}`",
values.found, values.expected,
@ -779,7 +779,8 @@ fn foo(&self) -> Self::T { String::new() }
ty: Ty<'tcx>,
) -> bool {
let assoc = self.associated_item(proj_ty.def_id);
if let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = *proj_ty.self_ty().kind() {
if let ty::Alias(ty::Opaque, ty::AliasTy { 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 {
@ -828,7 +829,7 @@ fn foo(&self) -> Self::T { String::new() }
.filter_map(|(_, item)| {
let method = self.fn_sig(item.def_id);
match *method.output().skip_binder().kind() {
ty::Projection(ty::AliasTy { def_id: item_def_id, .. })
ty::Alias(ty::Projection, ty::AliasTy { def_id: item_def_id, .. })
if item_def_id == proj_ty_item_def_id =>
{
Some((

View file

@ -126,7 +126,7 @@ pub fn simplify_type<'tcx>(
TreatParams::AsPlaceholder => Some(PlaceholderSimplifiedType),
TreatParams::AsInfer => None,
},
ty::Opaque(..) | ty::Projection(_) => match treat_params {
ty::Alias(ty::Opaque, ..) | ty::Alias(ty::Projection, _) => match treat_params {
// When treating `ty::Param` as a placeholder, projections also
// don't unify with anything else as long as they are fully normalized.
//
@ -225,7 +225,10 @@ impl DeepRejectCtxt {
match impl_ty.kind() {
// Start by checking whether the type in the impl may unify with
// pretty much everything. Just return `true` in that case.
ty::Param(_) | ty::Projection(_) | ty::Error(_) | ty::Opaque(..) => return true,
ty::Param(_)
| ty::Alias(ty::Projection, _)
| ty::Error(_)
| ty::Alias(ty::Opaque, ..) => return true,
// These types only unify with inference variables or their own
// variant.
ty::Bool
@ -323,7 +326,7 @@ impl DeepRejectCtxt {
_ => false,
},
ty::Opaque(..) => true,
ty::Alias(ty::Opaque, ..) => true,
// Impls cannot contain these types as these cannot be named directly.
ty::FnDef(..) | ty::Closure(..) | ty::Generator(..) => false,
@ -344,7 +347,7 @@ impl DeepRejectCtxt {
// projections can unify with other stuff.
//
// Looking forward to lazy normalization this is the safer strategy anyways.
ty::Projection(_) => true,
ty::Alias(ty::Projection, _) => true,
ty::Error(_) => true,

View file

@ -155,12 +155,12 @@ impl FlagComputation {
self.add_substs(substs);
}
&ty::Projection(data) => {
&ty::Alias(ty::Projection, data) => {
self.add_flags(TypeFlags::HAS_TY_PROJECTION);
self.add_projection_ty(data);
}
&ty::Opaque(ty::AliasTy { def_id: _, substs }) => {
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs }) => {
self.add_flags(TypeFlags::HAS_TY_OPAQUE);
self.add_substs(substs);
}

View file

@ -112,7 +112,7 @@ impl<'tcx> Ty<'tcx> {
InhabitedPredicate::True
}
Never => InhabitedPredicate::False,
Param(_) | Projection(_) => InhabitedPredicate::GenericType(self),
Param(_) | Alias(ty::Projection, _) => InhabitedPredicate::GenericType(self),
Tuple(tys) if tys.is_empty() => InhabitedPredicate::True,
// use a query for more complex cases
Adt(..) | Array(..) | Tuple(_) => tcx.inhabited_predicate_type(self),

View file

@ -271,7 +271,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
let non_zero = !ty.is_unsafe_ptr();
let tail = tcx.struct_tail_erasing_lifetimes(pointee, param_env);
match tail.kind() {
ty::Param(_) | ty::Projection(_) => {
ty::Param(_) | ty::Alias(ty::Projection, _) => {
debug_assert!(tail.has_non_region_param());
Ok(SizeSkeleton::Pointer { non_zero, tail: tcx.erase_regions(tail) })
}
@ -349,7 +349,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
}
}
ty::Projection(_) | ty::Opaque(..) => {
ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..) => {
let normalized = tcx.normalize_erasing_regions(param_env, ty);
if ty == normalized {
Err(err)
@ -757,10 +757,10 @@ where
}
}
ty::Projection(_)
ty::Alias(ty::Projection, _)
| ty::Bound(..)
| ty::Placeholder(..)
| ty::Opaque(..)
| ty::Alias(ty::Opaque, ..)
| ty::Param(_)
| ty::Infer(_)
| ty::Error(_) => bug!("TyAndLayout::field: unexpected type `{}`", this.ty),

View file

@ -64,6 +64,7 @@ use std::ops::ControlFlow;
use std::{fmt, str};
pub use crate::ty::diagnostics::*;
pub use rustc_type_ir::AliasKind::*;
pub use rustc_type_ir::DynKind::*;
pub use rustc_type_ir::InferTy::*;
pub use rustc_type_ir::RegionKind::*;

View file

@ -275,10 +275,10 @@ fn characteristic_def_id_of_type_cached<'a>(
| ty::Uint(_)
| ty::Str
| ty::FnPtr(_)
| ty::Projection(_)
| ty::Alias(ty::Projection, _)
| ty::Placeholder(..)
| ty::Param(_)
| ty::Opaque(..)
| ty::Alias(ty::Opaque, ..)
| ty::Infer(_)
| ty::Bound(..)
| ty::Error(_)

View file

@ -718,7 +718,7 @@ pub trait PrettyPrinter<'tcx>:
ty::Foreign(def_id) => {
p!(print_def_path(def_id, &[]));
}
ty::Projection(ref data) => {
ty::Alias(ty::Projection, ref data) => {
if !(self.should_print_verbose() || NO_QUERIES.with(|q| q.get()))
&& self.tcx().def_kind(data.def_id) == DefKind::ImplTraitPlaceholder
{
@ -728,7 +728,7 @@ pub trait PrettyPrinter<'tcx>:
}
}
ty::Placeholder(placeholder) => p!(write("Placeholder({:?})", placeholder)),
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::Opaque(ty::AliasTy { def_id: d, substs: _ }) =
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: d, substs: _ }) =
*self.tcx().type_of(parent).kind()
{
if d == def_id {
@ -1021,7 +1021,7 @@ pub trait PrettyPrinter<'tcx>:
// Skip printing `<[generator@] as Generator<_>>::Return` from async blocks,
// unless we can find out what generator return type it comes from.
let term = if let Some(ty) = term.skip_binder().ty()
&& let ty::Projection(proj) = ty.kind()
&& let ty::Alias(ty::Projection, proj) = ty.kind()
&& let Some(assoc) = tcx.opt_associated_item(proj.def_id)
&& assoc.trait_container(tcx) == tcx.lang_items().gen_trait()
&& assoc.name == rustc_span::sym::Return

View file

@ -551,14 +551,14 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>(
}
// these two are already handled downstream in case of lazy normalization
(&ty::Projection(a_data), &ty::Projection(b_data)) => {
(&ty::Alias(ty::Projection, a_data), &ty::Alias(ty::Projection, b_data)) => {
let projection_ty = relation.relate(a_data, b_data)?;
Ok(tcx.mk_projection(projection_ty.def_id, projection_ty.substs))
}
(
&ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: a_substs }),
&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

View file

@ -651,9 +651,11 @@ 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(ty::AliasTy { def_id, substs }) => {
ty::Opaque(ty::AliasTy { def_id, substs: substs.try_fold_with(folder)? })
ty::Alias(ty::Projection, data) => {
ty::Alias(ty::Projection, data.try_fold_with(folder)?)
}
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: substs.try_fold_with(folder)? })
}
ty::Bool
@ -699,8 +701,10 @@ impl<'tcx> TypeSuperVisitable<'tcx> for Ty<'tcx> {
ty::Generator(_did, ref substs, _) => substs.visit_with(visitor),
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(ty::AliasTy { def_id: _, ref substs }) => substs.visit_with(visitor),
ty::Alias(ty::Projection, ref data) => data.visit_with(visitor),
ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, ref substs }) => {
substs.visit_with(visitor)
}
ty::Bool
| ty::Char

View file

@ -1980,7 +1980,7 @@ impl<'tcx> Ty<'tcx> {
#[inline]
pub fn is_impl_trait(self) -> bool {
matches!(self.kind(), Opaque(..))
matches!(self.kind(), Alias(ty::Opaque, ..))
}
#[inline]
@ -2047,7 +2047,10 @@ impl<'tcx> Ty<'tcx> {
ty::Adt(adt, _) if adt.is_enum() => adt.repr().discr_type().to_ty(tcx),
ty::Generator(_, substs, _) => substs.as_generator().discr_ty(tcx),
ty::Param(_) | ty::Projection(_) | ty::Opaque(..) | ty::Infer(ty::TyVar(_)) => {
ty::Param(_)
| ty::Alias(ty::Projection, _)
| ty::Alias(ty::Opaque, ..)
| ty::Infer(ty::TyVar(_)) => {
let assoc_items = tcx.associated_item_def_ids(
tcx.require_lang_item(hir::LangItem::DiscriminantKind, None),
);
@ -2127,7 +2130,7 @@ impl<'tcx> Ty<'tcx> {
// type parameters only have unit metadata if they're sized, so return true
// to make sure we double check this during confirmation
ty::Param(_) | ty::Projection(_) | ty::Opaque(..) => (tcx.types.unit, true),
ty::Param(_) | ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..) => (tcx.types.unit, true),
ty::Infer(ty::TyVar(_))
| ty::Bound(..)
@ -2203,7 +2206,7 @@ impl<'tcx> Ty<'tcx> {
ty::Adt(def, _substs) => def.sized_constraint(tcx).0.is_empty(),
ty::Projection(_) | ty::Param(_) | ty::Opaque(..) => false,
ty::Alias(ty::Projection, _) | ty::Param(_) | ty::Alias(ty::Opaque, ..) => false,
ty::Infer(ty::TyVar(_)) => false,
@ -2259,9 +2262,9 @@ impl<'tcx> Ty<'tcx> {
ty::Generator(..) | ty::GeneratorWitness(..) => false,
// Might be, but not "trivial" so just giving the safe answer.
ty::Adt(..) | ty::Closure(..) | ty::Opaque(..) => false,
ty::Adt(..) | ty::Closure(..) | ty::Alias(ty::Opaque, ..) => false,
ty::Projection(..) | ty::Param(..) | ty::Infer(..) | ty::Error(..) => false,
ty::Alias(ty::Projection, ..) | ty::Param(..) | ty::Infer(..) | ty::Error(..) => false,
ty::Bound(..) | ty::Placeholder(..) => {
bug!("`is_trivially_pure_clone_copy` applied to unexpected type: {:?}", self);

View file

@ -259,7 +259,7 @@ impl<'tcx> TyCtxt<'tcx> {
ty::Tuple(_) => break,
ty::Projection(_) | ty::Opaque(..) => {
ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..) => {
let normalized = normalize(ty);
if ty == normalized {
return ty;
@ -332,8 +332,8 @@ impl<'tcx> TyCtxt<'tcx> {
break;
}
}
(ty::Projection(_) | ty::Opaque(..), _)
| (_, ty::Projection(_) | ty::Opaque(..)) => {
(ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..), _)
| (_, ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..)) => {
// If either side is a projection, attempt to
// progress via normalization. (Should be safe to
// apply to both sides as normalization is
@ -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(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)
@ -938,10 +938,10 @@ impl<'tcx> Ty<'tcx> {
| ty::Generator(..)
| ty::GeneratorWitness(_)
| ty::Infer(_)
| ty::Opaque(..)
| ty::Alias(ty::Opaque, ..)
| ty::Param(_)
| ty::Placeholder(_)
| ty::Projection(_) => false,
| ty::Alias(ty::Projection, _) => false,
}
}
@ -978,10 +978,10 @@ impl<'tcx> Ty<'tcx> {
| ty::Generator(..)
| ty::GeneratorWitness(_)
| ty::Infer(_)
| ty::Opaque(..)
| ty::Alias(ty::Opaque, ..)
| ty::Param(_)
| ty::Placeholder(_)
| ty::Projection(_) => false,
| ty::Alias(ty::Projection, _) => false,
}
}
@ -1101,8 +1101,8 @@ impl<'tcx> Ty<'tcx> {
//
// FIXME(ecstaticmorse): Maybe we should `bug` here? This should probably only be
// called for known, fully-monomorphized types.
ty::Projection(_)
| ty::Opaque(..)
ty::Alias(ty::Projection, _)
| ty::Alias(ty::Opaque, ..)
| ty::Param(_)
| ty::Bound(..)
| ty::Placeholder(_)
@ -1237,11 +1237,11 @@ pub fn needs_drop_components<'tcx>(
// These require checking for `Copy` bounds or `Adt` destructors.
ty::Adt(..)
| ty::Projection(..)
| ty::Alias(ty::Projection, ..)
| ty::Param(_)
| ty::Bound(..)
| ty::Placeholder(..)
| ty::Opaque(..)
| ty::Alias(ty::Opaque, ..)
| ty::Infer(_)
| ty::Closure(..)
| ty::Generator(..) => Ok(smallvec![ty]),
@ -1265,13 +1265,13 @@ pub fn is_trivially_const_drop<'tcx>(ty: Ty<'tcx>) -> bool {
| ty::Never
| ty::Foreign(_) => true,
ty::Opaque(..)
ty::Alias(ty::Opaque, ..)
| ty::Dynamic(..)
| ty::Error(_)
| ty::Bound(..)
| ty::Param(_)
| ty::Placeholder(_)
| ty::Projection(_)
| ty::Alias(ty::Projection, _)
| ty::Infer(_) => false,
// Not trivial because they have components, and instead of looking inside,

View file

@ -654,7 +654,7 @@ impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector {
// ignore the inputs to a projection, as they may not appear
// in the normalized form
if self.just_constrained {
if let ty::Projection(..) | ty::Opaque(..) = t.kind() {
if let ty::Alias(ty::Projection, ..) | ty::Alias(ty::Opaque, ..) = t.kind() {
return ControlFlow::CONTINUE;
}
}

View file

@ -165,7 +165,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>)
stack.push(ty.into());
stack.push(lt.into());
}
ty::Projection(data) => {
ty::Alias(ty::Projection, data) => {
stack.extend(data.substs.iter().rev());
}
ty::Dynamic(obj, lt, _) => {
@ -188,7 +188,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>)
}));
}
ty::Adt(_, substs)
| ty::Opaque(ty::AliasTy { def_id: _, substs })
| ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs })
| ty::Closure(_, substs)
| ty::Generator(_, substs, _)
| ty::FnDef(_, substs) => {

View file

@ -373,7 +373,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// the case of `!`, no return value is required, as the block will never return.
// Opaque types of empty bodies also need this unit assignment, in order to infer that their
// type is actually unit. Otherwise there will be no defining use found in the MIR.
if destination_ty.is_unit() || matches!(destination_ty.kind(), ty::Opaque(..)) {
if destination_ty.is_unit()
|| matches!(destination_ty.kind(), ty::Alias(ty::Opaque, ..))
{
// We only want to assign an implicit `()` as the return value of the block if the
// block does not diverge. (Otherwise, we may try to assign a unit to a `!`-type.)
this.cfg.push_assign_unit(block, source_info, destination, this.tcx);

View file

@ -121,7 +121,7 @@ impl<'tcx> ConstToPat<'tcx> {
ty::Dynamic(..) => {
"trait objects cannot be used in patterns".to_string()
}
ty::Opaque(..) => {
ty::Alias(ty::Opaque, ..) => {
"opaque types cannot be used in patterns".to_string()
}
ty::Closure(..) => {

View file

@ -845,7 +845,7 @@ fn is_useful<'p, 'tcx>(
// Opaque types can't get destructured/split, but the patterns can
// actually hint at hidden types, so we use the patterns' types instead.
if let ty::Opaque(..) = ty.kind() {
if let ty::Alias(ty::Opaque, ..) = ty.kind() {
if let Some(row) = rows.first() {
ty = row.head().ty();
}

View file

@ -849,7 +849,7 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
};
let kind = match parent_ty.ty.kind() {
&ty::Opaque(ty::AliasTy { def_id, substs }) => {
&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
self.tcx.bound_type_of(def_id).subst(self.tcx, substs).kind()
}
kind => kind,

View file

@ -52,7 +52,11 @@ impl<'tcx> MirPass<'tcx> for RemoveZsts {
fn maybe_zst(ty: Ty<'_>) -> bool {
match ty.kind() {
// maybe ZST (could be more precise)
ty::Adt(..) | ty::Array(..) | ty::Closure(..) | ty::Tuple(..) | ty::Opaque(..) => true,
ty::Adt(..)
| ty::Array(..)
| ty::Closure(..)
| ty::Tuple(..)
| ty::Alias(ty::Opaque, ..) => true,
// definitely ZST
ty::FnDef(..) | ty::Never => true,
// unreachable or can't be ZST

View file

@ -208,7 +208,7 @@ where
}
}
}
ty::Projection(proj) => {
ty::Alias(ty::Projection, proj) => {
if self.def_id_visitor.skip_assoc_tys() {
// Visitors searching for minimal visibility/reachability want to
// conservatively approximate associated types like `<Type as Trait>::Alias`
@ -235,7 +235,7 @@ where
self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref)?;
}
}
ty::Opaque(ty::AliasTy { def_id, substs: _ }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => {
// Skip repeated `Opaque`s to avoid infinite recursion.
if self.visited_opaque_tys.insert(def_id) {
// The intent is to treat `impl Trait1 + Trait2` identically to

View file

@ -216,8 +216,8 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
match *ty.kind() {
// Print all nominal types as paths (unlike `pretty_print_type`).
ty::FnDef(def_id, substs)
| ty::Opaque(ty::AliasTy { def_id, substs })
| ty::Projection(ty::AliasTy { def_id, substs })
| ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs })
| ty::Alias(ty::Projection, ty::AliasTy { def_id, substs })
| ty::Closure(def_id, substs)
| ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs),
@ -287,11 +287,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
// Similar to `pretty_path_qualified`, but for the other
// types that are printed as paths (see `print_type` above).
match self_ty.kind() {
ty::FnDef(..)
| ty::Opaque(..)
| ty::Projection(_)
| ty::Closure(..)
| ty::Generator(..)
ty::FnDef(..) | ty::Alias(..) | ty::Closure(..) | ty::Generator(..)
if trait_ref.is_none() =>
{
self.print_type(self_ty)

View file

@ -646,10 +646,10 @@ fn encode_ty<'tcx>(
| ty::Error(..)
| ty::GeneratorWitness(..)
| ty::Infer(..)
| ty::Opaque(..)
| ty::Alias(ty::Opaque, ..)
| ty::Param(..)
| ty::Placeholder(..)
| ty::Projection(..) => {
| ty::Alias(ty::Projection, ..) => {
bug!("encode_ty: unexpected `{:?}`", ty.kind());
}
};
@ -799,10 +799,10 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
| ty::Error(..)
| ty::GeneratorWitness(..)
| ty::Infer(..)
| ty::Opaque(..)
| ty::Alias(ty::Opaque, ..)
| ty::Param(..)
| ty::Placeholder(..)
| ty::Projection(..) => {
| ty::Alias(ty::Projection, ..) => {
bug!("transform_ty: unexpected `{:?}`", ty.kind());
}
}

View file

@ -439,8 +439,8 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
// Mangle all nominal types as paths.
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs)
| ty::FnDef(def_id, substs)
| ty::Opaque(ty::AliasTy { def_id, substs })
| ty::Projection(ty::AliasTy { def_id, substs })
| ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs })
| ty::Alias(ty::Projection, ty::AliasTy { def_id, substs })
| ty::Closure(def_id, substs)
| ty::Generator(def_id, substs, _) => {
self = self.print_def_path(def_id, substs)?;

View file

@ -579,14 +579,14 @@ impl<'tcx> AutoTraitFinder<'tcx> {
pub fn is_of_param(&self, ty: Ty<'_>) -> bool {
match ty.kind() {
ty::Param(_) => true,
ty::Projection(p) => self.is_of_param(p.self_ty()),
ty::Alias(ty::Projection, p) => self.is_of_param(p.self_ty()),
_ => false,
}
}
fn is_self_referential_projection(&self, p: ty::PolyProjectionPredicate<'_>) -> bool {
if let Some(ty) = p.term().skip_binder().ty() {
matches!(ty.kind(), ty::Projection(proj) if proj == &p.skip_binder().projection_ty)
matches!(ty.kind(), ty::Alias(ty::Projection, proj) if proj == &p.skip_binder().projection_ty)
} else {
false
}

View file

@ -659,7 +659,7 @@ impl<'tcx> TypeVisitor<'tcx> for OrphanChecker<'tcx> {
| ty::RawPtr(..)
| ty::Never
| ty::Tuple(..)
| ty::Projection(..) => self.found_non_local_ty(ty),
| ty::Alias(ty::Projection, ..) => self.found_non_local_ty(ty),
ty::Param(..) => self.found_param_ty(ty),
@ -704,7 +704,7 @@ impl<'tcx> TypeVisitor<'tcx> for OrphanChecker<'tcx> {
);
ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty))
}
ty::Opaque(..) => {
ty::Alias(ty::Opaque, ..) => {
// This merits some explanation.
// Normally, opaque types are not involved when performing
// coherence checking, since it is illegal to directly

View file

@ -1787,8 +1787,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
ty::Closure(..) => Some(9),
ty::Tuple(..) => Some(10),
ty::Param(..) => Some(11),
ty::Projection(..) => Some(12),
ty::Opaque(..) => Some(13),
ty::Alias(ty::Projection, ..) => Some(12),
ty::Alias(ty::Opaque, ..) => Some(13),
ty::Never => Some(14),
ty::Adt(..) => Some(15),
ty::Generator(..) => Some(16),

View file

@ -495,7 +495,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let self_ty = trait_pred.skip_binder().self_ty();
let (param_ty, projection) = match self_ty.kind() {
ty::Param(_) => (true, None),
ty::Projection(projection) => (false, Some(projection)),
ty::Alias(ty::Projection, projection) => (false, Some(projection)),
_ => (false, None),
};
@ -855,7 +855,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
fn_sig.inputs().map_bound(|inputs| &inputs[1..]),
))
}
ty::Opaque(ty::AliasTy { def_id, substs }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| {
if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder()
&& Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output()
@ -2644,7 +2644,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
Some(ident) => err.span_note(ident.span, &msg),
None => err.note(&msg),
},
ty::Opaque(ty::AliasTy { def_id, substs: _ }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => {
// Avoid printing the future from `core::future::identity_future`, it's not helpful
if tcx.parent(*def_id) == identity_future {
break 'print;
@ -3221,7 +3221,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let ocx = ObligationCtxt::new_in_snapshot(self.infcx);
for diff in &type_diffs {
let Sorts(expected_found) = diff else { continue; };
let ty::Projection(proj) = expected_found.expected.kind() else { continue; };
let ty::Alias(ty::Projection, proj) = expected_found.expected.kind() else { continue; };
let origin =
TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span };

View file

@ -794,13 +794,13 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeVisitable<'tcx>>(
ControlFlow::CONTINUE
}
}
ty::Projection(ref data)
ty::Alias(ty::Projection, ref data)
if self.tcx.def_kind(data.def_id) == DefKind::ImplTraitPlaceholder =>
{
// We'll deny these later in their own pass
ControlFlow::CONTINUE
}
ty::Projection(ref data) => {
ty::Alias(ty::Projection, ref data) => {
// This is a projected type `<Foo as SomeTrait>::X`.
// Compute supertraits of current trait lazily.
@ -861,7 +861,7 @@ pub fn contains_illegal_impl_trait_in_trait<'tcx>(
// FIXME(RPITIT): Perhaps we should use a visitor here?
ty.skip_binder().walk().find_map(|arg| {
if let ty::GenericArgKind::Type(ty) = arg.unpack()
&& let ty::Projection(proj) = ty.kind()
&& let ty::Alias(ty::Projection, proj) = ty.kind()
&& tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder
{
Some(MethodViolationCode::ReferencesImplTraitInTrait(tcx.def_span(proj.def_id)))

View file

@ -496,7 +496,9 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
// This is really important. While we *can* handle this, this has
// severe performance implications for large opaque types with
// late-bound regions. See `issue-88862` benchmark.
ty::Opaque(ty::AliasTy { def_id, substs }) if !substs.has_escaping_bound_vars() => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs })
if !substs.has_escaping_bound_vars() =>
{
// Only normalize `impl Trait` outside of type inference, usually in codegen.
match self.param_env.reveal() {
Reveal::UserFacing => ty.super_fold_with(self),
@ -523,7 +525,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
}
}
ty::Projection(data) if !data.has_escaping_bound_vars() => {
ty::Alias(ty::Projection, data) if !data.has_escaping_bound_vars() => {
// This branch is *mostly* just an optimization: when we don't
// have escaping bound vars, we don't need to replace them with
// placeholders (see branch below). *Also*, we know that we can
@ -562,7 +564,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
normalized_ty.ty().unwrap()
}
ty::Projection(data) => {
ty::Alias(ty::Projection, data) => {
// If there are escaping bound vars, we temporarily replace the
// bound vars with placeholders. Note though, that in the case
// that we still can't project for whatever reason (e.g. self
@ -1375,8 +1377,10 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>(
// Check whether the self-type is itself a projection.
// If so, extract what we know from the trait and try to come up with a good answer.
let bounds = match *obligation.predicate.self_ty().kind() {
ty::Projection(ref data) => tcx.bound_item_bounds(data.def_id).subst(tcx, data.substs),
ty::Opaque(ty::AliasTy { def_id, substs }) => {
ty::Alias(ty::Projection, ref data) => {
tcx.bound_item_bounds(data.def_id).subst(tcx, data.substs)
}
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
tcx.bound_item_bounds(def_id).subst(tcx, substs)
}
ty::Infer(ty::TyVar(_)) => {
@ -1616,8 +1620,8 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
// type parameters, opaques, and unnormalized projections have pointer
// metadata if they're known (e.g. by the param_env) to be sized
ty::Param(_)
| ty::Projection(..)
| ty::Opaque(..)
| ty::Alias(ty::Projection, ..)
| ty::Alias(ty::Opaque, ..)
| ty::Bound(..)
| ty::Placeholder(..)
| ty::Infer(..)
@ -1671,7 +1675,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
// type parameters, opaques, and unnormalized projections have pointer
// metadata if they're known (e.g. by the param_env) to be sized
ty::Param(_) | ty::Projection(..) | ty::Opaque(..)
ty::Param(_) | ty::Alias(ty::Projection, ..) | ty::Alias(ty::Opaque, ..)
if selcx.infcx.predicate_must_hold_modulo_regions(
&obligation.with(
selcx.tcx(),
@ -1687,8 +1691,8 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
// FIXME(compiler-errors): are Bound and Placeholder types ever known sized?
ty::Param(_)
| ty::Projection(..)
| ty::Opaque(..)
| ty::Alias(ty::Projection, ..)
| ty::Alias(ty::Opaque, ..)
| ty::Bound(..)
| ty::Placeholder(..)
| ty::Infer(..)

View file

@ -62,9 +62,9 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
// The following *might* require a destructor: needs deeper inspection.
ty::Dynamic(..)
| ty::Projection(..)
| ty::Alias(ty::Projection, ..)
| ty::Param(_)
| ty::Opaque(..)
| ty::Alias(ty::Opaque, ..)
| ty::Placeholder(..)
| ty::Infer(_)
| ty::Bound(..)

View file

@ -205,7 +205,9 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
// This is really important. While we *can* handle this, this has
// severe performance implications for large opaque types with
// late-bound regions. See `issue-88862` benchmark.
ty::Opaque(ty::AliasTy { def_id, substs }) if !substs.has_escaping_bound_vars() => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs })
if !substs.has_escaping_bound_vars() =>
{
// Only normalize `impl Trait` outside of type inference, usually in codegen.
match self.param_env.reveal() {
Reveal::UserFacing => ty.try_super_fold_with(self),
@ -242,7 +244,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
}
}
ty::Projection(data) if !data.has_escaping_bound_vars() => {
ty::Alias(ty::Projection, data) if !data.has_escaping_bound_vars() => {
// This branch is just an optimization: when we don't have escaping bound vars,
// we don't need to replace them with placeholders (see branch below).
@ -291,7 +293,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
}
}
ty::Projection(data) => {
ty::Alias(ty::Projection, data) => {
// See note in `rustc_trait_selection::traits::project`
let tcx = self.infcx.tcx;

View file

@ -138,7 +138,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// Before we go into the whole placeholder thing, just
// quickly check if the self-type is a projection at all.
match obligation.predicate.skip_binder().trait_ref.self_ty().kind() {
ty::Projection(_) | ty::Opaque(..) => {}
ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..) => {}
ty::Infer(ty::TyVar(_)) => {
span_bug!(
obligation.cause.span,
@ -394,7 +394,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// still be provided by a manual implementation for
// this trait and type.
}
ty::Param(..) | ty::Projection(..) => {
ty::Param(..) | ty::Alias(ty::Projection, ..) => {
// In these cases, we don't know what the actual
// type is. Therefore, we cannot break it down
// into its constituent types. So we don't
@ -734,13 +734,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let self_ty = self.infcx.shallow_resolve(obligation.self_ty());
match self_ty.skip_binder().kind() {
ty::Opaque(..)
ty::Alias(ty::Opaque, ..)
| ty::Dynamic(..)
| ty::Error(_)
| ty::Bound(..)
| ty::Param(_)
| ty::Placeholder(_)
| ty::Projection(_) => {
| ty::Alias(ty::Projection, _) => {
// We don't know if these are `~const Destruct`, at least
// not structurally... so don't push a candidate.
}
@ -826,8 +826,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| ty::Generator(_, _, _)
| ty::GeneratorWitness(_)
| ty::Never
| ty::Projection(_)
| ty::Opaque(ty::AliasTy { def_id: _, substs: _ })
| ty::Alias(ty::Projection, _)
| ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs: _ })
| ty::Param(_)
| ty::Bound(_, _)
| ty::Error(_)

View file

@ -155,8 +155,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let placeholder_self_ty = placeholder_trait_predicate.self_ty();
let placeholder_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate);
let (def_id, substs) = match *placeholder_self_ty.kind() {
ty::Projection(proj) => (proj.def_id, proj.substs),
ty::Opaque(ty::AliasTy { def_id, substs }) => (def_id, substs),
ty::Alias(ty::Projection, proj) => (proj.def_id, proj.substs),
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => (def_id, substs),
_ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty),
};
@ -184,7 +184,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
.map_err(|_| Unimplemented)
})?);
if let ty::Projection(..) = placeholder_self_ty.kind() {
if let ty::Alias(ty::Projection, ..) = placeholder_self_ty.kind() {
let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, substs).predicates;
debug!(?predicates, "projection predicates");
for predicate in predicates {
@ -1279,7 +1279,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// If we have a projection type, make sure to normalize it so we replace it
// with a fresh infer variable
ty::Projection(..) => {
ty::Alias(ty::Projection, ..) => {
let predicate = normalize_with_depth_to(
self,
obligation.param_env,

View file

@ -1595,8 +1595,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let tcx = self.infcx.tcx;
let (def_id, substs) = match *placeholder_trait_predicate.trait_ref.self_ty().kind() {
ty::Projection(ref data) => (data.def_id, data.substs),
ty::Opaque(ty::AliasTy { def_id, substs }) => (def_id, substs),
ty::Alias(ty::Projection, ref data) => (data.def_id, data.substs),
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => (def_id, substs),
_ => {
span_bug!(
obligation.cause.span,
@ -2067,7 +2067,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}))
}
ty::Projection(_) | ty::Param(_) | ty::Opaque(..) => None,
ty::Alias(ty::Projection, _) | ty::Param(_) | ty::Alias(ty::Opaque, ..) => None,
ty::Infer(ty::TyVar(_)) => Ambiguous,
ty::Placeholder(..)
@ -2167,7 +2167,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
}
ty::Adt(..) | ty::Projection(..) | ty::Param(..) | ty::Opaque(..) => {
ty::Adt(..)
| ty::Alias(ty::Projection, ..)
| ty::Param(..)
| ty::Alias(ty::Opaque, ..) => {
// Fallback to whatever user-defined impls exist in this case.
None
}
@ -2220,7 +2223,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| ty::Dynamic(..)
| ty::Param(..)
| ty::Foreign(..)
| ty::Projection(..)
| ty::Alias(ty::Projection, ..)
| ty::Bound(..)
| ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
bug!("asked to assemble constituent types of unexpected type: {:?}", t);
@ -2260,7 +2263,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
t.rebind(def.all_fields().map(|f| f.ty(self.tcx(), substs)).collect())
}
ty::Opaque(ty::AliasTy { def_id, substs }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
// We can resolve the `impl Trait` to its concrete type,
// which enforces a DAG between the functions requiring
// the auto trait bounds in question.

View file

@ -95,10 +95,10 @@ impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> {
ty::Foreign(_) => {
return ControlFlow::Break(ty);
}
ty::Opaque(..) => {
ty::Alias(ty::Opaque, ..) => {
return ControlFlow::Break(ty);
}
ty::Projection(..) => {
ty::Alias(ty::Projection, ..) => {
return ControlFlow::Break(ty);
}
ty::Closure(..) => {

View file

@ -234,7 +234,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
// projection coming from another associated type. See
// `src/test/ui/associated-types/point-at-type-on-obligation-failure.rs` and
// `traits-assoc-type-in-supertrait-bad.rs`.
if let Some(ty::Projection(projection_ty)) = proj.term.ty().map(|ty| ty.kind())
if let Some(ty::Alias(ty::Projection, projection_ty)) = proj.term.ty().map(|ty| ty.kind())
&& let Some(&impl_item_id) =
tcx.impl_item_implementor_ids(impl_def_id).get(&projection_ty.def_id)
&& let Some(impl_item_span) = items
@ -249,7 +249,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
// An associated item obligation born out of the `trait` failed to be met. An example
// can be seen in `ui/associated-types/point-at-type-on-obligation-failure-2.rs`.
debug!("extended_cause_with_original_assoc_item_obligation trait proj {:?}", pred);
if let ty::Projection(ty::AliasTy { def_id, .. }) = *pred.self_ty().kind()
if let ty::Alias(ty::Projection, ty::AliasTy { def_id, .. }) = *pred.self_ty().kind()
&& let Some(&impl_item_id) =
tcx.impl_item_implementor_ids(impl_def_id).get(&def_id)
&& let Some(impl_item_span) = items
@ -556,7 +556,7 @@ impl<'tcx> WfPredicates<'tcx> {
// Simple cases that are WF if their type args are WF.
}
ty::Projection(data) => {
ty::Alias(ty::Projection, data) => {
walker.skip_current_subtree(); // Subtree handled by compute_projection.
self.compute_projection(data);
}
@ -648,7 +648,7 @@ impl<'tcx> WfPredicates<'tcx> {
// types appearing in the fn signature
}
ty::Opaque(ty::AliasTy { def_id, substs }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
// All of the requirements on type parameters
// have already been checked for `impl Trait` in
// return position. We do need to check type-alias-impl-trait though.

View file

@ -432,9 +432,10 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
(ast::Mutability::Not, chalk_ir::Mutability::Not) => true,
}
}
(&ty::Opaque(ty::AliasTy { def_id, substs: _ }), OpaqueType(opaque_ty_id, ..)) => {
def_id == opaque_ty_id.0
}
(
&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }),
OpaqueType(opaque_ty_id, ..),
) => def_id == opaque_ty_id.0,
(&ty::FnDef(def_id, ..), FnDef(fn_def_id, ..)) => def_id == fn_def_id.0,
(&ty::Str, Str) => true,
(&ty::Never, Never) => true,
@ -788,7 +789,7 @@ impl<'tcx> ty::TypeFolder<'tcx> for ReplaceOpaqueTyFolder<'tcx> {
}
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
if let ty::Opaque(ty::AliasTy { def_id, substs }) = *ty.kind() {
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) = *ty.kind() {
if def_id == self.opaque_ty_id.0 && substs == self.identity_substs {
return self.tcx.mk_ty(ty::Bound(
self.binder_index,

View file

@ -353,8 +353,8 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
ty::Tuple(types) => {
chalk_ir::TyKind::Tuple(types.len(), types.as_substs().lower_into(interner))
}
ty::Projection(proj) => chalk_ir::TyKind::Alias(proj.lower_into(interner)),
ty::Opaque(ty::AliasTy { def_id, substs }) => {
ty::Alias(ty::Projection, proj) => chalk_ir::TyKind::Alias(proj.lower_into(interner)),
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy {
opaque_ty_id: chalk_ir::OpaqueTyId(def_id),
substitution: substs.lower_into(interner),
@ -442,14 +442,14 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
mutbl.lower_into(interner),
),
TyKind::Str => ty::Str,
TyKind::OpaqueType(opaque_ty, substitution) => ty::Opaque(ty::AliasTy {
def_id: opaque_ty.0,
substs: substitution.lower_into(interner),
}),
TyKind::AssociatedType(assoc_ty, substitution) => ty::Projection(ty::AliasTy {
substs: substitution.lower_into(interner),
def_id: assoc_ty.0,
}),
TyKind::OpaqueType(opaque_ty, substitution) => ty::Alias(
ty::Opaque,
ty::AliasTy { def_id: opaque_ty.0, substs: substitution.lower_into(interner) },
),
TyKind::AssociatedType(assoc_ty, substitution) => ty::Alias(
ty::Projection,
ty::AliasTy { substs: substitution.lower_into(interner), def_id: assoc_ty.0 },
),
TyKind::Foreign(def_id) => ty::Foreign(def_id.0),
TyKind::Error => return interner.tcx.ty_error(),
TyKind::Placeholder(placeholder) => ty::Placeholder(ty::Placeholder {
@ -457,14 +457,20 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
name: ty::BoundVar::from_usize(placeholder.idx),
}),
TyKind::Alias(alias_ty) => match alias_ty {
chalk_ir::AliasTy::Projection(projection) => ty::Projection(ty::AliasTy {
def_id: projection.associated_ty_id.0,
substs: projection.substitution.lower_into(interner),
}),
chalk_ir::AliasTy::Opaque(opaque) => ty::Opaque(ty::AliasTy {
def_id: opaque.opaque_ty_id.0,
substs: opaque.substitution.lower_into(interner),
}),
chalk_ir::AliasTy::Projection(projection) => ty::Alias(
ty::Projection,
ty::AliasTy {
def_id: projection.associated_ty_id.0,
substs: projection.substitution.lower_into(interner),
},
),
chalk_ir::AliasTy::Opaque(opaque) => ty::Alias(
ty::Opaque,
ty::AliasTy {
def_id: opaque.opaque_ty_id.0,
substs: opaque.substitution.lower_into(interner),
},
),
},
TyKind::Function(_quantified_ty) => unimplemented!(),
TyKind::BoundVar(_bound) => ty::Bound(

View file

@ -112,7 +112,7 @@ fn dropck_outlives<'tcx>(
// A projection that we couldn't resolve - it
// might have a destructor.
ty::Projection(..) | ty::Opaque(..) => {
ty::Alias(ty::Projection, ..) | ty::Alias(ty::Opaque, ..) => {
result.kinds.push(ty.into());
}
@ -268,7 +268,7 @@ fn dtorck_constraint_for_ty<'tcx>(
}
// Types that can't be resolved. Pass them forward.
ty::Projection(..) | ty::Opaque(..) | ty::Param(..) => {
ty::Alias(ty::Projection, ..) | ty::Alias(ty::Opaque, ..) | ty::Param(..) => {
constraints.dtorck_types.push(ty);
}

View file

@ -444,7 +444,7 @@ fn layout_of_uncached<'tcx>(
}
// Types with no meaningful known layout.
ty::Projection(_) | ty::Opaque(..) => {
ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..) => {
// NOTE(eddyb) `layout_of` query should've normalized these away,
// if that was possible, so there's no reason to try again here.
return Err(LayoutError::Unknown(ty));

View file

@ -152,7 +152,10 @@ where
queue_type(self, required);
}
}
ty::Array(..) | ty::Opaque(..) | ty::Projection(..) | ty::Param(_) => {
ty::Array(..)
| ty::Alias(ty::Opaque, ..)
| ty::Alias(ty::Projection, ..)
| ty::Param(_) => {
if ty == component {
// Return the type to the caller: they may be able
// to normalize further than we can.

View file

@ -37,7 +37,7 @@ fn sized_constraint_for_ty<'tcx>(
.collect()
}
Projection(..) | Opaque(..) => {
Alias(..) => {
// must calculate explicitly.
// FIXME: consider special-casing always-Sized projections
vec![ty]

View file

@ -42,9 +42,8 @@ pub trait Interner {
type ListBinderExistentialPredicate: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
type BinderListTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
type ListTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
type ProjectionTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
type AliasTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
type ParamTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
type OpaqueTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
type BoundTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
type PlaceholderType: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
type InferTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;

View file

@ -19,19 +19,8 @@ use rustc_data_structures::stable_hasher::HashStable;
use rustc_serialize::{Decodable, Decoder, Encodable};
/// Specifies how a trait object is represented.
#[derive(
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Debug,
Encodable,
Decodable,
HashStable_Generic
)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Encodable, Decodable, HashStable_Generic)]
pub enum DynKind {
/// An unsized `dyn Trait` object
Dyn,
@ -46,6 +35,13 @@ pub enum DynKind {
DynStar,
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(Encodable, Decodable, HashStable_Generic)]
pub enum AliasKind {
Projection,
Opaque,
}
/// Defines the kinds of types used by the type system.
///
/// Types written by the user start out as `hir::TyKind` and get
@ -171,19 +167,7 @@ pub enum TyKind<I: Interner> {
Tuple(I::ListTy),
/// A projection or opaque type. Both of these types
Projection(I::ProjectionTy),
/// Opaque (`impl Trait`) type found in a return type.
///
/// The `DefId` comes either from
/// * the `impl Trait` ast::Ty node,
/// * or the `type Foo = impl Trait` declaration
///
/// For RPIT the substitutions are for the generics of the function,
/// while for TAIT it is used for the generic parameters of the alias.
///
/// During codegen, `tcx.type_of(def_id)` can be used to get the underlying type.
Opaque(I::OpaqueTy),
Alias(AliasKind, I::AliasTy),
/// A type parameter; for example, `T` in `fn f<T>(x: T) {}`.
Param(I::ParamTy),
@ -251,13 +235,12 @@ const fn tykind_discriminant<I: Interner>(value: &TyKind<I>) -> usize {
GeneratorWitness(_) => 17,
Never => 18,
Tuple(_) => 19,
Projection(_) => 20,
Opaque(_) => 21,
Param(_) => 22,
Bound(_, _) => 23,
Placeholder(_) => 24,
Infer(_) => 25,
Error(_) => 26,
Alias(_, _) => 20,
Param(_) => 21,
Bound(_, _) => 22,
Placeholder(_) => 23,
Infer(_) => 24,
Error(_) => 25,
}
}
@ -285,8 +268,7 @@ impl<I: Interner> Clone for TyKind<I> {
GeneratorWitness(g) => GeneratorWitness(g.clone()),
Never => Never,
Tuple(t) => Tuple(t.clone()),
Projection(p) => Projection(p.clone()),
Opaque(o) => Opaque(o.clone()),
Alias(k, p) => Alias(*k, p.clone()),
Param(p) => Param(p.clone()),
Bound(d, b) => Bound(d.clone(), b.clone()),
Placeholder(p) => Placeholder(p.clone()),
@ -322,8 +304,7 @@ impl<I: Interner> PartialEq for TyKind<I> {
}
(GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g == b_g,
(Tuple(a_t), Tuple(b_t)) => a_t == b_t,
(Projection(a_p), Projection(b_p)) => a_p == b_p,
(Opaque(a_o), Opaque(b_o)) => a_o == b_o,
(Alias(a_i, a_p), Alias(b_i, b_p)) => a_i == b_i && a_p == b_p,
(Param(a_p), Param(b_p)) => a_p == b_p,
(Bound(a_d, a_b), Bound(b_d, b_b)) => a_d == b_d && a_b == b_b,
(Placeholder(a_p), Placeholder(b_p)) => a_p == b_p,
@ -380,8 +361,7 @@ impl<I: Interner> Ord for TyKind<I> {
}
(GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g.cmp(b_g),
(Tuple(a_t), Tuple(b_t)) => a_t.cmp(b_t),
(Projection(a_p), Projection(b_p)) => a_p.cmp(b_p),
(Opaque(a_o), Opaque(b_o)) => a_o.cmp(b_o),
(Alias(a_i, a_p), Alias(b_i, b_p)) => a_i.cmp(b_i).then_with(|| a_p.cmp(b_p)),
(Param(a_p), Param(b_p)) => a_p.cmp(b_p),
(Bound(a_d, a_b), Bound(b_d, b_b)) => a_d.cmp(b_d).then_with(|| a_b.cmp(b_b)),
(Placeholder(a_p), Placeholder(b_p)) => a_p.cmp(b_p),
@ -442,9 +422,9 @@ impl<I: Interner> hash::Hash for TyKind<I> {
}
GeneratorWitness(g) => g.hash(state),
Tuple(t) => t.hash(state),
Projection(p) => p.hash(state),
Opaque(o) => {
o.hash(state);
Alias(i, p) => {
i.hash(state);
p.hash(state);
}
Param(p) => p.hash(state),
Bound(d, b) => {
@ -483,8 +463,7 @@ impl<I: Interner> fmt::Debug for TyKind<I> {
GeneratorWitness(g) => f.debug_tuple_field1_finish("GeneratorWitness", g),
Never => f.write_str("Never"),
Tuple(t) => f.debug_tuple_field1_finish("Tuple", t),
Projection(p) => f.debug_tuple_field1_finish("Projection", p),
Opaque(o) => f.debug_tuple_field1_finish("Opaque", o),
Alias(i, a) => f.debug_tuple_field2_finish("Alias", i, a),
Param(p) => f.debug_tuple_field1_finish("Param", p),
Bound(d, b) => f.debug_tuple_field2_finish("Bound", d, b),
Placeholder(p) => f.debug_tuple_field1_finish("Placeholder", p),
@ -511,9 +490,8 @@ where
I::ListBinderExistentialPredicate: Encodable<E>,
I::BinderListTy: Encodable<E>,
I::ListTy: Encodable<E>,
I::ProjectionTy: Encodable<E>,
I::AliasTy: Encodable<E>,
I::ParamTy: Encodable<E>,
I::OpaqueTy: Encodable<E>,
I::BoundTy: Encodable<E>,
I::PlaceholderType: Encodable<E>,
I::InferTy: Encodable<E>,
@ -585,12 +563,10 @@ where
Tuple(substs) => e.emit_enum_variant(disc, |e| {
substs.encode(e);
}),
Projection(p) => e.emit_enum_variant(disc, |e| {
Alias(k, p) => e.emit_enum_variant(disc, |e| {
k.encode(e);
p.encode(e);
}),
Opaque(o) => e.emit_enum_variant(disc, |e| {
o.encode(e);
}),
Param(p) => e.emit_enum_variant(disc, |e| {
p.encode(e);
}),
@ -628,9 +604,9 @@ where
I::ListBinderExistentialPredicate: Decodable<D>,
I::BinderListTy: Decodable<D>,
I::ListTy: Decodable<D>,
I::ProjectionTy: Decodable<D>,
I::AliasTy: Decodable<D>,
I::ParamTy: Decodable<D>,
I::OpaqueTy: Decodable<D>,
I::AliasTy: Decodable<D>,
I::BoundTy: Decodable<D>,
I::PlaceholderType: Decodable<D>,
I::InferTy: Decodable<D>,
@ -659,8 +635,7 @@ where
17 => GeneratorWitness(Decodable::decode(d)),
18 => Never,
19 => Tuple(Decodable::decode(d)),
20 => Projection(Decodable::decode(d)),
21 => Opaque(Decodable::decode(d)),
20 => Alias(Decodable::decode(d), Decodable::decode(d)),
22 => Param(Decodable::decode(d)),
23 => Bound(Decodable::decode(d), Decodable::decode(d)),
24 => Placeholder(Decodable::decode(d)),
@ -694,10 +669,9 @@ where
I::Mutability: HashStable<CTX>,
I::BinderListTy: HashStable<CTX>,
I::ListTy: HashStable<CTX>,
I::ProjectionTy: HashStable<CTX>,
I::AliasTy: HashStable<CTX>,
I::BoundTy: HashStable<CTX>,
I::ParamTy: HashStable<CTX>,
I::OpaqueTy: HashStable<CTX>,
I::PlaceholderType: HashStable<CTX>,
I::InferTy: HashStable<CTX>,
I::ErrorGuaranteed: HashStable<CTX>,
@ -772,12 +746,10 @@ where
Tuple(substs) => {
substs.hash_stable(__hcx, __hasher);
}
Projection(p) => {
Alias(k, p) => {
k.hash_stable(__hcx, __hasher);
p.hash_stable(__hcx, __hasher);
}
Opaque(o) => {
o.hash_stable(__hcx, __hasher);
}
Param(p) => {
p.hash_stable(__hcx, __hasher);
}

View file

@ -1487,7 +1487,9 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
hir::QPath::TypeRelative(qself, segment) => {
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
let res = match ty.kind() {
ty::Projection(proj) => Res::Def(DefKind::Trait, proj.trait_ref(cx.tcx).def_id),
ty::Alias(ty::Projection, proj) => {
Res::Def(DefKind::Trait, proj.trait_ref(cx.tcx).def_id)
}
// Rustdoc handles `ty::Error`s by turning them into `Type::Infer`s.
ty::Error(_) => return Type::Infer,
// Otherwise, this is an inherent associated type.
@ -1823,7 +1825,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
Tuple(t.iter().map(|t| clean_middle_ty(bound_ty.rebind(t), cx, None)).collect())
}
ty::Projection(ref data) => clean_projection(bound_ty.rebind(*data), cx, def_id),
ty::Alias(ty::Projection, ref data) => clean_projection(bound_ty.rebind(*data), cx, def_id),
ty::Param(ref p) => {
if let Some(bounds) = cx.impl_trait_bounds.remove(&p.index.into()) {
@ -1833,7 +1835,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
}
}
ty::Opaque(ty::AliasTy { def_id, substs }) => {
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
// by looking up the bounds associated with the def_id.
let bounds = cx

View file

@ -538,11 +538,10 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did, .. }, _)), _) | ty::Foreign(did) => {
Res::from_def_id(self.cx.tcx, did)
}
ty::Projection(_)
ty::Alias(..)
| ty::Closure(..)
| ty::Generator(..)
| ty::GeneratorWitness(_)
| ty::Opaque(..)
| ty::Dynamic(..)
| ty::Param(_)
| ty::Bound(..)

View file

@ -33,8 +33,7 @@ fn main() {
TyKind::GeneratorWitness(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
TyKind::Never => (), //~ ERROR usage of `ty::TyKind::<kind>`
TyKind::Tuple(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
TyKind::Projection(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
TyKind::Opaque(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
TyKind::Alias(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
TyKind::Param(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
TyKind::Bound(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
TyKind::Placeholder(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`

View file

@ -133,53 +133,47 @@ LL | TyKind::Tuple(..) => (),
error: usage of `ty::TyKind::<kind>`
--> $DIR/ty_tykind_usage.rs:36:9
|
LL | TyKind::Projection(..) => (),
LL | TyKind::Alias(..) => (),
| ^^^^^^ help: try using `ty::<kind>` directly: `ty`
error: usage of `ty::TyKind::<kind>`
--> $DIR/ty_tykind_usage.rs:37:9
|
LL | TyKind::Opaque(..) => (),
LL | TyKind::Param(..) => (),
| ^^^^^^ help: try using `ty::<kind>` directly: `ty`
error: usage of `ty::TyKind::<kind>`
--> $DIR/ty_tykind_usage.rs:38:9
|
LL | TyKind::Param(..) => (),
LL | TyKind::Bound(..) => (),
| ^^^^^^ help: try using `ty::<kind>` directly: `ty`
error: usage of `ty::TyKind::<kind>`
--> $DIR/ty_tykind_usage.rs:39:9
|
LL | TyKind::Bound(..) => (),
LL | TyKind::Placeholder(..) => (),
| ^^^^^^ help: try using `ty::<kind>` directly: `ty`
error: usage of `ty::TyKind::<kind>`
--> $DIR/ty_tykind_usage.rs:40:9
|
LL | TyKind::Placeholder(..) => (),
LL | TyKind::Infer(..) => (),
| ^^^^^^ help: try using `ty::<kind>` directly: `ty`
error: usage of `ty::TyKind::<kind>`
--> $DIR/ty_tykind_usage.rs:41:9
|
LL | TyKind::Infer(..) => (),
| ^^^^^^ help: try using `ty::<kind>` directly: `ty`
error: usage of `ty::TyKind::<kind>`
--> $DIR/ty_tykind_usage.rs:42:9
|
LL | TyKind::Error(_) => (),
| ^^^^^^ help: try using `ty::<kind>` directly: `ty`
error: usage of `ty::TyKind::<kind>`
--> $DIR/ty_tykind_usage.rs:47:12
--> $DIR/ty_tykind_usage.rs:46:12
|
LL | if let TyKind::Int(int_ty) = kind {}
| ^^^^^^ help: try using `ty::<kind>` directly: `ty`
error: usage of `ty::TyKind`
--> $DIR/ty_tykind_usage.rs:49:24
--> $DIR/ty_tykind_usage.rs:48:24
|
LL | fn ty_kind(ty_bad: TyKind<'_>, ty_good: Ty<'_>) {}
| ^^^^^^^^^^
@ -187,7 +181,7 @@ LL | fn ty_kind(ty_bad: TyKind<'_>, ty_good: Ty<'_>) {}
= help: try using `Ty` instead
error: usage of `ty::TyKind`
--> $DIR/ty_tykind_usage.rs:51:37
--> $DIR/ty_tykind_usage.rs:50:37
|
LL | fn ir_ty_kind<I: Interner>(bad: IrTyKind<I>) -> IrTyKind<I> {
| ^^^^^^^^^^^
@ -195,7 +189,7 @@ LL | fn ir_ty_kind<I: Interner>(bad: IrTyKind<I>) -> IrTyKind<I> {
= help: try using `Ty` instead
error: usage of `ty::TyKind`
--> $DIR/ty_tykind_usage.rs:51:53
--> $DIR/ty_tykind_usage.rs:50:53
|
LL | fn ir_ty_kind<I: Interner>(bad: IrTyKind<I>) -> IrTyKind<I> {
| ^^^^^^^^^^^
@ -203,12 +197,12 @@ LL | fn ir_ty_kind<I: Interner>(bad: IrTyKind<I>) -> IrTyKind<I> {
= help: try using `Ty` instead
error: usage of `ty::TyKind::<kind>`
--> $DIR/ty_tykind_usage.rs:54:9
--> $DIR/ty_tykind_usage.rs:53:9
|
LL | IrTyKind::Bool
| --------^^^^^^
| |
| help: try using `ty::<kind>` directly: `ty`
error: aborting due to 33 previous errors
error: aborting due to 32 previous errors

View file

@ -1244,7 +1244,7 @@ fn is_mixed_projection_predicate<'tcx>(
let mut projection_ty = projection_predicate.projection_ty;
loop {
match projection_ty.self_ty().kind() {
ty::Projection(inner_projection_ty) => {
ty::Alias(ty::Projection, inner_projection_ty) => {
projection_ty = *inner_projection_ty;
}
ty::Param(param_ty) => {
@ -1390,8 +1390,8 @@ fn ty_auto_deref_stability<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, precedenc
continue;
},
ty::Param(_) => TyPosition::new_deref_stable_for_result(precedence, ty),
ty::Projection(_) if ty.has_non_region_param() => TyPosition::new_deref_stable_for_result(precedence, ty),
ty::Infer(_) | ty::Error(_) | ty::Bound(..) | ty::Opaque(..) | ty::Placeholder(_) | ty::Dynamic(..) => {
ty::Alias(ty::Projection, _) if ty.has_non_region_param() => TyPosition::new_deref_stable_for_result(precedence, ty),
ty::Infer(_) | ty::Error(_) | ty::Bound(..) | ty::Alias(ty::Opaque, ..) | ty::Placeholder(_) | ty::Dynamic(..) => {
Position::ReborrowStable(precedence).into()
},
ty::Adt(..) if ty.has_placeholders() || ty.has_opaque_types() => {
@ -1417,7 +1417,7 @@ fn ty_auto_deref_stability<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, precedenc
| ty::Closure(..)
| ty::Never
| ty::Tuple(_)
| ty::Projection(_) => {
| ty::Alias(ty::Projection, _) => {
Position::DerefStable(precedence, ty.is_sized(cx.tcx, cx.param_env.without_caller_bounds())).into()
},
};

Some files were not shown because too many files have changed in this diff Show more