From 8ab0c4cbf39916f4860b2bae376d0d4ca18e2112 Mon Sep 17 00:00:00 2001
From: Nicholas Nethercote <n.nethercote@gmail.com>
Date: Wed, 25 Mar 2026 13:53:53 +1100
Subject: [PATCH 1/7] Remove unused `Erasable` impls.

There are many!
---
 compiler/rustc_middle/src/query/erase.rs | 115 +----------------------
 1 file changed, 1 insertion(+), 114 deletions(-)

diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs
index 036aa2ed05a4a..a28e8f23e045f 100644
--- a/compiler/rustc_middle/src/query/erase.rs
+++ b/compiler/rustc_middle/src/query/erase.rs
@@ -108,10 +108,6 @@ impl<T> Erasable for &'_ [T] {
     type Storage = [u8; size_of::<&'static [()]>()];
 }
 
-impl Erasable for &'_ OsStr {
-    type Storage = [u8; size_of::<&'static OsStr>()];
-}
-
 impl<T> Erasable for &'_ ty::List<T> {
     type Storage = [u8; size_of::<&'static ty::List<()>>()];
 }
@@ -120,26 +116,14 @@ impl<T> Erasable for &'_ ty::ListWithCachedTypeInfo<T> {
     type Storage = [u8; size_of::<&'static ty::ListWithCachedTypeInfo<()>>()];
 }
 
-impl<I: rustc_index::Idx, T> Erasable for &'_ rustc_index::IndexSlice<I, T> {
-    type Storage = [u8; size_of::<&'static rustc_index::IndexSlice<u32, ()>>()];
-}
-
 impl<T> Erasable for Result<&'_ T, traits::query::NoSolution> {
     type Storage = [u8; size_of::<Result<&'static (), traits::query::NoSolution>>()];
 }
 
-impl<T> Erasable for Result<&'_ [T], traits::query::NoSolution> {
-    type Storage = [u8; size_of::<Result<&'static [()], traits::query::NoSolution>>()];
-}
-
 impl<T> Erasable for Result<&'_ T, rustc_errors::ErrorGuaranteed> {
     type Storage = [u8; size_of::<Result<&'static (), rustc_errors::ErrorGuaranteed>>()];
 }
 
-impl<T> Erasable for Result<&'_ [T], rustc_errors::ErrorGuaranteed> {
-    type Storage = [u8; size_of::<Result<&'static [()], rustc_errors::ErrorGuaranteed>>()];
-}
-
 impl<T> Erasable for Result<&'_ T, traits::CodegenObligationError> {
     type Storage = [u8; size_of::<Result<&'static (), traits::CodegenObligationError>>()];
 }
@@ -229,10 +213,6 @@ impl Erasable for Option<&'_ OsStr> {
     type Storage = [u8; size_of::<Option<&'static OsStr>>()];
 }
 
-impl Erasable for Option<mir::DestructuredConstant<'_>> {
-    type Storage = [u8; size_of::<Option<mir::DestructuredConstant<'static>>>()];
-}
-
 impl Erasable for ty::ImplTraitHeader<'_> {
     type Storage = [u8; size_of::<ty::ImplTraitHeader<'static>>()];
 }
@@ -262,10 +242,6 @@ impl Erasable for ty::Binder<'_, ty::CoroutineWitnessTypes<TyCtxt<'_>>> {
         [u8; size_of::<ty::Binder<'static, ty::CoroutineWitnessTypes<TyCtxt<'static>>>>()];
 }
 
-impl Erasable for ty::Binder<'_, &'_ ty::List<Ty<'_>>> {
-    type Storage = [u8; size_of::<ty::Binder<'static, &'static ty::List<Ty<'static>>>>()];
-}
-
 impl<T0, T1> Erasable for (&'_ T0, &'_ T1) {
     type Storage = [u8; size_of::<(&'static (), &'static ())>()];
 }
@@ -274,14 +250,6 @@ impl<T0> Erasable for (solve::QueryResult<'_>, &'_ T0) {
     type Storage = [u8; size_of::<(solve::QueryResult<'static>, &'static ())>()];
 }
 
