about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-05-26 20:22:28 -0700
committerMichael Goulet <michael@errs.io>2022-05-28 11:38:22 -0700
commit34e05812e029206add91fa39df86765fcb3f8b5a (patch)
treefc2d0bfaf18186b591d68aa830c54026df9316b9
parenta056a953f00d7b78d12dc192b34c47cca6fa7b6b (diff)
downloadrust-34e05812e029206add91fa39df86765fcb3f8b5a.tar.gz
rust-34e05812e029206add91fa39df86765fcb3f8b5a.zip
Fix TyKind lint, make consts no longer fn, etc
-rw-r--r--compiler/rustc_borrowck/src/lib.rs8
-rw-r--r--compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs4
-rw-r--r--compiler/rustc_const_eval/src/interpret/traits.rs10
-rw-r--r--compiler/rustc_lint/src/internal.rs191
-rw-r--r--compiler/rustc_middle/src/ty/context.rs2
-rw-r--r--compiler/rustc_middle/src/ty/fast_reject.rs8
-rw-r--r--compiler/rustc_middle/src/ty/mod.rs8
-rw-r--r--compiler/rustc_middle/src/ty/sty.rs204
-rw-r--r--compiler/rustc_middle/src/ty/vtable.rs8
-rw-r--r--compiler/rustc_span/src/symbol.rs1
-rw-r--r--compiler/rustc_trait_selection/src/traits/mod.rs8
-rw-r--r--compiler/rustc_trait_selection/src/traits/select/confirmation.rs4
-rw-r--r--compiler/rustc_type_ir/src/lib.rs2
-rw-r--r--compiler/rustc_type_ir/src/sty.rs718
-rw-r--r--src/test/run-make-fulldeps/obtain-borrowck/driver.rs2
-rw-r--r--src/test/ui-fulldeps/internal-lints/ty_tykind_usage.rs60
-rw-r--r--src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr146
17 files changed, 857 insertions, 527 deletions
diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs
index 93c7a832afd..bf38ca19484 100644
--- a/compiler/rustc_borrowck/src/lib.rs
+++ b/compiler/rustc_borrowck/src/lib.rs
@@ -98,8 +98,10 @@ struct Upvar<'tcx> {
     by_ref: bool,
 }
 
-const fn deref_projection<'tcx>() -> &'tcx [PlaceElem<'tcx>; 1] {
-    &[ProjectionElem::Deref]
+/// Associate some local constants with the `'tcx` lifetime
+struct TyCtxtConsts<'tcx>(TyCtxt<'tcx>);
+impl<'tcx> TyCtxtConsts<'tcx> {
+    const DEREF_PROJECTION: &'tcx [PlaceElem<'tcx>; 1] = &[ProjectionElem::Deref];
 }
 
 pub fn provide(providers: &mut Providers) {
@@ -1445,7 +1447,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
                 // Thread-locals might be dropped after the function exits
                 // We have to dereference the outer reference because
                 // borrows don't conflict behind shared references.
-                root_place.projection = deref_projection();
+                root_place.projection = TyCtxtConsts::DEREF_PROJECTION;
                 (true, true)
             } else {
                 (false, self.locals_are_invalidated_at_exit)
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
index bbbd1e94514..dd3adbf70a6 100644
--- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
+++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
@@ -33,7 +33,7 @@ use rustc_middle::mir::{self, GeneratorLayout};
 use rustc_middle::ty::layout::LayoutOf;
 use rustc_middle::ty::layout::TyAndLayout;
 use rustc_middle::ty::subst::GenericArgKind;
-use rustc_middle::ty::{self, common_vtable_entries, AdtKind, Instance, ParamEnv, Ty, TyCtxt};
+use rustc_middle::ty::{self, AdtKind, Instance, ParamEnv, Ty, TyCtxt};
 use rustc_session::config::{self, DebugInfo};
 use rustc_span::symbol::Symbol;
 use rustc_span::FileName;
@@ -1392,7 +1392,7 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
 
         tcx.vtable_entries(trait_ref)
     } else {
-        common_vtable_entries()
+        TyCtxt::COMMON_VTABLE_ENTRIES
     };
 
     // All function pointers are described as opaque pointers. This could be improved in the future
diff --git a/compiler/rustc_const_eval/src/interpret/traits.rs b/compiler/rustc_const_eval/src/interpret/traits.rs
index d5a448a8963..c4d1074e437 100644
--- a/compiler/rustc_const_eval/src/interpret/traits.rs
+++ b/compiler/rustc_const_eval/src/interpret/traits.rs
@@ -2,8 +2,8 @@ use std::convert::TryFrom;
 
 use rustc_middle::mir::interpret::{InterpResult, Pointer, PointerArithmetic};
 use rustc_middle::ty::{
-    self, common_vtable_entries, Ty, COMMON_VTABLE_ENTRIES_ALIGN,
-    COMMON_VTABLE_ENTRIES_DROPINPLACE, COMMON_VTABLE_ENTRIES_SIZE,
+    self, Ty, TyCtxt, COMMON_VTABLE_ENTRIES_ALIGN, COMMON_VTABLE_ENTRIES_DROPINPLACE,
+    COMMON_VTABLE_ENTRIES_SIZE,
 };
 use rustc_target::abi::{Align, Size};
 
@@ -38,7 +38,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
     }
 
     /// Resolves the function at the specified slot in the provided
-    /// vtable. Currently an index of '3' (`common_vtable_entries().len()`)
+    /// vtable. Currently an index of '3' (`TyCtxt::COMMON_VTABLE_ENTRIES.len()`)
     /// corresponds to the first method declared in the trait of the provided vtable.
     pub fn get_vtable_slot(
         &self,
@@ -64,7 +64,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
         let vtable = self
             .get_ptr_alloc(
                 vtable,
-                pointer_size * u64::try_from(common_vtable_entries().len()).unwrap(),
+                pointer_size * u64::try_from(TyCtxt::COMMON_VTABLE_ENTRIES.len()).unwrap(),
                 self.tcx.data_layout.pointer_align.abi,
             )?
             .expect("cannot be a ZST");
@@ -99,7 +99,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
         let vtable = self
             .get_ptr_alloc(
                 vtable,
-                pointer_size * u64::try_from(common_vtable_entries().len()).unwrap(),
+                pointer_size * u64::try_from(TyCtxt::COMMON_VTABLE_ENTRIES.len()).unwrap(),
                 self.tcx.data_layout.pointer_align.abi,
             )?
             .expect("cannot be a ZST");
diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs
index 27d44da6dfc..b83d63e0da0 100644
--- a/compiler/rustc_lint/src/internal.rs
+++ b/compiler/rustc_lint/src/internal.rs
@@ -5,8 +5,8 @@ use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}
 use rustc_ast as ast;
 use rustc_errors::Applicability;
 use rustc_hir::def::Res;
-use rustc_hir::{Expr, ExprKind, GenericArg, Path, PathSegment, QPath};
-use rustc_hir::{HirId, Item, ItemKind, Node, Ty, TyKind};
+use rustc_hir::{Expr, ExprKind, GenericArg, PatKind, Path, PathSegment, QPath};
+use rustc_hir::{HirId, Item, ItemKind, Node, Pat, Ty, TyKind};
 use rustc_middle::ty;
 use rustc_session::{declare_lint_pass, declare_tool_lint};
 use rustc_span::hygiene::{ExpnKind, MacroKind};
