Auto merge of #104986 - compiler-errors:opaques, r=oli-obk

Combine `ty::Projection` and `ty::Opaque` into `ty::Alias`

Implements https://github.com/rust-lang/types-team/issues/79.

This PR consolidates `ty::Projection` and `ty::Opaque` into a single `ty::Alias`, with an `AliasKind` and `AliasTy` type (renamed from `ty::ProjectionTy`, which is the inner data of `ty::Projection`) defined as so:

```
enum AliasKind {
  Projection,
  Opaque,
}

struct AliasTy<'tcx> {
  def_id: DefId,
  substs: SubstsRef<'tcx>,
}
```

Since we don't have access to `TyCtxt` in type flags computation, and because repeatedly calling `DefKind` on the def-id is expensive, these two types are distinguished with `ty::AliasKind`, conveniently glob-imported into `ty::{Projection, Opaque}`. For example:

```diff
  match ty.kind() {
-   ty::Opaque(..) =>
+   ty::Alias(ty::Opaque, ..) => {}
    _ => {}
  }
```

This PR also consolidates match arms that treated `ty::Opaque` and `ty::Projection` identically.

r? `@ghost`
This commit is contained in:
bors 2022-12-14 01:19:24 +00:00
commit 918d0ac38e
115 changed files with 632 additions and 674 deletions

View file

@ -849,7 +849,7 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
};
let kind = match parent_ty.ty.kind() {
&ty::Opaque(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