-impl<T0, T1> Erasable for (&'_ T0, &'_ [T1]) {
-    type Storage = [u8; size_of::<(&'static (), &'static [()])>()];
-}
-
-impl<T0, T1> Erasable for (&'_ [T0], &'_ [T1]) {
-    type Storage = [u8; size_of::<(&'static [()], &'static [()])>()];
-}
-
 impl<T0> Erasable for (&'_ T0, Result<(), ErrorGuaranteed>) {
     type Storage = [u8; size_of::<(&'static (), Result<(), ErrorGuaranteed>)>()];
 }
@@ -308,109 +276,54 @@ impl_erasable_for_simple_types! {
     Option<rustc_hir::DefaultBodyStability>,
     Option<rustc_hir::Stability>,
     Option<rustc_data_structures::svh::Svh>,
-    Option<rustc_hir::def::DefKind>,
     Option<rustc_hir::CoroutineKind>,
-    Option<rustc_hir::HirId>,
     Option<rustc_middle::middle::stability::DeprecationEntry>,
     Option<rustc_middle::ty::AsyncDestructor>,
     Option<rustc_middle::ty::Destructor>,
-    Option<rustc_middle::ty::ImplTraitInTraitData>,
     Option<rustc_middle::ty::ScalarInt>,
     Option<rustc_span::def_id::CrateNum>,
     Option<rustc_span::def_id::DefId>,
     Option<rustc_span::def_id::LocalDefId>,
     Option<rustc_span::Span>,
-    Option<rustc_abi::FieldIdx>,
     Option<rustc_target::spec::PanicStrategy>,
     Option<usize>,
     Option<rustc_middle::ty::IntrinsicDef>,
     Option<rustc_abi::Align>,
     Result<(), rustc_errors::ErrorGuaranteed>,
-    Result<(), rustc_middle::traits::query::NoSolution>,
     Result<rustc_middle::traits::EvaluationResult, rustc_middle::traits::OverflowError>,
     Result<rustc_middle::ty::adjustment::CoerceUnsizedInfo, rustc_errors::ErrorGuaranteed>,
     Result<mir::ConstValue, mir::interpret::ErrorHandled>,
-    rustc_abi::ReprOptions,
-    rustc_ast::expand::allocator::AllocatorKind,
-    rustc_hir::DefaultBodyStability,
-    rustc_hir::attrs::Deprecation,
-    rustc_hir::attrs::EiiDecl,
-    rustc_hir::attrs::EiiImpl,
     rustc_data_structures::svh::Svh,
-    rustc_errors::ErrorGuaranteed,
     rustc_hir::Constness,
-    rustc_hir::ConstStability,
     rustc_hir::def_id::DefId,
-    rustc_hir::def_id::DefIndex,
-    rustc_hir::def_id::LocalDefId,
-    rustc_hir::def_id::LocalModDefId,
     rustc_hir::def::DefKind,
     rustc_hir::Defaultness,
-    rustc_hir::definitions::DefKey,
-    rustc_hir::CoroutineKind,
     rustc_hir::HirId,
-    rustc_hir::IsAsync,
-    rustc_hir::ItemLocalId,
-    rustc_hir::LangItem,
     rustc_hir::OpaqueTyOrigin<rustc_hir::def_id::DefId>,
-    rustc_hir::OwnerId,
-    rustc_hir::Stability,
-    rustc_hir::Upvar,
-    rustc_middle::middle::deduced_param_attrs::DeducedParamAttrs,
-    rustc_middle::middle::dependency_format::Linkage,
-    rustc_middle::middle::exported_symbols::SymbolExportInfo,
     rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault,
-    rustc_middle::middle::resolve_bound_vars::ResolvedArg,
-    rustc_middle::middle::stability::DeprecationEntry,
     rustc_middle::mir::ConstQualifs,
     rustc_middle::mir::ConstValue,
     rustc_middle::mir::interpret::AllocId,
-    rustc_middle::mir::interpret::CtfeProvenance,
-    rustc_middle::mir::interpret::ErrorHandled,
-    rustc_middle::thir::ExprId,
-    rustc_middle::traits::CodegenObligationError,
-    rustc_middle::traits::EvaluationResult,
-    rustc_middle::traits::OverflowError,
-    rustc_middle::traits::query::NoSolution,
-    rustc_middle::traits::WellFormedLoc,
-    rustc_middle::ty::adjustment::CoerceUnsizedInfo,
     rustc_middle::ty::AssocItem,
-    rustc_middle::ty::AssocContainer,
     rustc_middle::ty::Asyncness,
-    rustc_middle::ty::AsyncDestructor,
     rustc_middle::ty::AnonConstKind,
-    rustc_middle::ty::Destructor,
-    rustc_middle::ty::fast_reject::SimplifiedType,
-    rustc_middle::ty::ImplPolarity,
-    rustc_middle::ty::util::AlwaysRequiresDrop,
     rustc_middle::ty::Visibility<rustc_span::def_id::DefId>,
     rustc_middle::middle::codegen_fn_attrs::SanitizerFnAttrs,
-    rustc_session::config::CrateType,
-    rustc_session::config::EntryFnType,
     rustc_session::config::OptLevel,
     rustc_session::config::SymbolManglingVersion,
     rustc_session::cstore::CrateDepKind,
-    rustc_session::cstore::ExternCrate,
-    rustc_session::cstore::LinkagePreference,
     rustc_session::Limits,
-    rustc_session::lint::LintExpectationId,
-    rustc_span::def_id::CrateNum,
-    rustc_span::def_id::DefPathHash,
-    rustc_span::ExpnHash,
     rustc_span::ExpnId,
     rustc_span::Span,
     rustc_span::Symbol,
-    rustc_span::Ident,
     rustc_target::spec::PanicStrategy,
-    rustc_type_ir::Variance,
-    u32,
     usize,
 }
 
 macro_rules! impl_erasable_for_single_lifetime_types {
     ($($($fake_path:ident)::+),+ $(,)?) => {
         $(
-            impl<'tcx> Erasable for $($fake_path)::+<'tcx> {
+            impl Erasable for $($fake_path)::+<'_> {
                 type Storage = [u8; size_of::<$($fake_path)::+<'static>>()];
             }
         )*
@@ -424,43 +337,17 @@ macro_rules! impl_erasable_for_single_lifetime_types {
 // lifetime can probably be migrated here.
 impl_erasable_for_single_lifetime_types! {
     // FIXME(#151565): Add `tidy-alphabetical-{start,end}` and sort this.
-    rustc_middle::middle::exported_symbols::ExportedSymbol,
-    rustc_middle::mir::Const,
-    rustc_middle::mir::DestructuredConstant,
-    rustc_middle::mir::ConstAlloc,
-    rustc_middle::mir::interpret::GlobalId,
     rustc_middle::mir::interpret::EvalStaticInitializerRawResult,
     rustc_middle::mir::mono::MonoItemPartitions,
     rustc_middle::traits::query::MethodAutoderefStepsResult,
-    rustc_middle::traits::query::type_op::AscribeUserType,
-    rustc_middle::traits::query::type_op::Eq,
-    rustc_middle::traits::query::type_op::ProvePredicate,
-    rustc_middle::traits::query::type_op::Subtype,
     rustc_middle::ty::AdtDef,
-    rustc_middle::ty::AliasTy,
-    rustc_middle::ty::ClauseKind,
     rustc_middle::ty::ClosureTypeInfo,
     rustc_middle::ty::Const,
-    rustc_middle::ty::DestructuredAdtConst,
-    rustc_middle::ty::ExistentialTraitRef,
-    rustc_middle::ty::FnSig,
-    rustc_middle::ty::GenericArg,
     rustc_middle::ty::GenericPredicates,
     rustc_middle::ty::ConstConditions,
     rustc_middle::ty::inhabitedness::InhabitedPredicate,
-    rustc_middle::ty::Instance,
-    rustc_middle::ty::BoundVariableKind,
-    rustc_middle::ty::InstanceKind,
-    rustc_middle::ty::layout::FnAbiError,
-    rustc_middle::ty::layout::LayoutError,
-    rustc_middle::ty::LitToConstInput,
     rustc_middle::ty::ParamEnv,
     rustc_middle::ty::TypingEnv,
-    rustc_middle::ty::Predicate,
     rustc_middle::ty::SymbolName,
-    rustc_middle::ty::TraitRef,
     rustc_middle::ty::Ty,
-    rustc_middle::ty::UnevaluatedConst,
-    rustc_middle::ty::ValTree,
-    rustc_middle::ty::VtblEntry,
 }

From 833bf3c375b2931826f65a8bad31658aa9b5ac5f Mon Sep 17 00:00:00 2001
From: Nicholas Nethercote <n.nethercote@gmail.com>
Date: Wed, 25 Mar 2026 14:16:33 +1100
Subject: [PATCH 2/7] Sort `impl_erasable_*` macro calls.

---
 compiler/rustc_middle/src/query/erase.rs | 36 +++++++++++++-----------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs
index a28e8f23e045f..66b0f01196d4a 100644
--- a/compiler/rustc_middle/src/query/erase.rs
+++ b/compiler/rustc_middle/src/query/erase.rs
@@ -267,57 +267,58 @@ macro_rules! impl_erasable_for_simple_types {
 // For concrete types with no lifetimes, the erased storage for `Foo` is
 // `[u8; size_of::<Foo>()]`.
 impl_erasable_for_simple_types! {
-    // FIXME(#151565): Add `tidy-alphabetical-{start,end}` and sort this.
+    // tidy-alphabetical-start
     (),
-    bool,
     Option<(rustc_span::def_id::DefId, rustc_session::config::EntryFnType)>,
+    Option<rustc_abi::Align>,
     Option<rustc_ast::expand::allocator::AllocatorKind>,
+    Option<rustc_data_structures::svh::Svh>,
     Option<rustc_hir::ConstStability>,
+    Option<rustc_hir::CoroutineKind>,
     Option<rustc_hir::DefaultBodyStability>,
     Option<rustc_hir::Stability>,
-    Option<rustc_data_structures::svh::Svh>,
-    Option<rustc_hir::CoroutineKind>,
     Option<rustc_middle::middle::stability::DeprecationEntry>,
     Option<rustc_middle::ty::AsyncDestructor>,
     Option<rustc_middle::ty::Destructor>,
+    Option<rustc_middle::ty::IntrinsicDef>,
     Option<rustc_middle::ty::ScalarInt>,
+    Option<rustc_span::Span>,
     Option<rustc_span::def_id::CrateNum>,
     Option<rustc_span::def_id::DefId>,
     Option<rustc_span::def_id::LocalDefId>,
-    Option<rustc_span::Span>,
     Option<rustc_target::spec::PanicStrategy>,
     Option<usize>,
-    Option<rustc_middle::ty::IntrinsicDef>,
-    Option<rustc_abi::Align>,
     Result<(), rustc_errors::ErrorGuaranteed>,
+    Result<mir::ConstValue, mir::interpret::ErrorHandled>,
     Result<rustc_middle::traits::EvaluationResult, rustc_middle::traits::OverflowError>,
     Result<rustc_middle::ty::adjustment::CoerceUnsizedInfo, rustc_errors::ErrorGuaranteed>,
-    Result<mir::ConstValue, mir::interpret::ErrorHandled>,
+    bool,
     rustc_data_structures::svh::Svh,
     rustc_hir::Constness,
-    rustc_hir::def_id::DefId,
-    rustc_hir::def::DefKind,
     rustc_hir::Defaultness,
     rustc_hir::HirId,
     rustc_hir::OpaqueTyOrigin<rustc_hir::def_id::DefId>,
+    rustc_hir::def::DefKind,
+    rustc_hir::def_id::DefId,
+    rustc_middle::middle::codegen_fn_attrs::SanitizerFnAttrs,
     rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault,
     rustc_middle::mir::ConstQualifs,
     rustc_middle::mir::ConstValue,
     rustc_middle::mir::interpret::AllocId,
+    rustc_middle::ty::AnonConstKind,
     rustc_middle::ty::AssocItem,
     rustc_middle::ty::Asyncness,
-    rustc_middle::ty::AnonConstKind,
     rustc_middle::ty::Visibility<rustc_span::def_id::DefId>,
-    rustc_middle::middle::codegen_fn_attrs::SanitizerFnAttrs,
+    rustc_session::Limits,
     rustc_session::config::OptLevel,
     rustc_session::config::SymbolManglingVersion,
     rustc_session::cstore::CrateDepKind,
-    rustc_session::Limits,
     rustc_span::ExpnId,
     rustc_span::Span,
     rustc_span::Symbol,
     rustc_target::spec::PanicStrategy,
     usize,
+    // tidy-alphabetical-end
 }
 
 macro_rules! impl_erasable_for_single_lifetime_types {
@@ -336,18 +337,19 @@ macro_rules! impl_erasable_for_single_lifetime_types {
 // FIXME(#151565): Some of the hand-written impls above that only use one
 // lifetime can probably be migrated here.
 impl_erasable_for_single_lifetime_types! {
-    // FIXME(#151565): Add `tidy-alphabetical-{start,end}` and sort this.
+    // tidy-alphabetical-start
     rustc_middle::mir::interpret::EvalStaticInitializerRawResult,
     rustc_middle::mir::mono::MonoItemPartitions,
     rustc_middle::traits::query::MethodAutoderefStepsResult,
     rustc_middle::ty::AdtDef,
     rustc_middle::ty::ClosureTypeInfo,
     rustc_middle::ty::Const,
-    rustc_middle::ty::GenericPredicates,
     rustc_middle::ty::ConstConditions,
-    rustc_middle::ty::inhabitedness::InhabitedPredicate,
+    rustc_middle::ty::GenericPredicates,
     rustc_middle::ty::ParamEnv,
-    rustc_middle::ty::TypingEnv,
     rustc_middle::ty::SymbolName,
     rustc_middle::ty::Ty,
+    rustc_middle::ty::TypingEnv,
+    rustc_middle::ty::inhabitedness::InhabitedPredicate,
+    // tidy-alphabetical-end
 }

From 289932194af47f75359e3db05b910d9c9b9e9856 Mon Sep 17 00:00:00 2001
From: Nicholas Nethercote <n.nethercote@gmail.com>
Date: Wed, 25 Mar 2026 14:19:37 +1100
Subject: [PATCH 3/7] Avoid unnecessary qualification of `ErrorGuaranteed`.

It's imported and can be used directly within this file, and already is
in a few places.
---
 compiler/rustc_middle/src/query/erase.rs | 25 ++++++++++--------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs
index 66b0f01196d4a..fce9943d105b6 100644
--- a/compiler/rustc_middle/src/query/erase.rs
+++ b/compiler/rustc_middle/src/query/erase.rs
@@ -120,8 +120,8 @@ impl<T> Erasable for Result<&'_ T, traits::query::NoSolution> {
     type Storage = [u8; size_of::<Result<&'static (), traits::query::NoSolution>>()];
 }
 
-impl<T> Erasable for Result<&'_ T, rustc_errors::ErrorGuaranteed> {
-    type Storage = [u8; size_of::<Result<&'static (), rustc_errors::ErrorGuaranteed>>()];
+impl<T> Erasable for Result<&'_ T, ErrorGuaranteed> {
+    type Storage = [u8; size_of::<Result<&'static (), ErrorGuaranteed>>()];
 }
 
 impl<T> Erasable for Result<&'_ T, traits::CodegenObligationError> {
@@ -132,22 +132,17 @@ impl<T> Erasable for Result<&'_ T, &'_ ty::layout::FnAbiError<'_>> {
     type Storage = [u8; size_of::<Result<&'static (), &'static ty::layout::FnAbiError<'static>>>()];
 }
 
-impl<T> Erasable for Result<(&'_ T, crate::thir::ExprId), rustc_errors::ErrorGuaranteed> {
-    type Storage = [u8; size_of::<
-        Result<(&'static (), crate::thir::ExprId), rustc_errors::ErrorGuaranteed>,
-    >()];
+impl<T> Erasable for Result<(&'_ T, crate::thir::ExprId), ErrorGuaranteed> {
+    type Storage = [u8; size_of::<Result<(&'static (), crate::thir::ExprId), ErrorGuaranteed>>()];
 }
 
-impl Erasable for Result<Option<ty::Instance<'_>>, rustc_errors::ErrorGuaranteed> {
-    type Storage =
-        [u8; size_of::<Result<Option<ty::Instance<'static>>, rustc_errors::ErrorGuaranteed>>()];
+impl Erasable for Result<Option<ty::Instance<'_>>, ErrorGuaranteed> {
+    type Storage = [u8; size_of::<Result<Option<ty::Instance<'static>>, ErrorGuaranteed>>()];
 }
 
-impl Erasable
-    for Result<Option<ty::EarlyBinder<'_, ty::Const<'_>>>, rustc_errors::ErrorGuaranteed>
-{
+impl Erasable for Result<Option<ty::EarlyBinder<'_, ty::Const<'_>>>, ErrorGuaranteed> {
     type Storage = [u8; size_of::<
-        Result<Option<ty::EarlyBinder<'static, ty::Const<'static>>>, rustc_errors::ErrorGuaranteed>,
+        Result<Option<ty::EarlyBinder<'static, ty::Const<'static>>>, ErrorGuaranteed>,
     >()];
 }
 
@@ -288,10 +283,10 @@ impl_erasable_for_simple_types! {
     Option<rustc_span::def_id::LocalDefId>,
     Option<rustc_target::spec::PanicStrategy>,
     Option<usize>,
-    Result<(), rustc_errors::ErrorGuaranteed>,
+    Result<(), ErrorGuaranteed>,
     Result<mir::ConstValue, mir::interpret::ErrorHandled>,
     Result<rustc_middle::traits::EvaluationResult, rustc_middle::traits::OverflowError>,
-    Result<rustc_middle::ty::adjustment::CoerceUnsizedInfo, rustc_errors::ErrorGuaranteed>,
+    Result<rustc_middle::ty::adjustment::CoerceUnsizedInfo, ErrorGuaranteed>,
     bool,
     rustc_data_structures::svh::Svh,
     rustc_hir::Constness,

From 2fde4f4210b0e300e70613238769089a2cede7fd Mon Sep 17 00:00:00 2001
From: Nicholas Nethercote <n.nethercote@gmail.com>
Date: Wed, 25 Mar 2026 14:24:45 +1100
Subject: [PATCH 4/7] Adjust some `Erasable` impls.

A few can be done with the `impl_erasable_for_single_lifetime_types!`
macro instead of being hand-written.
---
 compiler/rustc_middle/src/query/erase.rs | 19 +++----------------
 1 file changed, 3 insertions(+), 16 deletions(-)

diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs
index fce9943d105b6..865cdecf6d804 100644
--- a/compiler/rustc_middle/src/query/erase.rs
+++ b/compiler/rustc_middle/src/query/erase.rs
@@ -12,7 +12,6 @@ use std::mem::MaybeUninit;
 use rustc_ast::tokenstream::TokenStream;
 use rustc_span::{ErrorGuaranteed, Spanned};
 
-use crate::mir::interpret::EvalToValTreeResult;
 use crate::mir::mono::{MonoItem, NormalizationErrorInMono};
 use crate::traits::solve;
 use crate::ty::{self, Ty, TyCtxt};
@@ -172,10 +171,6 @@ impl Erasable for Option<(mir::ConstValue, Ty<'_>)> {
     type Storage = [u8; size_of::<Option<(mir::ConstValue, Ty<'_>)>>()];
 }
 
-impl Erasable for EvalToValTreeResult<'_> {
-    type Storage = [u8; size_of::<EvalToValTreeResult<'static>>()];
-}
-
 impl Erasable for Result<&'_ ty::List<Ty<'_>>, ty::util::AlwaysRequiresDrop> {
     type Storage =
         [u8; size_of::<Result<&'static ty::List<Ty<'static>>, ty::util::AlwaysRequiresDrop>>()];
@@ -208,10 +203,6 @@ impl Erasable for Option<&'_ OsStr> {
     type Storage = [u8; size_of::<Option<&'static OsStr>>()];
 }
 
-impl Erasable for ty::ImplTraitHeader<'_> {
-    type Storage = [u8; size_of::<ty::ImplTraitHeader<'static>>()];
-}
-
 impl Erasable for Option<ty::EarlyBinder<'_, Ty<'_>>> {
     type Storage = [u8; size_of::<Option<ty::EarlyBinder<'static, Ty<'static>>>>()];
 }
@@ -220,10 +211,6 @@ impl Erasable for Option<ty::Value<'_>> {
     type Storage = [u8; size_of::<Option<ty::Value<'static>>>()];
 }
 
-impl Erasable for rustc_hir::MaybeOwner<'_> {
-    type Storage = [u8; size_of::<rustc_hir::MaybeOwner<'static>>()];
-}
-
 impl<T: Erasable> Erasable for ty::EarlyBinder<'_, T> {
     type Storage = T::Storage;
 }
@@ -328,12 +315,11 @@ macro_rules! impl_erasable_for_single_lifetime_types {
 
 // For types containing a single lifetime and no other generics, e.g.
 // `Foo<'tcx>`, the erased storage is `[u8; size_of::<Foo<'static>>()]`.
-//
-// FIXME(#151565): Some of the hand-written impls above that only use one
-// lifetime can probably be migrated here.
 impl_erasable_for_single_lifetime_types! {
     // tidy-alphabetical-start
+    rustc_hir::MaybeOwner,
     rustc_middle::mir::interpret::EvalStaticInitializerRawResult,
+    rustc_middle::mir::interpret::EvalToValTreeResult,
     rustc_middle::mir::mono::MonoItemPartitions,
     rustc_middle::traits::query::MethodAutoderefStepsResult,
     rustc_middle::ty::AdtDef,
@@ -341,6 +327,7 @@ impl_erasable_for_single_lifetime_types! {
     rustc_middle::ty::Const,
     rustc_middle::ty::ConstConditions,
     rustc_middle::ty::GenericPredicates,
+    rustc_middle::ty::ImplTraitHeader,
     rustc_middle::ty::ParamEnv,
     rustc_middle::ty::SymbolName,
     rustc_middle::ty::Ty,

From efd36a4897b643882ad037c77fc6ddd84fff4f4b Mon Sep 17 00:00:00 2001
From: Nicholas Nethercote <n.nethercote@gmail.com>
Date: Wed, 25 Mar 2026 14:29:10 +1100
Subject: [PATCH 5/7] Avoid 'static in `Erasable` impls.

Using '_ removes unnecessary differences between the impl type and the
associated `Storage` type.
---
 compiler/rustc_middle/src/query/erase.rs | 62 ++++++++++++------------
 1 file changed, 31 insertions(+), 31 deletions(-)

diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs
index 865cdecf6d804..59853e8cc4640 100644
--- a/compiler/rustc_middle/src/query/erase.rs
+++ b/compiler/rustc_middle/src/query/erase.rs
@@ -100,71 +100,71 @@ pub fn restore_val<T: Erasable>(erased_value: Erased<T>) -> T {
 // FIXME(#151565): Using `T: ?Sized` here should let us remove the separate
 // impls for fat reference types.
 impl<T> Erasable for &'_ T {
-    type Storage = [u8; size_of::<&'static ()>()];
+    type Storage = [u8; size_of::<&'_ ()>()];
 }
 
 impl<T> Erasable for &'_ [T] {
-    type Storage = [u8; size_of::<&'static [()]>()];
+    type Storage = [u8; size_of::<&'_ [()]>()];
 }
 
 impl<T> Erasable for &'_ ty::List<T> {
-    type Storage = [u8; size_of::<&'static ty::List<()>>()];
+    type Storage = [u8; size_of::<&'_ ty::List<()>>()];
 }
 
 impl<T> Erasable for &'_ ty::ListWithCachedTypeInfo<T> {
-    type Storage = [u8; size_of::<&'static ty::ListWithCachedTypeInfo<()>>()];
+    type Storage = [u8; size_of::<&'_ ty::ListWithCachedTypeInfo<()>>()];
 }
 
 impl<T> Erasable for Result<&'_ T, traits::query::NoSolution> {
-    type Storage = [u8; size_of::<Result<&'static (), traits::query::NoSolution>>()];
+    type Storage = [u8; size_of::<Result<&'_ (), traits::query::NoSolution>>()];
 }
 
 impl<T> Erasable for Result<&'_ T, ErrorGuaranteed> {
-    type Storage = [u8; size_of::<Result<&'static (), ErrorGuaranteed>>()];
+    type Storage = [u8; size_of::<Result<&'_ (), ErrorGuaranteed>>()];
 }
 
 impl<T> Erasable for Result<&'_ T, traits::CodegenObligationError> {
-    type Storage = [u8; size_of::<Result<&'static (), traits::CodegenObligationError>>()];
+    type Storage = [u8; size_of::<Result<&'_ (), traits::CodegenObligationError>>()];
 }
 
 impl<T> Erasable for Result<&'_ T, &'_ ty::layout::FnAbiError<'_>> {
-    type Storage = [u8; size_of::<Result<&'static (), &'static ty::layout::FnAbiError<'static>>>()];
+    type Storage = [u8; size_of::<Result<&'_ (), &'_ ty::layout::FnAbiError<'_>>>()];
 }
 
 impl<T> Erasable for Result<(&'_ T, crate::thir::ExprId), ErrorGuaranteed> {
-    type Storage = [u8; size_of::<Result<(&'static (), crate::thir::ExprId), ErrorGuaranteed>>()];
+    type Storage = [u8; size_of::<Result<(&'_ (), crate::thir::ExprId), ErrorGuaranteed>>()];
 }
 
 impl Erasable for Result<Option<ty::Instance<'_>>, ErrorGuaranteed> {
-    type Storage = [u8; size_of::<Result<Option<ty::Instance<'static>>, ErrorGuaranteed>>()];
+    type Storage = [u8; size_of::<Result<Option<ty::Instance<'_>>, ErrorGuaranteed>>()];
 }
 
 impl Erasable for Result<Option<ty::EarlyBinder<'_, ty::Const<'_>>>, ErrorGuaranteed> {
     type Storage = [u8; size_of::<
-        Result<Option<ty::EarlyBinder<'static, ty::Const<'static>>>, ErrorGuaranteed>,
+        Result<Option<ty::EarlyBinder<'_, ty::Const<'_>>>, ErrorGuaranteed>,
     >()];
 }
 
 impl Erasable for Result<ty::GenericArg<'_>, traits::query::NoSolution> {
-    type Storage = [u8; size_of::<Result<ty::GenericArg<'static>, traits::query::NoSolution>>()];
+    type Storage = [u8; size_of::<Result<ty::GenericArg<'_>, traits::query::NoSolution>>()];
 }
 
 impl Erasable for Result<bool, &ty::layout::LayoutError<'_>> {
-    type Storage = [u8; size_of::<Result<bool, &'static ty::layout::LayoutError<'static>>>()];
+    type Storage = [u8; size_of::<Result<bool, &'_ ty::layout::LayoutError<'_>>>()];
 }
 
 impl Erasable for Result<rustc_abi::TyAndLayout<'_, Ty<'_>>, &ty::layout::LayoutError<'_>> {
     type Storage = [u8; size_of::<
         Result<
-            rustc_abi::TyAndLayout<'static, Ty<'static>>,
-            &'static ty::layout::LayoutError<'static>,
+            rustc_abi::TyAndLayout<'_, Ty<'_>>,
+            &'_ ty::layout::LayoutError<'_>,
         >,
     >()];
 }
 
 impl Erasable for Result<mir::ConstAlloc<'_>, mir::interpret::ErrorHandled> {
     type Storage =
-        [u8; size_of::<Result<mir::ConstAlloc<'static>, mir::interpret::ErrorHandled>>()];
+        [u8; size_of::<Result<mir::ConstAlloc<'_>, mir::interpret::ErrorHandled>>()];
 }
 
 impl Erasable for Option<(mir::ConstValue, Ty<'_>)> {
@@ -173,7 +173,7 @@ impl Erasable for Option<(mir::ConstValue, Ty<'_>)> {
 
 impl Erasable for Result<&'_ ty::List<Ty<'_>>, ty::util::AlwaysRequiresDrop> {
     type Storage =
-        [u8; size_of::<Result<&'static ty::List<Ty<'static>>, ty::util::AlwaysRequiresDrop>>()];
+        [u8; size_of::<Result<&'_ ty::List<Ty<'_>>, ty::util::AlwaysRequiresDrop>>()];
 }
 
 impl Erasable
@@ -181,34 +181,34 @@ impl Erasable
 {
     type Storage = [u8; size_of::<
         Result<
-            (&'static [Spanned<MonoItem<'static>>], &'static [Spanned<MonoItem<'static>>]),
+            (&'_ [Spanned<MonoItem<'_>>], &'_ [Spanned<MonoItem<'_>>]),
             NormalizationErrorInMono,
         >,
     >()];
 }
 
 impl Erasable for Result<&'_ TokenStream, ()> {
-    type Storage = [u8; size_of::<Result<&'static TokenStream, ()>>()];
+    type Storage = [u8; size_of::<Result<&'_ TokenStream, ()>>()];
 }
 
 impl<T> Erasable for Option<&'_ T> {
-    type Storage = [u8; size_of::<Option<&'static ()>>()];
+    type Storage = [u8; size_of::<Option<&'_ ()>>()];
 }
 
 impl<T> Erasable for Option<&'_ [T]> {
-    type Storage = [u8; size_of::<Option<&'static [()]>>()];
+    type Storage = [u8; size_of::<Option<&'_ [()]>>()];
 }
 
 impl Erasable for Option<&'_ OsStr> {
-    type Storage = [u8; size_of::<Option<&'static OsStr>>()];
+    type Storage = [u8; size_of::<Option<&'_ OsStr>>()];
 }
 
 impl Erasable for Option<ty::EarlyBinder<'_, Ty<'_>>> {
-    type Storage = [u8; size_of::<Option<ty::EarlyBinder<'static, Ty<'static>>>>()];
+    type Storage = [u8; size_of::<Option<ty::EarlyBinder<'_, Ty<'_>>>>()];
 }
 
 impl Erasable for Option<ty::Value<'_>> {
-    type Storage = [u8; size_of::<Option<ty::Value<'static>>>()];
+    type Storage = [u8; size_of::<Option<ty::Value<'_>>>()];
 }
 
 impl<T: Erasable> Erasable for ty::EarlyBinder<'_, T> {
@@ -216,24 +216,24 @@ impl<T: Erasable> Erasable for ty::EarlyBinder<'_, T> {
 }
 
 impl Erasable for ty::Binder<'_, ty::FnSig<'_>> {
-    type Storage = [u8; size_of::<ty::Binder<'static, ty::FnSig<'static>>>()];
+    type Storage = [u8; size_of::<ty::Binder<'_, ty::FnSig<'_>>>()];
 }
 
 impl Erasable for ty::Binder<'_, ty::CoroutineWitnessTypes<TyCtxt<'_>>> {
     type Storage =
-        [u8; size_of::<ty::Binder<'static, ty::CoroutineWitnessTypes<TyCtxt<'static>>>>()];
+        [u8; size_of::<ty::Binder<'_, ty::CoroutineWitnessTypes<TyCtxt<'_>>>>()];
 }
 
 impl<T0, T1> Erasable for (&'_ T0, &'_ T1) {
-    type Storage = [u8; size_of::<(&'static (), &'static ())>()];
+    type Storage = [u8; size_of::<(&'_ (), &'_ ())>()];
 }
 
 impl<T0> Erasable for (solve::QueryResult<'_>, &'_ T0) {
-    type Storage = [u8; size_of::<(solve::QueryResult<'static>, &'static ())>()];
+    type Storage = [u8; size_of::<(solve::QueryResult<'_>, &'_ ())>()];
 }
 
 impl<T0> Erasable for (&'_ T0, Result<(), ErrorGuaranteed>) {
-    type Storage = [u8; size_of::<(&'static (), Result<(), ErrorGuaranteed>)>()];
+    type Storage = [u8; size_of::<(&'_ (), Result<(), ErrorGuaranteed>)>()];
 }
 
 macro_rules! impl_erasable_for_simple_types {
@@ -307,14 +307,14 @@ macro_rules! impl_erasable_for_single_lifetime_types {
     ($($($fake_path:ident)::+),+ $(,)?) => {
         $(
             impl Erasable for $($fake_path)::+<'_> {
-                type Storage = [u8; size_of::<$($fake_path)::+<'static>>()];
+                type Storage = [u8; size_of::<$($fake_path)::+<'_>>()];
             }
         )*
     }
 }
 
 // For types containing a single lifetime and no other generics, e.g.
-// `Foo<'tcx>`, the erased storage is `[u8; size_of::<Foo<'static>>()]`.
+// `Foo<'tcx>`, the erased storage is `[u8; size_of::<Foo<'_>>()]`.
 impl_erasable_for_single_lifetime_types! {
     // tidy-alphabetical-start
     rustc_hir::MaybeOwner,

From dce180559976fc3ce4d90a67541dcc724109e9ba Mon Sep 17 00:00:00 2001
From: Nicholas Nethercote <n.nethercote@gmail.com>
Date: Wed, 25 Mar 2026 14:40:46 +1100
Subject: [PATCH 6/7] Use `impl_erasable_for_simple_types!` more, and rename
 it.

Now that 'static lifetimes aren't used, a lot of the hand-written
`Erasable` impls can now be done with the macro. (The only ones that
can't are those with a generic type parameter, because `size_of`
doesn't work in that case.)

Also, `impl_erasable_for_single_lifetime_types!` isn't needed at all.
---
 compiler/rustc_middle/src/query/erase.rs | 149 ++++++-----------------
 1 file changed, 35 insertions(+), 114 deletions(-)

diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs
index 59853e8cc4640..54fe858e4809f 100644
--- a/compiler/rustc_middle/src/query/erase.rs
+++ b/compiler/rustc_middle/src/query/erase.rs
@@ -135,62 +135,6 @@ impl<T> Erasable for Result<(&'_ T, crate::thir::ExprId), ErrorGuaranteed> {
     type Storage = [u8; size_of::<Result<(&'_ (), crate::thir::ExprId), ErrorGuaranteed>>()];
 }
 
-impl Erasable for Result<Option<ty::Instance<'_>>, ErrorGuaranteed> {
-    type Storage = [u8; size_of::<Result<Option<ty::Instance<'_>>, ErrorGuaranteed>>()];
-}
-
-impl Erasable for Result<Option<ty::EarlyBinder<'_, ty::Const<'_>>>, ErrorGuaranteed> {
-    type Storage = [u8; size_of::<
-        Result<Option<ty::EarlyBinder<'_, ty::Const<'_>>>, ErrorGuaranteed>,
-    >()];
-}
-
-impl Erasable for Result<ty::GenericArg<'_>, traits::query::NoSolution> {
-    type Storage = [u8; size_of::<Result<ty::GenericArg<'_>, traits::query::NoSolution>>()];
-}
-
-impl Erasable for Result<bool, &ty::layout::LayoutError<'_>> {
-    type Storage = [u8; size_of::<Result<bool, &'_ ty::layout::LayoutError<'_>>>()];
-}
-
-impl Erasable for Result<rustc_abi::TyAndLayout<'_, Ty<'_>>, &ty::layout::LayoutError<'_>> {
-    type Storage = [u8; size_of::<
-        Result<
-            rustc_abi::TyAndLayout<'_, Ty<'_>>,
-            &'_ ty::layout::LayoutError<'_>,
-        >,
-    >()];
-}
-
-impl Erasable for Result<mir::ConstAlloc<'_>, mir::interpret::ErrorHandled> {
-    type Storage =
-        [u8; size_of::<Result<mir::ConstAlloc<'_>, mir::interpret::ErrorHandled>>()];
-}
-
-impl Erasable for Option<(mir::ConstValue, Ty<'_>)> {
-    type Storage = [u8; size_of::<Option<(mir::ConstValue, Ty<'_>)>>()];
-}
-
-impl Erasable for Result<&'_ ty::List<Ty<'_>>, ty::util::AlwaysRequiresDrop> {
-    type Storage =
-        [u8; size_of::<Result<&'_ ty::List<Ty<'_>>, ty::util::AlwaysRequiresDrop>>()];
-}
-
-impl Erasable
-    for Result<(&'_ [Spanned<MonoItem<'_>>], &'_ [Spanned<MonoItem<'_>>]), NormalizationErrorInMono>
-{
-    type Storage = [u8; size_of::<
-        Result<
-            (&'_ [Spanned<MonoItem<'_>>], &'_ [Spanned<MonoItem<'_>>]),
-            NormalizationErrorInMono,
-        >,
-    >()];
-}
-
-impl Erasable for Result<&'_ TokenStream, ()> {
-    type Storage = [u8; size_of::<Result<&'_ TokenStream, ()>>()];
-}
-
 impl<T> Erasable for Option<&'_ T> {
     type Storage = [u8; size_of::<Option<&'_ ()>>()];
 }
@@ -199,31 +143,10 @@ impl<T> Erasable for Option<&'_ [T]> {
     type Storage = [u8; size_of::<Option<&'_ [()]>>()];
 }
 
-impl Erasable for Option<&'_ OsStr> {
-    type Storage = [u8; size_of::<Option<&'_ OsStr>>()];
-}
-
-impl Erasable for Option<ty::EarlyBinder<'_, Ty<'_>>> {
-    type Storage = [u8; size_of::<Option<ty::EarlyBinder<'_, Ty<'_>>>>()];
-}
-
-impl Erasable for Option<ty::Value<'_>> {
-    type Storage = [u8; size_of::<Option<ty::Value<'_>>>()];
-}
-
 impl<T: Erasable> Erasable for ty::EarlyBinder<'_, T> {
     type Storage = T::Storage;
 }
 
-impl Erasable for ty::Binder<'_, ty::FnSig<'_>> {
-    type Storage = [u8; size_of::<ty::Binder<'_, ty::FnSig<'_>>>()];
-}
-
-impl Erasable for ty::Binder<'_, ty::CoroutineWitnessTypes<TyCtxt<'_>>> {
-    type Storage =
-        [u8; size_of::<ty::Binder<'_, ty::CoroutineWitnessTypes<TyCtxt<'_>>>>()];
-}
-
 impl<T0, T1> Erasable for (&'_ T0, &'_ T1) {
     type Storage = [u8; size_of::<(&'_ (), &'_ ())>()];
 }
@@ -236,7 +159,7 @@ impl<T0> Erasable for (&'_ T0, Result<(), ErrorGuaranteed>) {
     type Storage = [u8; size_of::<(&'_ (), Result<(), ErrorGuaranteed>)>()];
 }
 
-macro_rules! impl_erasable_for_simple_types {
+macro_rules! impl_erasable_for_types_with_no_type_params {
     ($($ty:ty),+ $(,)?) => {
         $(
             impl Erasable for $ty {
@@ -246,11 +169,13 @@ macro_rules! impl_erasable_for_simple_types {
     }
 }
 
-// For concrete types with no lifetimes, the erased storage for `Foo` is
-// `[u8; size_of::<Foo>()]`.
-impl_erasable_for_simple_types! {
+// For types with no type parameters the erased storage for `Foo` is
+// `[u8; size_of::<Foo>()]`. ('_ lifetimes are allowed.)
+impl_erasable_for_types_with_no_type_params! {
     // tidy-alphabetical-start
     (),
+    Option<&'_ OsStr>,
+    Option<(mir::ConstValue, Ty<'_>)>,
     Option<(rustc_span::def_id::DefId, rustc_session::config::EntryFnType)>,
     Option<rustc_abi::Align>,
     Option<rustc_ast::expand::allocator::AllocatorKind>,
@@ -269,16 +194,29 @@ impl_erasable_for_simple_types! {
     Option<rustc_span::def_id::DefId>,
     Option<rustc_span::def_id::LocalDefId>,
     Option<rustc_target::spec::PanicStrategy>,
+    Option<ty::EarlyBinder<'_, Ty<'_>>>,
+    Option<ty::Value<'_>>,
     Option<usize>,
+    Result<&'_ TokenStream, ()>,
+    Result<&'_ ty::List<Ty<'_>>, ty::util::AlwaysRequiresDrop>,
+    Result<(&'_ [Spanned<MonoItem<'_>>], &'_ [Spanned<MonoItem<'_>>]), NormalizationErrorInMono>,
     Result<(), ErrorGuaranteed>,
+    Result<Option<ty::EarlyBinder<'_, ty::Const<'_>>>, ErrorGuaranteed>,
+    Result<Option<ty::Instance<'_>>, ErrorGuaranteed>,
+    Result<bool, &ty::layout::LayoutError<'_>>,
+    Result<mir::ConstAlloc<'_>, mir::interpret::ErrorHandled>,
     Result<mir::ConstValue, mir::interpret::ErrorHandled>,
+    Result<rustc_abi::TyAndLayout<'_, Ty<'_>>, &ty::layout::LayoutError<'_>>,
     Result<rustc_middle::traits::EvaluationResult, rustc_middle::traits::OverflowError>,
     Result<rustc_middle::ty::adjustment::CoerceUnsizedInfo, ErrorGuaranteed>,
+    Result<ty::GenericArg<'_>, traits::query::NoSolution>,
+    Ty<'_>,
     bool,
     rustc_data_structures::svh::Svh,
     rustc_hir::Constness,
     rustc_hir::Defaultness,
     rustc_hir::HirId,
+    rustc_hir::MaybeOwner<'_>,
     rustc_hir::OpaqueTyOrigin<rustc_hir::def_id::DefId>,
     rustc_hir::def::DefKind,
     rustc_hir::def_id::DefId,
@@ -287,10 +225,26 @@ impl_erasable_for_simple_types! {
     rustc_middle::mir::ConstQualifs,
     rustc_middle::mir::ConstValue,
     rustc_middle::mir::interpret::AllocId,
+    rustc_middle::mir::interpret::EvalStaticInitializerRawResult<'_>,
+    rustc_middle::mir::interpret::EvalToValTreeResult<'_>,
+    rustc_middle::mir::mono::MonoItemPartitions<'_>,
+    rustc_middle::traits::query::MethodAutoderefStepsResult<'_>,
+    rustc_middle::ty::AdtDef<'_>,
     rustc_middle::ty::AnonConstKind,
     rustc_middle::ty::AssocItem,
     rustc_middle::ty::Asyncness,
+    rustc_middle::ty::Binder<'_, ty::CoroutineWitnessTypes<TyCtxt<'_>>>,
+    rustc_middle::ty::Binder<'_, ty::FnSig<'_>>,
+    rustc_middle::ty::ClosureTypeInfo<'_>,
+    rustc_middle::ty::Const<'_>,
+    rustc_middle::ty::ConstConditions<'_>,
+    rustc_middle::ty::GenericPredicates<'_>,
+    rustc_middle::ty::ImplTraitHeader<'_>,
+    rustc_middle::ty::ParamEnv<'_>,
+    rustc_middle::ty::SymbolName<'_>,
+    rustc_middle::ty::TypingEnv<'_>,
     rustc_middle::ty::Visibility<rustc_span::def_id::DefId>,
+    rustc_middle::ty::inhabitedness::InhabitedPredicate<'_>,
     rustc_session::Limits,
     rustc_session::config::OptLevel,
     rustc_session::config::SymbolManglingVersion,
@@ -302,36 +256,3 @@ impl_erasable_for_simple_types! {
     usize,
     // tidy-alphabetical-end
 }
-
-macro_rules! impl_erasable_for_single_lifetime_types {
-    ($($($fake_path:ident)::+),+ $(,)?) => {
-        $(
-            impl Erasable for $($fake_path)::+<'_> {
-                type Storage = [u8; size_of::<$($fake_path)::+<'_>>()];
-            }
-        )*
-    }
-}
-
-// For types containing a single lifetime and no other generics, e.g.
-// `Foo<'tcx>`, the erased storage is `[u8; size_of::<Foo<'_>>()]`.
-impl_erasable_for_single_lifetime_types! {
-    // tidy-alphabetical-start
-    rustc_hir::MaybeOwner,
-    rustc_middle::mir::interpret::EvalStaticInitializerRawResult,
-    rustc_middle::mir::interpret::EvalToValTreeResult,
-    rustc_middle::mir::mono::MonoItemPartitions,
-    rustc_middle::traits::query::MethodAutoderefStepsResult,
-    rustc_middle::ty::AdtDef,
-    rustc_middle::ty::ClosureTypeInfo,
-    rustc_middle::ty::Const,
-    rustc_middle::ty::ConstConditions,
-    rustc_middle::ty::GenericPredicates,
-    rustc_middle::ty::ImplTraitHeader,
-    rustc_middle::ty::ParamEnv,
-    rustc_middle::ty::SymbolName,
-    rustc_middle::ty::Ty,
-    rustc_middle::ty::TypingEnv,
-    rustc_middle::ty::inhabitedness::InhabitedPredicate,
-    // tidy-alphabetical-end
-}

From 4f03262c8ac4b977cc3dd716bf2a6ffaf8864c49 Mon Sep 17 00:00:00 2001
From: Nicholas Nethercote <n.nethercote@gmail.com>
Date: Wed, 25 Mar 2026 15:30:34 +1100
Subject: [PATCH 7/7] Use `impl_erasable_for_types_with_no_type_params!` even
 more.

Some of the hand-written `Erasable` impls only match a single type in
practice. It's easier to just list the concrete types in
`impl_erasable_for_types_with_no_type_params!`.
---
 compiler/rustc_middle/src/query/erase.rs | 34 ++++++------------------
 1 file changed, 8 insertions(+), 26 deletions(-)

diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs
index 54fe858e4809f..53ec0584ae599 100644
--- a/compiler/rustc_middle/src/query/erase.rs
+++ b/compiler/rustc_middle/src/query/erase.rs
@@ -10,12 +10,12 @@ use std::intrinsics::transmute_unchecked;
 use std::mem::MaybeUninit;
 
 use rustc_ast::tokenstream::TokenStream;
+use rustc_data_structures::steal::Steal;
 use rustc_span::{ErrorGuaranteed, Spanned};
 
 use crate::mir::mono::{MonoItem, NormalizationErrorInMono};
-use crate::traits::solve;
 use crate::ty::{self, Ty, TyCtxt};
-use crate::{mir, traits};
+use crate::{mir, thir, traits};
 
 /// Internal implementation detail of [`Erased`].
 #[derive(Copy, Clone)]
@@ -123,26 +123,10 @@ impl<T> Erasable for Result<&'_ T, ErrorGuaranteed> {
     type Storage = [u8; size_of::<Result<&'_ (), ErrorGuaranteed>>()];
 }
 
-impl<T> Erasable for Result<&'_ T, traits::CodegenObligationError> {
-    type Storage = [u8; size_of::<Result<&'_ (), traits::CodegenObligationError>>()];
-}
-
-impl<T> Erasable for Result<&'_ T, &'_ ty::layout::FnAbiError<'_>> {
-    type Storage = [u8; size_of::<Result<&'_ (), &'_ ty::layout::FnAbiError<'_>>>()];
-}
-
-impl<T> Erasable for Result<(&'_ T, crate::thir::ExprId), ErrorGuaranteed> {
-    type Storage = [u8; size_of::<Result<(&'_ (), crate::thir::ExprId), ErrorGuaranteed>>()];
-}
-
 impl<T> Erasable for Option<&'_ T> {
     type Storage = [u8; size_of::<Option<&'_ ()>>()];
 }
 
-impl<T> Erasable for Option<&'_ [T]> {
-    type Storage = [u8; size_of::<Option<&'_ [()]>>()];
-}
-
 impl<T: Erasable> Erasable for ty::EarlyBinder<'_, T> {
     type Storage = T::Storage;
 }
@@ -151,14 +135,6 @@ impl<T0, T1> Erasable for (&'_ T0, &'_ T1) {
     type Storage = [u8; size_of::<(&'_ (), &'_ ())>()];
 }
 
-impl<T0> Erasable for (solve::QueryResult<'_>, &'_ T0) {
-    type Storage = [u8; size_of::<(solve::QueryResult<'_>, &'_ ())>()];
-}
-
-impl<T0> Erasable for (&'_ T0, Result<(), ErrorGuaranteed>) {
-    type Storage = [u8; size_of::<(&'_ (), Result<(), ErrorGuaranteed>)>()];
-}
-
 macro_rules! impl_erasable_for_types_with_no_type_params {
     ($($ty:ty),+ $(,)?) => {
         $(
@@ -173,8 +149,11 @@ macro_rules! impl_erasable_for_types_with_no_type_params {
 // `[u8; size_of::<Foo>()]`. ('_ lifetimes are allowed.)
 impl_erasable_for_types_with_no_type_params! {
     // tidy-alphabetical-start
+    (&'_ ty::CrateInherentImpls, Result<(), ErrorGuaranteed>),
     (),
+    (traits::solve::QueryResult<'_>, &'_ traits::solve::inspect::Probe<TyCtxt<'_>>),
     Option<&'_ OsStr>,
+    Option<&'_ [rustc_hir::PreciseCapturingArgKind<rustc_span::Symbol, rustc_span::Symbol>]>,
     Option<(mir::ConstValue, Ty<'_>)>,
     Option<(rustc_span::def_id::DefId, rustc_session::config::EntryFnType)>,
     Option<rustc_abi::Align>,
@@ -198,7 +177,10 @@ impl_erasable_for_types_with_no_type_params! {
     Option<ty::Value<'_>>,
     Option<usize>,
     Result<&'_ TokenStream, ()>,
+    Result<&'_ rustc_target::callconv::FnAbi<'_, Ty<'_>>, &'_ ty::layout::FnAbiError<'_>>,
+    Result<&'_ traits::ImplSource<'_, ()>, traits::CodegenObligationError>,
     Result<&'_ ty::List<Ty<'_>>, ty::util::AlwaysRequiresDrop>,
+    Result<(&'_ Steal<thir::Thir<'_>>, thir::ExprId), ErrorGuaranteed>,
     Result<(&'_ [Spanned<MonoItem<'_>>], &'_ [Spanned<MonoItem<'_>>]), NormalizationErrorInMono>,
     Result<(), ErrorGuaranteed>,
     Result<Option<ty::EarlyBinder<'_, ty::Const<'_>>>, ErrorGuaranteed>,