@@ -123,55 +123,115 @@ declare_lint_pass!(TyTyKind => [
 ]);
 
 impl<'tcx> LateLintPass<'tcx> for TyTyKind {
-    fn check_path(&mut self, cx: &LateContext<'_>, path: &'tcx Path<'tcx>, _: HirId) {
-        let segments = path.segments.iter().rev().skip(1).rev();
-
-        if let Some(last) = segments.last() {
-            let span = path.span.with_hi(last.ident.span.hi());
-            if lint_ty_kind_usage(cx, last) {
-                cx.struct_span_lint(USAGE_OF_TY_TYKIND, span, |lint| {
-                    lint.build("usage of `ty::TyKind::<kind>`")
-                        .span_suggestion(
-                            span,
-                            "try using ty::<kind> directly",
-                            "ty".to_string(),
-                            Applicability::MaybeIncorrect, // ty maybe needs an import
-                        )
-                        .emit();
-                })
-            }
+    fn check_path(
+        &mut self,
+        cx: &LateContext<'tcx>,
+        path: &'tcx rustc_hir::Path<'tcx>,
+        _: rustc_hir::HirId,
+    ) {
+        if let Some(segment) = path.segments.iter().nth_back(1)
+        && let Some(res) = &segment.res
+        && lint_ty_kind_usage(cx, res)
+        {
+            let span = path.span.with_hi(
+                segment.args.map_or(segment.ident.span, |a| a.span_ext).hi()
+            );
+            cx.struct_span_lint(USAGE_OF_TY_TYKIND, path.span, |lint| {
+                lint.build("usage of `ty::TyKind::<kind>`")
+                    .span_suggestion(
+                        span,
+                        "try using `ty::<kind>` directly",
+                        "ty".to_string(),
+                        Applicability::MaybeIncorrect, // ty maybe needs an import
+                    )
+                    .emit();
+            });
         }
     }
 
     fn check_ty(&mut self, cx: &LateContext<'_>, ty: &'tcx Ty<'tcx>) {
         match &ty.kind {
             TyKind::Path(QPath::Resolved(_, path)) => {
-                if let Some(last) = path.segments.iter().last() {
-                    if lint_ty_kind_usage(cx, last) {
-                        cx.struct_span_lint(USAGE_OF_TY_TYKIND, path.span, |lint| {
-                            lint.build("usage of `ty::TyKind`")
-                                .help("try using `Ty` instead")
-                                .emit();
-                        })
-                    } else {
-                        if ty.span.from_expansion() {
-                            return;
-                        }
-                        if let Some(t) = is_ty_or_ty_ctxt(cx, ty) {
-                            if path.segments.len() > 1 {
-                                cx.struct_span_lint(USAGE_OF_QUALIFIED_TY, path.span, |lint| {
-                                    lint.build(&format!("usage of qualified `ty::{}`", t))
+                if lint_ty_kind_usage(cx, &path.res) {
+                    cx.struct_span_lint(USAGE_OF_TY_TYKIND, path.span, |lint| {
+                        let hir = cx.tcx.hir();
+                        match hir.find(hir.get_parent_node(ty.hir_id)) {
+                            Some(Node::Pat(Pat {
+                                kind:
+                                    PatKind::Path(qpath)
+                                    | PatKind::TupleStruct(qpath, ..)
+                                    | PatKind::Struct(qpath, ..),
+                                ..
+                            })) => {
+                                if let QPath::TypeRelative(qpath_ty, ..) = qpath
+                                    && qpath_ty.hir_id == ty.hir_id
+                                {
+                                    lint.build("usage of `ty::TyKind::<kind>`")
+                                        .span_suggestion(
+                                            path.span,
+                                            "try using `ty::<kind>` directly",
+                                            "ty".to_string(),
+                                            Applicability::MaybeIncorrect, // ty maybe needs an import
+                                        )
+                                        .emit();
+                                    return;
+                                }
+                            }
+                            Some(Node::Expr(Expr {
+                                kind: ExprKind::Path(qpath),
+                                ..
+                            })) => {
+                                if let QPath::TypeRelative(qpath_ty, ..) = qpath
+                                    && qpath_ty.hir_id == ty.hir_id
+                                {
+                                    lint.build("usage of `ty::TyKind::<kind>`")
                                         .span_suggestion(
                                             path.span,
-                                            "try importing it and using it unqualified",
-                                            t,
-                                            // The import probably needs to be changed
-                                            Applicability::MaybeIncorrect,
+                                            "try using `ty::<kind>` directly",
+                                            "ty".to_string(),
+                                            Applicability::MaybeIncorrect, // ty maybe needs an import
                                         )
                                         .emit();
-                                })
+                                    return;
+                                }
                             }
+                            // Can't unify these two branches because qpath below is `&&` and above is `&`
+                            // and `A | B` paths don't play well together with adjustments, apparently.
+                            Some(Node::Expr(Expr {
+                                kind: ExprKind::Struct(qpath, ..),
+                                ..
+                            })) => {
+                                if let QPath::TypeRelative(qpath_ty, ..) = qpath
+                                    && qpath_ty.hir_id == ty.hir_id
+                                {
+                                    lint.build("usage of `ty::TyKind::<kind>`")
+                                        .span_suggestion(
+                                            path.span,
+                                            "try using `ty::<kind>` directly",
+                                            "ty".to_string(),
+                                            Applicability::MaybeIncorrect, // ty maybe needs an import
+                                        )
+                                        .emit();
+                                    return;
+                                }
+                            }
+                            _ => {}
                         }
+                        lint.build("usage of `ty::TyKind`").help("try using `Ty` instead").emit();
+                    })
+                } else if !ty.span.from_expansion() && let Some(t) = is_ty_or_ty_ctxt(cx, &path) {
+                    if path.segments.len() > 1 {
+                        cx.struct_span_lint(USAGE_OF_QUALIFIED_TY, path.span, |lint| {
+                            lint.build(&format!("usage of qualified `ty::{}`", t))
+                                .span_suggestion(
+                                    path.span,
+                                    "try importing it and using it unqualified",
+                                    t,
+                                    // The import probably needs to be changed
+                                    Applicability::MaybeIncorrect,
+                                )
+                                .emit();
+                        })
                     }
                 }
             }
@@ -180,42 +240,37 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
     }
 }
 
-fn lint_ty_kind_usage(cx: &LateContext<'_>, segment: &PathSegment<'_>) -> bool {
-    if let Some(res) = segment.res {
-        if let Some(did) = res.opt_def_id() {
-            return cx.tcx.is_diagnostic_item(sym::TyKind, did);
-        }
+fn lint_ty_kind_usage(cx: &LateContext<'_>, res: &Res) -> bool {
+    if let Some(did) = res.opt_def_id() {
+        cx.tcx.is_diagnostic_item(sym::TyKind, did) || cx.tcx.is_diagnostic_item(sym::IrTyKind, did)
+    } else {
+        false
     }
-
-    false
 }
 
-fn is_ty_or_ty_ctxt(cx: &LateContext<'_>, ty: &Ty<'_>) -> Option<String> {
-    if let TyKind::Path(QPath::Resolved(_, path)) = &ty.kind {
-        match path.res {
-            Res::Def(_, def_id) => {
-                if let Some(name @ (sym::Ty | sym::TyCtxt)) = cx.tcx.get_diagnostic_name(def_id) {
-                    return Some(format!("{}{}", name, gen_args(path.segments.last().unwrap())));
-                }
+fn is_ty_or_ty_ctxt(cx: &LateContext<'_>, path: &Path<'_>) -> Option<String> {
+    match &path.res {
+        Res::Def(_, def_id) => {
+            if let Some(name @ (sym::Ty | sym::TyCtxt)) = cx.tcx.get_diagnostic_name(*def_id) {
+                return Some(format!("{}{}", name, gen_args(path.segments.last().unwrap())));
             }
-            // Only lint on `&Ty` and `&TyCtxt` if it is used outside of a trait.
-            Res::SelfTy { trait_: None, alias_to: Some((did, _)) } => {
-                if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() {
-                    if let Some(name @ (sym::Ty | sym::TyCtxt)) =
-                        cx.tcx.get_diagnostic_name(adt.did())
-                    {
-                        // NOTE: This path is currently unreachable as `Ty<'tcx>` is
-                        // defined as a type alias meaning that `impl<'tcx> Ty<'tcx>`
-                        // is not actually allowed.
-                        //
-                        // I(@lcnr) still kept this branch in so we don't miss this
-                        // if we ever change it in the future.
-                        return Some(format!("{}<{}>", name, substs[0]));
-                    }
+        }
+        // Only lint on `&Ty` and `&TyCtxt` if it is used outside of a trait.
+        Res::SelfTy { trait_: None, alias_to: Some((did, _)) } => {
+            if let ty::Adt(adt, substs) = cx.tcx.type_of(did).kind() {
+                if let Some(name @ (sym::Ty | sym::TyCtxt)) = cx.tcx.get_diagnostic_name(adt.did())
+                {
+                    // NOTE: This path is currently unreachable as `Ty<'tcx>` is
+                    // defined as a type alias meaning that `impl<'tcx> Ty<'tcx>`
+                    // is not actually allowed.
+                    //
+                    // I(@lcnr) still kept this branch in so we don't miss this
+                    // if we ever change it in the future.
+                    return Some(format!("{}<{}>", name, substs[0]));
                 }
             }
-            _ => (),
         }
+        _ => (),
     }
 
     None
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index a5e6a1b97dd..6f548658ef3 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -94,6 +94,7 @@ pub struct TyInterner<'tcx> {
     pub tcx: TyCtxt<'tcx>,
 }
 
+/*
 /// We don't ever actually need this. It's only required for derives.
 impl<'tcx> Hash for TyInterner<'tcx> {
     fn hash<H: Hasher>(&self, _state: &mut H) {}
@@ -128,6 +129,7 @@ impl fmt::Debug for TyInterner<'_> {
         write!(f, "TyInterner")
     }
 }
+*/
 
 #[allow(rustc::usage_of_ty_tykind)]
 impl<'tcx> Interner for TyInterner<'tcx> {
diff --git a/compiler/rustc_middle/src/ty/fast_reject.rs b/compiler/rustc_middle/src/ty/fast_reject.rs
index f7ced066062..208cd9ba16a 100644
--- a/compiler/rustc_middle/src/ty/fast_reject.rs
+++ b/compiler/rustc_middle/src/ty/fast_reject.rs
@@ -207,10 +207,10 @@ pub struct DeepRejectCtxt {
 }
 
 impl DeepRejectCtxt {
-    pub fn generic_args_may_unify(
+    pub fn generic_args_may_unify<'tcx>(
         self,
-        obligation_arg: ty::GenericArg<'_>,
-        impl_arg: ty::GenericArg<'_>,
+        obligation_arg: ty::GenericArg<'tcx>,
+        impl_arg: ty::GenericArg<'tcx>,
     ) -> bool {
         match (obligation_arg.unpack(), impl_arg.unpack()) {
             // We don't fast reject based on regions for now.
@@ -225,7 +225,7 @@ impl DeepRejectCtxt {
         }
     }
 
-    pub fn types_may_unify(self, obligation_ty: Ty<'_>, impl_ty: Ty<'_>) -> bool {
+    pub fn types_may_unify<'tcx>(self, obligation_ty: Ty<'tcx>, impl_ty: Ty<'tcx>) -> bool {
         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.
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs
index a7ecbdff5ae..25305804d3a 100644
--- a/compiler/rustc_middle/src/ty/mod.rs
+++ b/compiler/rustc_middle/src/ty/mod.rs
@@ -449,13 +449,13 @@ pub(crate) struct TyS<'tcx> {
 }
 
 // `TyS` is used a lot. Make sure it doesn't unintentionally get bigger.
-//#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
-//static_assert_size!(TyS<'_>, 40);
+#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
+static_assert_size!(TyS<'_>, 40);
 
 // We are actually storing a stable hash cache next to the type, so let's
 // also check the full size
-//#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
-//static_assert_size!(WithStableHash<TyS<'_>>, 56);
+#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
+static_assert_size!(WithStableHash<TyS<'_>>, 56);
 
 /// Use this rather than `TyS`, whenever possible.
 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)]
diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs
index 4edad27ee7a..9410166ac20 100644
--- a/compiler/rustc_middle/src/ty/sty.rs
+++ b/compiler/rustc_middle/src/ty/sty.rs
@@ -27,9 +27,12 @@ use std::marker::PhantomData;
 use std::ops::{ControlFlow, Deref, Range};
 use ty::util::IntTypeExt;
 
+use rustc_type_ir::sty::TyKind::*;
 use rustc_type_ir::TyKind as IrTyKind;
+
+// Re-export the `TyKind` from `rustc_type_ir` here for convenience
+#[rustc_diagnostic_item = "TyKind"]
 pub type TyKind<'tcx> = IrTyKind<ty::TyInterner<'tcx>>;
-use rustc_type_ir::sty::TyKind::*;
 
 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
 #[derive(HashStable, TypeFoldable, Lift)]
@@ -80,205 +83,6 @@ impl BoundRegionKind {
     }
 }
 
-/*
-/// Defines the kinds of types used by the type system.
-///
-/// Types written by the user start out as [hir::TyKind](rustc_hir::TyKind) and get
-/// converted to this representation using `AstConv::ast_ty_to_ty`.
-#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable, Debug)]
-#[derive(HashStable)]
-#[rustc_diagnostic_item = "TyKind"]
-pub enum TyKind<'tcx> {
-    /// The primitive boolean type. Written as `bool`.
-    Bool,
-
-    /// The primitive character type; holds a Unicode scalar value
-    /// (a non-surrogate code point). Written as `char`.
-    Char,
-
-    /// A primitive signed integer type. For example, `i32`.
-    Int(ty::IntTy),
-
-    /// A primitive unsigned integer type. For example, `u32`.
-    Uint(ty::UintTy),
-
-    /// A primitive floating-point type. For example, `f64`.
-    Float(ty::FloatTy),
-
-    /// Algebraic data types (ADT). For example: structures, enumerations and unions.
-    ///
-    /// For example, the type `List<i32>` would be represented using the `AdtDef`
-    /// for `struct List<T>` and the substs `[i32]`.
-    ///
-    /// Note that generic parameters in fields only get lazily substituted
-    /// by using something like `adt_def.all_fields().map(|field| field.ty(tcx, substs))`.
-    Adt(AdtDef<'tcx>, SubstsRef<'tcx>),
-
-    /// An unsized FFI type that is opaque to Rust. Written as `extern type T`.
-    Foreign(DefId),
-
-    /// The pointee of a string slice. Written as `str`.
-    Str,
-
-    /// An array with the given length. Written as `[T; N]`.
-    Array(Ty<'tcx>, ty::Const<'tcx>),
-
-    /// The pointee of an array slice. Written as `[T]`.
-    Slice(Ty<'tcx>),
-
-    /// A raw pointer. Written as `*mut T` or `*const T`
-    RawPtr(TypeAndMut<'tcx>),
-
-    /// A reference; a pointer with an associated lifetime. Written as
-    /// `&'a mut T` or `&'a T`.
-    Ref(Region<'tcx>, Ty<'tcx>, hir::Mutability),
-
-    /// The anonymous type of a function declaration/definition. Each
-    /// function has a unique type.
-    ///
-    /// For the function `fn foo() -> i32 { 3 }` this type would be
-    /// shown to the user as `fn() -> i32 {foo}`.
-    ///
-    /// For example the type of `bar` here:
-    /// ```rust
-    /// fn foo() -> i32 { 1 }
-    /// let bar = foo; // bar: fn() -> i32 {foo}
-    /// ```
-    FnDef(DefId, SubstsRef<'tcx>),
-
-    /// A pointer to a function. Written as `fn() -> i32`.
-    ///
-    /// Note that both functions and closures start out as either
-    /// [FnDef] or [Closure] which can be then be coerced to this variant.
-    ///
-    /// For example the type of `bar` here:
-    ///
-    /// ```rust
-    /// fn foo() -> i32 { 1 }
-    /// let bar: fn() -> i32 = foo;
-    /// ```
-    FnPtr(PolyFnSig<'tcx>),
-
-    /// A trait object. Written as `dyn for<'b> Trait<'b, Assoc = u32> + Send + 'a`.
-    Dynamic(&'tcx List<Binder<'tcx, ExistentialPredicate<'tcx>>>, ty::Region<'tcx>),
-
-    /// The anonymous type of a closure. Used to represent the type of `|a| a`.
-    ///
-    /// Closure substs contain both the - potentially substituted - generic parameters
-    /// of its parent and some synthetic parameters. See the documentation for
-    /// [ClosureSubsts] for more details.
-    Closure(DefId, SubstsRef<'tcx>),
-
-    /// The anonymous type of a generator. Used to represent the type of
-    /// `|a| yield a`.
-    ///
-    /// For more info about generator substs, visit the documentation for
-    /// [GeneratorSubsts].
-    Generator(DefId, SubstsRef<'tcx>, hir::Movability),
-
-    /// A type representing the types stored inside a generator.
-    /// This should only appear as part of the [GeneratorSubsts].
-    ///
-    /// Note that the captured variables for generators are stored separately
-    /// using a tuple in the same way as for closures.
-    ///
-    /// Unlike upvars, the witness can reference lifetimes from
-    /// inside of the generator itself. To deal with them in
-    /// the type of the generator, we convert them to higher ranked
-    /// lifetimes bound by the witness itself.
-    ///
-    /// Looking at the following example, the witness for this generator
-    /// may end up as something like `for<'a> [Vec<i32>, &'a Vec<i32>]`:
-    ///
-    /// ```ignore UNSOLVED (ask @compiler-errors, should this error? can we just swap the yields?)
-    /// #![feature(generators)]
-    /// |a| {
-    ///     let x = &vec![3];
-    ///     yield a;
-    ///     yield x[0];
-    /// }
-    /// # ;
-    /// ```
-    GeneratorWitness(Binder<'tcx, &'tcx List<Ty<'tcx>>>),
-
-    /// The never type `!`.
-    Never,
-
-    /// A tuple type. For example, `(i32, bool)`.
-    Tuple(&'tcx List<Ty<'tcx>>),
-
-    /// The projection of an associated type. For example,
-    /// `<T as Trait<..>>::N`.
-    Projection(ProjectionTy<'tcx>),
-
-    /// 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(DefId, SubstsRef<'tcx>),
-
-    /// A type parameter; for example, `T` in `fn f<T>(x: T) {}`.
-    Param(ParamTy),
-
-    /// Bound type variable, used to represent the `'a` in `for<'a> fn(&'a ())`.
-    ///
-    /// For canonical queries, we replace inference variables with bound variables,
-    /// so e.g. when checking whether `&'_ (): Trait<_>` holds, we canonicalize that to
-    /// `for<'a, T> &'a (): Trait<T>` and then convert the introduced bound variables
-    /// back to inference variables in a new inference context when inside of the query.
-    ///
-    /// See the `rustc-dev-guide` for more details about
-    /// [higher-ranked trait bounds][1] and [canonical queries][2].
-    ///
-    /// [1]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html
-    /// [2]: https://rustc-dev-guide.rust-lang.org/traits/canonical-queries.html
-    Bound(ty::DebruijnIndex, BoundTy),
-
-    /// A placeholder type, used during higher ranked subtyping to instantiate
-    /// bound variables.
-    Placeholder(ty::PlaceholderType),
-
-    /// A type variable used during type checking.
-    ///
-    /// Similar to placeholders, inference variables also live in a universe to
-    /// correctly deal with higher ranked types. Though unlike placeholders,
-    /// that universe is stored in the `InferCtxt` instead of directly
-    /// inside of the type.
-    Infer(InferTy),
-
-    /// A placeholder for a type which could not be computed; this is
-    /// propagated to avoid useless error messages.
-    Error(DelaySpanBugEmitted),
-}
-*/
-
-/*
-impl<'tcx> TyKind<'tcx> {
-    #[inline]
-    pub fn is_primitive(&self) -> bool {
-        matches!(self, Bool | Char | Int(_) | Uint(_) | Float(_))
-    }
-
-    /// Get the article ("a" or "an") to use with this type.
-    pub fn article(&self) -> &'static str {
-        match self {
-            Int(_) | Float(_) | Array(_, _) => "an",
-            Adt(def, _) if def.is_enum() => "an",
-            // This should never happen, but ICEing and causing the user's code
-            // to not compile felt too harsh.
-            Error(_) => "a",
-            _ => "a",
-        }
-    }
-}
-*/
-
 pub trait Article {
     fn article(&self) -> &'static str;
 }
diff --git a/compiler/rustc_middle/src/ty/vtable.rs b/compiler/rustc_middle/src/ty/vtable.rs
index 793b5768ad1..04a9fd1f713 100644
--- a/compiler/rustc_middle/src/ty/vtable.rs
+++ b/compiler/rustc_middle/src/ty/vtable.rs
@@ -36,8 +36,10 @@ impl<'tcx> fmt::Debug for VtblEntry<'tcx> {
     }
 }
 
-pub const fn common_vtable_entries<'tcx>() -> &'tcx [VtblEntry<'tcx>] {
-    &[VtblEntry::MetadataDropInPlace, VtblEntry::MetadataSize, VtblEntry::MetadataAlign]
+// Needs to be associated with the `'tcx` lifetime
+impl<'tcx> TyCtxt<'tcx> {
+    pub const COMMON_VTABLE_ENTRIES: &'tcx [VtblEntry<'tcx>] =
+        &[VtblEntry::MetadataDropInPlace, VtblEntry::MetadataSize, VtblEntry::MetadataAlign];
 }
 
 pub const COMMON_VTABLE_ENTRIES_DROPINPLACE: usize = 0;
@@ -58,7 +60,7 @@ pub(super) fn vtable_allocation_provider<'tcx>(
 
         tcx.vtable_entries(trait_ref)
     } else {
-        common_vtable_entries()
+        TyCtxt::COMMON_VTABLE_ENTRIES
     };
 
     let layout = tcx
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 406e9a4113e..6aeedc49adf 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -205,6 +205,7 @@ symbols! {
         IntoIterator,
         IoRead,
         IoWrite,
+        IrTyKind,
         Is,
         ItemContext,
         Iterator,
diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs
index 0a0a1296aae..03757b5447e 100644
--- a/compiler/rustc_trait_selection/src/traits/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/mod.rs
@@ -32,9 +32,7 @@ use rustc_hir::def_id::DefId;
 use rustc_hir::lang_items::LangItem;
 use rustc_middle::ty::fold::TypeFoldable;
 use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
-use rustc_middle::ty::{
-    self, common_vtable_entries, GenericParamDefKind, ToPredicate, Ty, TyCtxt, VtblEntry,
-};
+use rustc_middle::ty::{self, GenericParamDefKind, ToPredicate, Ty, TyCtxt, VtblEntry};
 use rustc_span::{sym, Span};
 use smallvec::SmallVec;
 
@@ -695,7 +693,7 @@ fn vtable_entries<'tcx>(
     let vtable_segment_callback = |segment| -> ControlFlow<()> {
         match segment {
             VtblSegment::MetadataDSA => {
-                entries.extend(common_vtable_entries());
+                entries.extend(TyCtxt::COMMON_VTABLE_ENTRIES);
             }
             VtblSegment::TraitOwnEntries { trait_ref, emit_vptr } => {
                 let existential_trait_ref = trait_ref
@@ -785,7 +783,7 @@ fn vtable_trait_first_method_offset<'tcx>(
         move |segment| {
             match segment {
                 VtblSegment::MetadataDSA => {
-                    vtable_base += common_vtable_entries().len();
+                    vtable_base += TyCtxt::COMMON_VTABLE_ENTRIES.len();
                 }
                 VtblSegment::TraitOwnEntries { trait_ref, emit_vptr } => {
                     if tcx.erase_regions(trait_ref) == trait_to_be_found_erased {
diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
index 548b60d74ba..34dc81b14d2 100644
--- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
+++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs
@@ -12,7 +12,7 @@ use rustc_index::bit_set::GrowableBitSet;
 use rustc_infer::infer::InferOk;
 use rustc_infer::infer::LateBoundRegionConversionTime::HigherRankedType;
 use rustc_middle::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef};
-use rustc_middle::ty::{self, EarlyBinder, GenericParamDefKind, Ty};
+use rustc_middle::ty::{self, EarlyBinder, GenericParamDefKind, Ty, TyCtxt};
 use rustc_middle::ty::{ToPolyTraitRef, ToPredicate};
 use rustc_span::def_id::DefId;
 
@@ -834,7 +834,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
             move |segment| {
                 match segment {
                     VtblSegment::MetadataDSA => {
-                        vptr_offset += ty::common_vtable_entries().len();
+                        vptr_offset += TyCtxt::COMMON_VTABLE_ENTRIES.len();
                     }
                     VtblSegment::TraitOwnEntries { trait_ref, emit_vptr } => {
                         vptr_offset += util::count_own_vtable_entries(tcx, trait_ref);
diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs
index 960e42d8006..766875dd82b 100644
--- a/compiler/rustc_type_ir/src/lib.rs
+++ b/compiler/rustc_type_ir/src/lib.rs
@@ -21,8 +21,6 @@ pub mod sty;
 pub use codec::*;
 pub use sty::*;
 
-extern crate self as rustc_type_ir;
-
 pub trait Interner {
     type AdtDef: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
     type SubstsRef: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord;
diff --git a/compiler/rustc_type_ir/src/sty.rs b/compiler/rustc_type_ir/src/sty.rs
index 0f614967def..33b3a273f44 100644
--- a/compiler/rustc_type_ir/src/sty.rs
+++ b/compiler/rustc_type_ir/src/sty.rs
@@ -1,3 +1,8 @@
+#![allow(rustc::usage_of_ty_tykind)]
+
+use std::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
+use std::{fmt, hash};
+
 use crate::DebruijnIndex;
 use crate::FloatTy;
 use crate::IntTy;
@@ -6,17 +11,17 @@ use crate::TyDecoder;
 use crate::TyEncoder;
 use crate::UintTy;
 
+use self::TyKind::*;
+
 use rustc_serialize::{Decodable, Encodable};
 
 /// Defines the kinds of types used by the type system.
 ///
-/// Types written by the user start out as [hir::TyKind](rustc_hir::TyKind) and get
+/// Types written by the user start out as `hir::TyKind` and get
 /// converted to this representation using `AstConv::ast_ty_to_ty`.
-#[allow(rustc::usage_of_ty_tykind)]
-#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
-//#[derive(TyEncodable, TyDecodable)]
-//#[derive(HashStable)]
-#[rustc_diagnostic_item = "TyKind"]
+///
+/// The `HashStable` implementation for this type is defined in `rustc_query_system::ich`.
+#[rustc_diagnostic_item = "IrTyKind"]
 pub enum TyKind<I: Interner> {
     /// The primitive boolean type. Written as `bool`.
     Bool,
@@ -95,18 +100,18 @@ pub enum TyKind<I: Interner> {
     ///
     /// Closure substs contain both the - potentially substituted - generic parameters
     /// of its parent and some synthetic parameters. See the documentation for
-    /// [ClosureSubsts] for more details.
+    /// `ClosureSubsts` for more details.
     Closure(I::DefId, I::SubstsRef),
 
     /// The anonymous type of a generator. Used to represent the type of
     /// `|a| yield a`.
     ///
     /// For more info about generator substs, visit the documentation for
-    /// [GeneratorSubsts].
+    /// `GeneratorSubsts`.
     Generator(I::DefId, I::SubstsRef, I::Movability),
 
     /// A type representing the types stored inside a generator.
-    /// This should only appear as part of the [GeneratorSubsts].
+    /// This should only appear as part of the `GeneratorSubsts`.
     ///
     /// Note that the captured variables for generators are stored separately
     /// using a tuple in the same way as for closures.
@@ -186,10 +191,47 @@ pub enum TyKind<I: Interner> {
     Error(I::DelaySpanBugEmitted),
 }
 
-#[allow(rustc::usage_of_ty_tykind)]
+impl<I: Interner> TyKind<I> {
+    #[inline]
+    pub fn is_primitive(&self) -> bool {
+        matches!(self, Bool | Char | Int(_) | Uint(_) | Float(_))
+    }
+}
+
+fn discriminant<I: Interner>(value: &TyKind<I>) -> usize {
+    match value {
+        Bool => 0,
+        Char => 1,
+        Int(_) => 2,
+        Uint(_) => 3,
+        Float(_) => 4,
+        Adt(_, _) => 5,
+        Foreign(_) => 6,
+        Str => 7,
+        Array(_, _) => 8,
+        Slice(_) => 9,
+        RawPtr(_) => 10,
+        Ref(_, _, _) => 11,
+        FnDef(_, _) => 12,
+        FnPtr(_) => 13,
+        Dynamic(_, _) => 14,
+        Closure(_, _) => 15,
+        Generator(_, _, _) => 16,
+        GeneratorWitness(_) => 17,
+        Never => 18,
+        Tuple(_) => 19,
+        Projection(_) => 20,
+        Opaque(_, _) => 21,
+        Param(_) => 22,
+        Bound(_, _) => 23,
+        Placeholder(_) => 24,
+        Infer(_) => 25,
+        Error(_) => 26,
+    }
+}
+
 impl<I: Interner> Clone for TyKind<I> {
     fn clone(&self) -> Self {
-        use crate::TyKind::*;
         match self {
             Bool => Bool,
             Char => Char,
@@ -222,149 +264,553 @@ impl<I: Interner> Clone for TyKind<I> {
     }
 }
 
-#[allow(rustc::usage_of_ty_tykind)]
-impl<I: Interner> TyKind<I> {
+impl<I: Interner> PartialEq for TyKind<I> {
     #[inline]
-    pub fn is_primitive(&self) -> bool {
-        use crate::TyKind::*;
-        matches!(self, Bool | Char | Int(_) | Uint(_) | Float(_))
+    fn eq(&self, other: &TyKind<I>) -> bool {
+        let __self_vi = discriminant(self);
+        let __arg_1_vi = discriminant(other);
+        if __self_vi == __arg_1_vi {
+            match (&*self, &*other) {
+                (&Int(ref __self_0), &Int(ref __arg_1_0)) => __self_0 == __arg_1_0,
+                (&Uint(ref __self_0), &Uint(ref __arg_1_0)) => __self_0 == __arg_1_0,
+                (&Float(ref __self_0), &Float(ref __arg_1_0)) => __self_0 == __arg_1_0,
+                (&Adt(ref __self_0, ref __self_1), &Adt(ref __arg_1_0, ref __arg_1_1)) => {
+                    __self_0 == __arg_1_0 && __self_1 == __arg_1_1
+                }
+                (&Foreign(ref __self_0), &Foreign(ref __arg_1_0)) => __self_0 == __arg_1_0,
+                (&Array(ref __self_0, ref __self_1), &Array(ref __arg_1_0, ref __arg_1_1)) => {
+                    __self_0 == __arg_1_0 && __self_1 == __arg_1_1
+                }
+                (&Slice(ref __self_0), &Slice(ref __arg_1_0)) => __self_0 == __arg_1_0,
+                (&RawPtr(ref __self_0), &RawPtr(ref __arg_1_0)) => __self_0 == __arg_1_0,
+                (
+                    &Ref(ref __self_0, ref __self_1, ref __self_2),
+                    &Ref(ref __arg_1_0, ref __arg_1_1, ref __arg_1_2),
+                ) => __self_0 == __arg_1_0 && __self_1 == __arg_1_1 && __self_2 == __arg_1_2,
+                (&FnDef(ref __self_0, ref __self_1), &FnDef(ref __arg_1_0, ref __arg_1_1)) => {
+                    __self_0 == __arg_1_0 && __self_1 == __arg_1_1
+                }
+                (&FnPtr(ref __self_0), &FnPtr(ref __arg_1_0)) => __self_0 == __arg_1_0,
+                (&Dynamic(ref __self_0, ref __self_1), &Dynamic(ref __arg_1_0, ref __arg_1_1)) => {
+                    __self_0 == __arg_1_0 && __self_1 == __arg_1_1
+                }
+                (&Closure(ref __self_0, ref __self_1), &Closure(ref __arg_1_0, ref __arg_1_1)) => {
+                    __self_0 == __arg_1_0 && __self_1 == __arg_1_1
+                }
+                (
+                    &Generator(ref __self_0, ref __self_1, ref __self_2),
+                    &Generator(ref __arg_1_0, ref __arg_1_1, ref __arg_1_2),
+                ) => __self_0 == __arg_1_0 && __self_1 == __arg_1_1 && __self_2 == __arg_1_2,
+                (&GeneratorWitness(ref __self_0), &GeneratorWitness(ref __arg_1_0)) => {
+                    __self_0 == __arg_1_0
+                }
+                (&Tuple(ref __self_0), &Tuple(ref __arg_1_0)) => __self_0 == __arg_1_0,
+                (&Projection(ref __self_0), &Projection(ref __arg_1_0)) => __self_0 == __arg_1_0,
+                (&Opaque(ref __self_0, ref __self_1), &Opaque(ref __arg_1_0, ref __arg_1_1)) => {
+                    __self_0 == __arg_1_0 && __self_1 == __arg_1_1
+                }
+                (&Param(ref __self_0), &Param(ref __arg_1_0)) => __self_0 == __arg_1_0,
+                (&Bound(ref __self_0, ref __self_1), &Bound(ref __arg_1_0, ref __arg_1_1)) => {
+                    __self_0 == __arg_1_0 && __self_1 == __arg_1_1
+                }
+                (&Placeholder(ref __self_0), &Placeholder(ref __arg_1_0)) => __self_0 == __arg_1_0,
+                (&Infer(ref __self_0), &Infer(ref __arg_1_0)) => __self_0 == __arg_1_0,
+                (&Error(ref __self_0), &Error(ref __arg_1_0)) => __self_0 == __arg_1_0,
+                _ => true,
+            }
+        } else {
+            false
+        }
+    }
+}
+
+impl<I: Interner> Eq for TyKind<I> {}
+
+impl<I: Interner> PartialOrd for TyKind<I> {
+    #[inline]
+    fn partial_cmp(&self, other: &TyKind<I>) -> Option<Ordering> {
+        Some(Ord::cmp(self, other))
+    }
+}
+
+impl<I: Interner> Ord for TyKind<I> {
+    #[inline]
+    fn cmp(&self, other: &TyKind<I>) -> Ordering {
+        let __self_vi = discriminant(self);
+        let __arg_1_vi = discriminant(other);
+        if __self_vi == __arg_1_vi {
+            match (&*self, &*other) {
+                (&Int(ref __self_0), &Int(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
+                (&Uint(ref __self_0), &Uint(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
+                (&Float(ref __self_0), &Float(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
+                (&Adt(ref __self_0, ref __self_1), &Adt(ref __arg_1_0, ref __arg_1_1)) => {
+                    match Ord::cmp(__self_0, __arg_1_0) {
+                        Ordering::Equal => Ord::cmp(__self_1, __arg_1_1),
+                        cmp => cmp,
+                    }
+                }
+                (&Foreign(ref __self_0), &Foreign(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
+                (&Array(ref __self_0, ref __self_1), &Array(ref __arg_1_0, ref __arg_1_1)) => {
+                    match Ord::cmp(__self_0, __arg_1_0) {
+                        Ordering::Equal => Ord::cmp(__self_1, __arg_1_1),
+                        cmp => cmp,
+                    }
+                }
+                (&Slice(ref __self_0), &Slice(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
+                (&RawPtr(ref __self_0), &RawPtr(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
+                (
+                    &Ref(ref __self_0, ref __self_1, ref __self_2),
+                    &Ref(ref __arg_1_0, ref __arg_1_1, ref __arg_1_2),
+                ) => match Ord::cmp(__self_0, __arg_1_0) {
+                    Ordering::Equal => match Ord::cmp(__self_1, __arg_1_1) {
+                        Ordering::Equal => Ord::cmp(__self_2, __arg_1_2),
+                        cmp => cmp,
+                    },
+                    cmp => cmp,
+                },
+                (&FnDef(ref __self_0, ref __self_1), &FnDef(ref __arg_1_0, ref __arg_1_1)) => {
+                    match Ord::cmp(__self_0, __arg_1_0) {
+                        Ordering::Equal => Ord::cmp(__self_1, __arg_1_1),
+                        cmp => cmp,
+                    }
+                }
+                (&FnPtr(ref __self_0), &FnPtr(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
+                (&Dynamic(ref __self_0, ref __self_1), &Dynamic(ref __arg_1_0, ref __arg_1_1)) => {
+                    match Ord::cmp(__self_0, __arg_1_0) {
+                        Ordering::Equal => Ord::cmp(__self_1, __arg_1_1),
+                        cmp => cmp,
+                    }
+                }
+                (&Closure(ref __self_0, ref __self_1), &Closure(ref __arg_1_0, ref __arg_1_1)) => {
+                    match Ord::cmp(__self_0, __arg_1_0) {
+                        Ordering::Equal => Ord::cmp(__self_1, __arg_1_1),
+                        cmp => cmp,
+                    }
+                }
+                (
+                    &Generator(ref __self_0, ref __self_1, ref __self_2),
+                    &Generator(ref __arg_1_0, ref __arg_1_1, ref __arg_1_2),
+                ) => match Ord::cmp(__self_0, __arg_1_0) {
+                    Ordering::Equal => match Ord::cmp(__self_1, __arg_1_1) {
+                        Ordering::Equal => Ord::cmp(__self_2, __arg_1_2),
+                        cmp => cmp,
+                    },
+                    cmp => cmp,
+                },
+                (&GeneratorWitness(ref __self_0), &GeneratorWitness(ref __arg_1_0)) => {
+                    Ord::cmp(__self_0, __arg_1_0)
+                }
+                (&Tuple(ref __self_0), &Tuple(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
+                (&Projection(ref __self_0), &Projection(ref __arg_1_0)) => {
+                    Ord::cmp(__self_0, __arg_1_0)
+                }
+                (&Opaque(ref __self_0, ref __self_1), &Opaque(ref __arg_1_0, ref __arg_1_1)) => {
+                    match Ord::cmp(__self_0, __arg_1_0) {
+                        Ordering::Equal => Ord::cmp(__self_1, __arg_1_1),
+                        cmp => cmp,
+                    }
+                }
+                (&Param(ref __self_0), &Param(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
+                (&Bound(ref __self_0, ref __self_1), &Bound(ref __arg_1_0, ref __arg_1_1)) => {
+                    match Ord::cmp(__self_0, __arg_1_0) {
+                        Ordering::Equal => Ord::cmp(__self_1, __arg_1_1),
+                        cmp => cmp,
+                    }
+                }
+                (&Placeholder(ref __self_0), &Placeholder(ref __arg_1_0)) => {
+                    Ord::cmp(__self_0, __arg_1_0)
+                }
+                (&Infer(ref __self_0), &Infer(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
+                (&Error(ref __self_0), &Error(ref __arg_1_0)) => Ord::cmp(__self_0, __arg_1_0),
+                _ => Ordering::Equal,
+            }
+        } else {
+            Ord::cmp(&__self_vi, &__arg_1_vi)
+        }
+    }
+}
+
+impl<I: Interner> hash::Hash for TyKind<I> {
+    fn hash<__H: hash::Hasher>(&self, state: &mut __H) -> () {
+        match (&*self,) {
+            (&Int(ref __self_0),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state)
+            }
+            (&Uint(ref __self_0),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state)
+            }
+            (&Float(ref __self_0),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state)
+            }
+            (&Adt(ref __self_0, ref __self_1),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state);
+                hash::Hash::hash(__self_1, state)
+            }
+            (&Foreign(ref __self_0),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state)
+            }
+            (&Array(ref __self_0, ref __self_1),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state);
+                hash::Hash::hash(__self_1, state)
+            }
+            (&Slice(ref __self_0),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state)
+            }
+            (&RawPtr(ref __self_0),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state)
+            }
+            (&Ref(ref __self_0, ref __self_1, ref __self_2),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state);
+                hash::Hash::hash(__self_1, state);
+                hash::Hash::hash(__self_2, state)
+            }
+            (&FnDef(ref __self_0, ref __self_1),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state);
+                hash::Hash::hash(__self_1, state)
+            }
+            (&FnPtr(ref __self_0),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state)
+            }
+            (&Dynamic(ref __self_0, ref __self_1),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state);
+                hash::Hash::hash(__self_1, state)
+            }
+            (&Closure(ref __self_0, ref __self_1),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state);
+                hash::Hash::hash(__self_1, state)
+            }
+            (&Generator(ref __self_0, ref __self_1, ref __self_2),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state);
+                hash::Hash::hash(__self_1, state);
+                hash::Hash::hash(__self_2, state)
+            }
+            (&GeneratorWitness(ref __self_0),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state)
+            }
+            (&Tuple(ref __self_0),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state)
+            }
+            (&Projection(ref __self_0),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state)
+            }
+            (&Opaque(ref __self_0, ref __self_1),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state);
+                hash::Hash::hash(__self_1, state)
+            }
+            (&Param(ref __self_0),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state)
+            }
+            (&Bound(ref __self_0, ref __self_1),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state);
+                hash::Hash::hash(__self_1, state)
+            }
+            (&Placeholder(ref __self_0),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state)
+            }
+            (&Infer(ref __self_0),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state)
+            }
+            (&Error(ref __self_0),) => {
+                hash::Hash::hash(&discriminant(self), state);
+                hash::Hash::hash(__self_0, state)
+            }
+            _ => hash::Hash::hash(&discriminant(self), state),
+        }
     }
 }
 
-#[allow(rustc::usage_of_ty_tykind)]
-impl<__I: Interner, __E: TyEncoder> Encodable<__E> for TyKind<__I>
+impl<I: Interner> fmt::Debug for TyKind<I> {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        match (&*self,) {
+            (&Bool,) => fmt::Formatter::write_str(f, "Bool"),
+            (&Char,) => fmt::Formatter::write_str(f, "Char"),
+            (&Int(ref __self_0),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Int");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Uint(ref __self_0),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Uint");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Float(ref __self_0),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Float");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Adt(ref __self_0, ref __self_1),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Adt");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Foreign(ref __self_0),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Foreign");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Str,) => fmt::Formatter::write_str(f, "Str"),
+            (&Array(ref __self_0, ref __self_1),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Array");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Slice(ref __self_0),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Slice");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&RawPtr(ref __self_0),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "RawPtr");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Ref(ref __self_0, ref __self_1, ref __self_2),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Ref");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_2);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&FnDef(ref __self_0, ref __self_1),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "FnDef");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&FnPtr(ref __self_0),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "FnPtr");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Dynamic(ref __self_0, ref __self_1),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Dynamic");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Closure(ref __self_0, ref __self_1),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Closure");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Generator(ref __self_0, ref __self_1, ref __self_2),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Generator");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_2);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&GeneratorWitness(ref __self_0),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "GeneratorWitness");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Never,) => fmt::Formatter::write_str(f, "Never"),
+            (&Tuple(ref __self_0),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Tuple");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Projection(ref __self_0),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Projection");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Opaque(ref __self_0, ref __self_1),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Opaque");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Param(ref __self_0),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Param");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Bound(ref __self_0, ref __self_1),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Bound");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_1);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Placeholder(ref __self_0),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Placeholder");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Infer(ref __self_0),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Infer");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+            (&Error(ref __self_0),) => {
+                let debug_trait_builder = &mut fmt::Formatter::debug_tuple(f, "Error");
+                let _ = fmt::DebugTuple::field(debug_trait_builder, &__self_0);
+                fmt::DebugTuple::finish(debug_trait_builder)
+            }
+        }
+    }
+}
+
+impl<I: Interner, E: TyEncoder> Encodable<E> for TyKind<I>
 where
-    __I::DelaySpanBugEmitted: Encodable<__E>,
-    __I::AdtDef: Encodable<__E>,
-    __I::SubstsRef: Encodable<__E>,
-    __I::DefId: Encodable<__E>,
-    __I::Ty: Encodable<__E>,
-    __I::Const: Encodable<__E>,
-    __I::Region: Encodable<__E>,
-    __I::TypeAndMut: Encodable<__E>,
-    __I::Mutability: Encodable<__E>,
-    __I::Movability: Encodable<__E>,
-    __I::PolyFnSig: Encodable<__E>,
-    __I::ListBinderExistentialPredicate: Encodable<__E>,
-    __I::BinderListTy: Encodable<__E>,
-    __I::ListTy: Encodable<__E>,
-    __I::ProjectionTy: Encodable<__E>,
-    __I::ParamTy: Encodable<__E>,
-    __I::BoundTy: Encodable<__E>,
-    __I::PlaceholderType: Encodable<__E>,
-    __I::InferTy: Encodable<__E>,
-    __I::DelaySpanBugEmitted: Encodable<__E>,
-    __I::PredicateKind: Encodable<__E>,
-    __I::AllocId: Encodable<__E>,
+    I::DelaySpanBugEmitted: Encodable<E>,
+    I::AdtDef: Encodable<E>,
+    I::SubstsRef: Encodable<E>,
+    I::DefId: Encodable<E>,
+    I::Ty: Encodable<E>,
+    I::Const: Encodable<E>,
+    I::Region: Encodable<E>,
+    I::TypeAndMut: Encodable<E>,
+    I::Mutability: Encodable<E>,
+    I::Movability: Encodable<E>,
+    I::PolyFnSig: Encodable<E>,
+    I::ListBinderExistentialPredicate: Encodable<E>,
+    I::BinderListTy: Encodable<E>,
+    I::ListTy: Encodable<E>,
+    I::ProjectionTy: Encodable<E>,
+    I::ParamTy: Encodable<E>,
+    I::BoundTy: Encodable<E>,
+    I::PlaceholderType: Encodable<E>,
+    I::InferTy: Encodable<E>,
+    I::DelaySpanBugEmitted: Encodable<E>,
+    I::PredicateKind: Encodable<E>,
+    I::AllocId: Encodable<E>,
 {
-    fn encode(&self, e: &mut __E) -> Result<(), <__E as rustc_serialize::Encoder>::Error> {
+    fn encode(&self, e: &mut E) -> Result<(), <E as rustc_serialize::Encoder>::Error> {
         rustc_serialize::Encoder::emit_enum(e, |e| {
-            use rustc_type_ir::TyKind::*;
+            let disc = discriminant(self);
             match self {
-                Bool => e.emit_enum_variant("Bool", 0, 0, |_| Ok(())),
-                Char => e.emit_enum_variant("Char", 1, 0, |_| Ok(())),
-                Int(i) => e.emit_enum_variant("Int", 2, 1, |e| {
+                Bool => e.emit_enum_variant("Bool", disc, 0, |_| Ok(())),
+                Char => e.emit_enum_variant("Char", disc, 0, |_| Ok(())),
+                Int(i) => e.emit_enum_variant("Int", disc, 1, |e| {
                     e.emit_enum_variant_arg(true, |e| i.encode(e))?;
                     Ok(())
                 }),
-                Uint(u) => e.emit_enum_variant("Uint", 3, 1, |e| {
+                Uint(u) => e.emit_enum_variant("Uint", disc, 1, |e| {
                     e.emit_enum_variant_arg(true, |e| u.encode(e))?;
                     Ok(())
                 }),
-                Float(f) => e.emit_enum_variant("Float", 4, 1, |e| {
+                Float(f) => e.emit_enum_variant("Float", disc, 1, |e| {
                     e.emit_enum_variant_arg(true, |e| f.encode(e))?;
                     Ok(())
                 }),
-                Adt(adt, substs) => e.emit_enum_variant("Adt", 5, 2, |e| {
+                Adt(adt, substs) => e.emit_enum_variant("Adt", disc, 2, |e| {
                     e.emit_enum_variant_arg(true, |e| adt.encode(e))?;
                     e.emit_enum_variant_arg(false, |e| substs.encode(e))?;
                     Ok(())
                 }),
-                Foreign(def_id) => e.emit_enum_variant("Foreign", 6, 1, |e| {
+                Foreign(def_id) => e.emit_enum_variant("Foreign", disc, 1, |e| {
                     e.emit_enum_variant_arg(true, |e| def_id.encode(e))?;
                     Ok(())
                 }),
-                Str => e.emit_enum_variant("Str", 7, 0, |_| Ok(())),
-                Array(t, c) => e.emit_enum_variant("Array", 8, 2, |e| {
+                Str => e.emit_enum_variant("Str", disc, 0, |_| Ok(())),
+                Array(t, c) => e.emit_enum_variant("Array", disc, 2, |e| {
                     e.emit_enum_variant_arg(true, |e| t.encode(e))?;
                     e.emit_enum_variant_arg(false, |e| c.encode(e))?;
                     Ok(())
                 }),
-                Slice(t) => e.emit_enum_variant("Slice", 9, 1, |e| {
+                Slice(t) => e.emit_enum_variant("Slice", disc, 1, |e| {
                     e.emit_enum_variant_arg(true, |e| t.encode(e))?;
                     Ok(())
                 }),
-                RawPtr(tam) => e.emit_enum_variant("RawPtr", 10, 1, |e| {
+                RawPtr(tam) => e.emit_enum_variant("RawPtr", disc, 1, |e| {
                     e.emit_enum_variant_arg(true, |e| tam.encode(e))?;
                     Ok(())
                 }),
-                Ref(r, t, m) => e.emit_enum_variant("Ref", 11, 3, |e| {
+                Ref(r, t, m) => e.emit_enum_variant("Ref", disc, 3, |e| {
                     e.emit_enum_variant_arg(true, |e| r.encode(e))?;
                     e.emit_enum_variant_arg(false, |e| t.encode(e))?;
                     e.emit_enum_variant_arg(false, |e| m.encode(e))?;
                     Ok(())
                 }),
-                FnDef(def_id, substs) => e.emit_enum_variant("FnDef", 12, 2, |e| {
+                FnDef(def_id, substs) => e.emit_enum_variant("FnDef", disc, 2, |e| {
                     e.emit_enum_variant_arg(true, |e| def_id.encode(e))?;
                     e.emit_enum_variant_arg(false, |e| substs.encode(e))?;
                     Ok(())
                 }),
-                FnPtr(polyfnsig) => e.emit_enum_variant("FnPtr", 13, 1, |e| {
+                FnPtr(polyfnsig) => e.emit_enum_variant("FnPtr", disc, 1, |e| {
                     e.emit_enum_variant_arg(true, |e| polyfnsig.encode(e))?;
                     Ok(())
                 }),
-                Dynamic(l, r) => e.emit_enum_variant("Dynamic", 14, 2, |e| {
+                Dynamic(l, r) => e.emit_enum_variant("Dynamic", disc, 2, |e| {
                     e.emit_enum_variant_arg(true, |e| l.encode(e))?;
                     e.emit_enum_variant_arg(false, |e| r.encode(e))?;
                     Ok(())
                 }),
-                Closure(def_id, substs) => e.emit_enum_variant("Closure", 15, 2, |e| {
+                Closure(def_id, substs) => e.emit_enum_variant("Closure", disc, 2, |e| {
                     e.emit_enum_variant_arg(true, |e| def_id.encode(e))?;
                     e.emit_enum_variant_arg(false, |e| substs.encode(e))?;
                     Ok(())
                 }),
-                Generator(def_id, substs, m) => e.emit_enum_variant("Generator", 16, 3, |e| {
+                Generator(def_id, substs, m) => e.emit_enum_variant("Generator", disc, 3, |e| {
                     e.emit_enum_variant_arg(true, |e| def_id.encode(e))?;
                     e.emit_enum_variant_arg(false, |e| substs.encode(e))?;
                     e.emit_enum_variant_arg(false, |e| m.encode(e))?;
                     Ok(())
                 }),
-                GeneratorWitness(b) => e.emit_enum_variant("GeneratorWitness", 17, 1, |e| {
+                GeneratorWitness(b) => e.emit_enum_variant("GeneratorWitness", disc, 1, |e| {
                     e.emit_enum_variant_arg(true, |e| b.encode(e))?;
                     Ok(())
                 }),
-                Never => e.emit_enum_variant("Never", 18, 0, |_| Ok(())),
-                Tuple(substs) => e.emit_enum_variant("Tuple", 19, 1, |e| {
+                Never => e.emit_enum_variant("Never", disc, 0, |_| Ok(())),
+                Tuple(substs) => e.emit_enum_variant("Tuple", disc, 1, |e| {
                     e.emit_enum_variant_arg(true, |e| substs.encode(e))?;
                     Ok(())
                 }),
-                Projection(p) => e.emit_enum_variant("Projection", 20, 1, |e| {
+                Projection(p) => e.emit_enum_variant("Projection", disc, 1, |e| {
                     e.emit_enum_variant_arg(true, |e| p.encode(e))?;
                     Ok(())
                 }),
-                Opaque(def_id, substs) => e.emit_enum_variant("Opaque", 21, 2, |e| {
+                Opaque(def_id, substs) => e.emit_enum_variant("Opaque", disc, 2, |e| {
                     e.emit_enum_variant_arg(true, |e| def_id.encode(e))?;
                     e.emit_enum_variant_arg(false, |e| substs.encode(e))?;
                     Ok(())
                 }),
-                Param(p) => e.emit_enum_variant("Param", 22, 1, |e| {
+                Param(p) => e.emit_enum_variant("Param", disc, 1, |e| {
                     e.emit_enum_variant_arg(true, |e| p.encode(e))?;
                     Ok(())
                 }),
-                Bound(d, b) => e.emit_enum_variant("Bound", 23, 2, |e| {
+                Bound(d, b) => e.emit_enum_variant("Bound", disc, 2, |e| {
                     e.emit_enum_variant_arg(true, |e| d.encode(e))?;
                     e.emit_enum_variant_arg(false, |e| b.encode(e))?;
                     Ok(())
                 }),
-                Placeholder(p) => e.emit_enum_variant("Placeholder", 24, 1, |e| {
+                Placeholder(p) => e.emit_enum_variant("Placeholder", disc, 1, |e| {
                     e.emit_enum_variant_arg(true, |e| p.encode(e))?;
                     Ok(())
                 }),
-                Infer(i) => e.emit_enum_variant("Infer", 25, 1, |e| {
+                Infer(i) => e.emit_enum_variant("Infer", disc, 1, |e| {
                     e.emit_enum_variant_arg(true, |e| i.encode(e))?;
                     Ok(())
                 }),
-                Error(d) => e.emit_enum_variant("Error", 26, 1, |e| {
+                Error(d) => e.emit_enum_variant("Error", disc, 1, |e| {
                     e.emit_enum_variant_arg(true, |e| d.encode(e))?;
                     Ok(())
                 }),
@@ -373,92 +819,82 @@ where
     }
 }
 
-#[allow(rustc::usage_of_ty_tykind)]
-impl<__I: Interner, __D: TyDecoder<I = __I>> Decodable<__D> for TyKind<__I>
+impl<I: Interner, D: TyDecoder<I = I>> Decodable<D> for TyKind<I>
 where
-    __I::DelaySpanBugEmitted: Decodable<__D>,
-    __I::AdtDef: Decodable<__D>,
-    __I::SubstsRef: Decodable<__D>,
-    __I::DefId: Decodable<__D>,
-    __I::Ty: Decodable<__D>,
-    __I::Const: Decodable<__D>,
-    __I::Region: Decodable<__D>,
-    __I::TypeAndMut: Decodable<__D>,
-    __I::Mutability: Decodable<__D>,
-    __I::Movability: Decodable<__D>,
-    __I::PolyFnSig: Decodable<__D>,
-    __I::ListBinderExistentialPredicate: Decodable<__D>,
-    __I::BinderListTy: Decodable<__D>,
-    __I::ListTy: Decodable<__D>,
-    __I::ProjectionTy: Decodable<__D>,
-    __I::ParamTy: Decodable<__D>,
-    __I::BoundTy: Decodable<__D>,
-    __I::PlaceholderType: Decodable<__D>,
-    __I::InferTy: Decodable<__D>,
-    __I::DelaySpanBugEmitted: Decodable<__D>,
-    __I::PredicateKind: Decodable<__D>,
-    __I::AllocId: Decodable<__D>,
+    I::DelaySpanBugEmitted: Decodable<D>,
+    I::AdtDef: Decodable<D>,
+    I::SubstsRef: Decodable<D>,
+    I::DefId: Decodable<D>,
+    I::Ty: Decodable<D>,
+    I::Const: Decodable<D>,
+    I::Region: Decodable<D>,
+    I::TypeAndMut: Decodable<D>,
+    I::Mutability: Decodable<D>,
+    I::Movability: Decodable<D>,
+    I::PolyFnSig: Decodable<D>,
+    I::ListBinderExistentialPredicate: Decodable<D>,
+    I::BinderListTy: Decodable<D>,
+    I::ListTy: Decodable<D>,
+    I::ProjectionTy: Decodable<D>,
+    I::ParamTy: Decodable<D>,
+    I::BoundTy: Decodable<D>,
+    I::PlaceholderType: Decodable<D>,
+    I::InferTy: Decodable<D>,
+    I::DelaySpanBugEmitted: Decodable<D>,
+    I::PredicateKind: Decodable<D>,
+    I::AllocId: Decodable<D>,
 {
-    fn decode(__decoder: &mut __D) -> Self {
-        use TyKind::*;
-
-        match rustc_serialize::Decoder::read_usize(__decoder) {
+    fn decode(d: &mut D) -> Self {
+        match rustc_serialize::Decoder::read_usize(d) {
             0 => Bool,
             1 => Char,
-            2 => Int(rustc_serialize::Decodable::decode(__decoder)),
-            3 => Uint(rustc_serialize::Decodable::decode(__decoder)),
-            4 => Float(rustc_serialize::Decodable::decode(__decoder)),
-            5 => Adt(
-                rustc_serialize::Decodable::decode(__decoder),
-                rustc_serialize::Decodable::decode(__decoder),
-            ),
-            6 => Foreign(rustc_serialize::Decodable::decode(__decoder)),
+            2 => Int(rustc_serialize::Decodable::decode(d)),
+            3 => Uint(rustc_serialize::Decodable::decode(d)),
+            4 => Float(rustc_serialize::Decodable::decode(d)),
+            5 => Adt(rustc_serialize::Decodable::decode(d), rustc_serialize::Decodable::decode(d)),
+            6 => Foreign(rustc_serialize::Decodable::decode(d)),
             7 => Str,
-            8 => Array(
-                rustc_serialize::Decodable::decode(__decoder),
-                rustc_serialize::Decodable::decode(__decoder),
-            ),
-            9 => Slice(rustc_serialize::Decodable::decode(__decoder)),
-            10 => RawPtr(rustc_serialize::Decodable::decode(__decoder)),
+            8 => {
+                Array(rustc_serialize::Decodable::decode(d), rustc_serialize::Decodable::decode(d))
+            }
+            9 => Slice(rustc_serialize::Decodable::decode(d)),
+            10 => RawPtr(rustc_serialize::Decodable::decode(d)),
             11 => Ref(
-                rustc_serialize::Decodable::decode(__decoder),
-                rustc_serialize::Decodable::decode(__decoder),
-                rustc_serialize::Decodable::decode(__decoder),
-            ),
-            12 => FnDef(
-                rustc_serialize::Decodable::decode(__decoder),
-                rustc_serialize::Decodable::decode(__decoder),
+                rustc_serialize::Decodable::decode(d),
+                rustc_serialize::Decodable::decode(d),
+                rustc_serialize::Decodable::decode(d),
             ),
-            13 => FnPtr(rustc_serialize::Decodable::decode(__decoder)),
+            12 => {
+                FnDef(rustc_serialize::Decodable::decode(d), rustc_serialize::Decodable::decode(d))
+            }
+            13 => FnPtr(rustc_serialize::Decodable::decode(d)),
             14 => Dynamic(
-                rustc_serialize::Decodable::decode(__decoder),
-                rustc_serialize::Decodable::decode(__decoder),
+                rustc_serialize::Decodable::decode(d),
+                rustc_serialize::Decodable::decode(d),
             ),
             15 => Closure(
-                rustc_serialize::Decodable::decode(__decoder),
-                rustc_serialize::Decodable::decode(__decoder),
+                rustc_serialize::Decodable::decode(d),
+                rustc_serialize::Decodable::decode(d),
             ),
             16 => Generator(
-                rustc_serialize::Decodable::decode(__decoder),
-                rustc_serialize::Decodable::decode(__decoder),
-                rustc_serialize::Decodable::decode(__decoder),
+                rustc_serialize::Decodable::decode(d),
+                rustc_serialize::Decodable::decode(d),
+                rustc_serialize::Decodable::decode(d),
             ),
-            17 => GeneratorWitness(rustc_serialize::Decodable::decode(__decoder)),
+            17 => GeneratorWitness(rustc_serialize::Decodable::decode(d)),
             18 => Never,
-            19 => Tuple(rustc_serialize::Decodable::decode(__decoder)),
-            20 => Projection(rustc_serialize::Decodable::decode(__decoder)),
-            21 => Opaque(
-                rustc_serialize::Decodable::decode(__decoder),
-                rustc_serialize::Decodable::decode(__decoder),
-            ),
-            22 => Param(rustc_serialize::Decodable::decode(__decoder)),
-            23 => Bound(
-                rustc_serialize::Decodable::decode(__decoder),
-                rustc_serialize::Decodable::decode(__decoder),
-            ),
-            24 => Placeholder(rustc_serialize::Decodable::decode(__decoder)),
-            25 => Infer(rustc_serialize::Decodable::decode(__decoder)),
-            26 => Error(rustc_serialize::Decodable::decode(__decoder)),
+            19 => Tuple(rustc_serialize::Decodable::decode(d)),
+            20 => Projection(rustc_serialize::Decodable::decode(d)),
+            21 => {
+                Opaque(rustc_serialize::Decodable::decode(d), rustc_serialize::Decodable::decode(d))
+            }
+            22 => Param(rustc_serialize::Decodable::decode(d)),
+            23 => {
+                Bound(rustc_serialize::Decodable::decode(d), rustc_serialize::Decodable::decode(d))
+            }
+            24 => Placeholder(rustc_serialize::Decodable::decode(d)),
+            25 => Infer(rustc_serialize::Decodable::decode(d)),
+            26 => Error(rustc_serialize::Decodable::decode(d)),
             _ => panic!(
                 "{}",
                 format!(
diff --git a/src/test/run-make-fulldeps/obtain-borrowck/driver.rs b/src/test/run-make-fulldeps/obtain-borrowck/driver.rs
index c3b82aa853c..8f78bda033e 100644
--- a/src/test/run-make-fulldeps/obtain-borrowck/driver.rs
+++ b/src/test/run-make-fulldeps/obtain-borrowck/driver.rs
@@ -154,7 +154,7 @@ fn get_bodies<'tcx>(tcx: TyCtxt<'tcx>) -> Vec<(String, BodyWithBorrowckFacts<'tc
                 // SAFETY: For soundness we need to ensure that the bodies have
                 // the same lifetime (`'tcx`), which they had before they were
                 // stored in the thread local.
-                (def_path.to_string_no_crate_verbose(), body)
+                (def_path.to_string_no_crate_verbose(), unsafe { std::mem::transmute(body) })
             })
             .collect()
     })
diff --git a/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.rs b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.rs
index 973294e985f..2cb1ed6fcb7 100644
--- a/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.rs
+++ b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.rs
@@ -3,41 +3,43 @@
 #![feature(rustc_private)]
 
 extern crate rustc_middle;
+extern crate rustc_type_ir;
 
 use rustc_middle::ty::{self, Ty, TyKind};
+use rustc_type_ir::{Interner, TyKind as IrTyKind};
 
 #[deny(rustc::usage_of_ty_tykind)]
 fn main() {
     let kind = TyKind::Bool; //~ ERROR usage of `ty::TyKind::<kind>`
 
     match kind {
-        TyKind::Bool => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Char => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Int(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Uint(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Float(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Adt(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Foreign(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Str => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Array(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Slice(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::RawPtr(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Ref(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::FnDef(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::FnPtr(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Dynamic(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Closure(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Generator(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Bool => (),                 //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Char => (),                 //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Int(..) => (),              //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Uint(..) => (),             //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Float(..) => (),            //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Adt(..) => (),              //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Foreign(..) => (),          //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Str => (),                  //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Array(..) => (),            //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Slice(..) => (),            //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::RawPtr(..) => (),           //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Ref(..) => (),              //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::FnDef(..) => (),            //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::FnPtr(..) => (),            //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Dynamic(..) => (),          //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Closure(..) => (),          //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Generator(..) => (),        //~ ERROR usage of `ty::TyKind::<kind>`
         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::Param(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Bound(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Placeholder(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Infer(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
-        TyKind::Error(_) => (), //~ 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::Param(..) => (),            //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Bound(..) => (),            //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Placeholder(..) => (),      //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Infer(..) => (),            //~ ERROR usage of `ty::TyKind::<kind>`
+        TyKind::Error(_) => (),             //~ ERROR usage of `ty::TyKind::<kind>`
     }
 
     if let ty::Int(int_ty) = kind {}
@@ -45,4 +47,10 @@ fn main() {
     if let TyKind::Int(int_ty) = kind {} //~ ERROR usage of `ty::TyKind::<kind>`
 
     fn ty_kind(ty_bad: TyKind<'_>, ty_good: Ty<'_>) {} //~ ERROR usage of `ty::TyKind`
+
+    fn ir_ty_kind<I: Interner>(bad: IrTyKind<I>) -> IrTyKind<I> {
+        //~^ ERROR usage of `ty::TyKind`
+        //~| ERROR usage of `ty::TyKind`
+        IrTyKind::Bool //~ ERROR usage of `ty::TyKind::<kind>`
+    }
 }
diff --git a/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr
index d6e4c85c190..171f49087d6 100644
--- a/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr
+++ b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr
@@ -1,190 +1,214 @@
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:11:16
+  --> $DIR/ty_tykind_usage.rs:13:16
    |
 LL |     let kind = TyKind::Bool;
-   |                ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |                ^^^^^^ help: try using `ty::<kind>` directly: `ty`
    |
 note: the lint level is defined here
-  --> $DIR/ty_tykind_usage.rs:9:8
+  --> $DIR/ty_tykind_usage.rs:11:8
    |
 LL | #[deny(rustc::usage_of_ty_tykind)]
    |        ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:14:9
+  --> $DIR/ty_tykind_usage.rs:16:9
    |
 LL |         TyKind::Bool => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:15:9
+  --> $DIR/ty_tykind_usage.rs:17:9
    |
 LL |         TyKind::Char => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:16:9
+  --> $DIR/ty_tykind_usage.rs:18:9
    |
 LL |         TyKind::Int(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:17:9
+  --> $DIR/ty_tykind_usage.rs:19:9
    |
 LL |         TyKind::Uint(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:18:9
+  --> $DIR/ty_tykind_usage.rs:20:9
    |
 LL |         TyKind::Float(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:19:9
+  --> $DIR/ty_tykind_usage.rs:21:9
    |
 LL |         TyKind::Adt(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:20:9
+  --> $DIR/ty_tykind_usage.rs:22:9
    |
 LL |         TyKind::Foreign(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:21:9
+  --> $DIR/ty_tykind_usage.rs:23:9
    |
 LL |         TyKind::Str => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:22:9
+  --> $DIR/ty_tykind_usage.rs:24:9
    |
 LL |         TyKind::Array(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:23:9
+  --> $DIR/ty_tykind_usage.rs:25:9
    |
 LL |         TyKind::Slice(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:24:9
+  --> $DIR/ty_tykind_usage.rs:26:9
    |
 LL |         TyKind::RawPtr(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:25:9
+  --> $DIR/ty_tykind_usage.rs:27:9
    |
 LL |         TyKind::Ref(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:26:9
+  --> $DIR/ty_tykind_usage.rs:28:9
    |
 LL |         TyKind::FnDef(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:27:9
+  --> $DIR/ty_tykind_usage.rs:29:9
    |
 LL |         TyKind::FnPtr(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:28:9
+  --> $DIR/ty_tykind_usage.rs:30:9
    |
 LL |         TyKind::Dynamic(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:29:9
+  --> $DIR/ty_tykind_usage.rs:31:9
    |
 LL |         TyKind::Closure(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:30:9
+  --> $DIR/ty_tykind_usage.rs:32:9
    |
 LL |         TyKind::Generator(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:31:9
+  --> $DIR/ty_tykind_usage.rs:33:9
    |
 LL |         TyKind::GeneratorWitness(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:32:9
+  --> $DIR/ty_tykind_usage.rs:34:9
    |
 LL |         TyKind::Never => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:33:9
+  --> $DIR/ty_tykind_usage.rs:35:9
    |
 LL |         TyKind::Tuple(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:34:9
+  --> $DIR/ty_tykind_usage.rs:36:9
    |
 LL |         TyKind::Projection(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:35:9
+  --> $DIR/ty_tykind_usage.rs:37:9
    |
 LL |         TyKind::Opaque(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:36:9
+  --> $DIR/ty_tykind_usage.rs:38:9
    |
 LL |         TyKind::Param(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:37:9
+  --> $DIR/ty_tykind_usage.rs:39:9
    |
 LL |         TyKind::Bound(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:38:9
+  --> $DIR/ty_tykind_usage.rs:40:9
    |
 LL |         TyKind::Placeholder(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:39:9
+  --> $DIR/ty_tykind_usage.rs:41:9
    |
 LL |         TyKind::Infer(..) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:40:9
+  --> $DIR/ty_tykind_usage.rs:42:9
    |
 LL |         TyKind::Error(_) => (),
-   |         ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |         ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind::<kind>`
-  --> $DIR/ty_tykind_usage.rs:45:12
+  --> $DIR/ty_tykind_usage.rs:47:12
    |
 LL |     if let TyKind::Int(int_ty) = kind {}
-   |            ^^^^^^ help: try using ty::<kind> directly: `ty`
+   |            ^^^^^^ help: try using `ty::<kind>` directly: `ty`
 
 error: usage of `ty::TyKind`
-  --> $DIR/ty_tykind_usage.rs:47:24
+  --> $DIR/ty_tykind_usage.rs:49:24
    |
 LL |     fn ty_kind(ty_bad: TyKind<'_>, ty_good: Ty<'_>) {}
    |                        ^^^^^^^^^^
    |
    = help: try using `Ty` instead
 
-error: aborting due to 30 previous errors
+error: usage of `ty::TyKind`
+  --> $DIR/ty_tykind_usage.rs:51:37
+   |
+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
+   |
+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
+   |
+LL |         IrTyKind::Bool
+   |         --------^^^^^^
+   |         |
+   |         help: try using `ty::<kind>` directly: `ty`
+
+error: aborting due to 33 previous errors