diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs index 7f0d6c8e8734..62ec0d2ef8bf 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -8,7 +8,7 @@ use rustc_middle::query::TyCtxtAt; use rustc_middle::ty::layout::{HasTypingEnv, TyAndLayout}; use rustc_middle::ty::print::with_no_trimmed_paths; -use rustc_middle::ty::{self, MayBeErased, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::{bug, throw_inval}; use rustc_span::Span; use rustc_span::def_id::LocalDefId; @@ -374,7 +374,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>( assert!(key.value.promoted.is_some() || !tcx.is_static(key.value.instance.def_id())); if cfg!(debug_assertions) { - match key.typing_env.typing_mode() { + match key.typing_env.typing_mode().assert_not_erased() { ty::TypingMode::PostAnalysis => {} ty::TypingMode::Coherence | ty::TypingMode::Analysis { .. } @@ -384,7 +384,6 @@ pub fn eval_to_allocation_raw_provider<'tcx>( "Const eval should always happens in PostAnalysis mode. See the comment in `InterpCx::new` for more details." ) } - ty::TypingMode::ErasedNotCoherence(MayBeErased) => todo!(), } // Make sure we format the instance even if we do not print it. diff --git a/compiler/rustc_const_eval/src/const_eval/valtrees.rs b/compiler/rustc_const_eval/src/const_eval/valtrees.rs index 3858a3b7047d..0169dc7ed99d 100644 --- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs +++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs @@ -3,7 +3,7 @@ use rustc_middle::mir::interpret::{EvalToValTreeResult, GlobalId, ValTreeCreationError}; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::layout::{LayoutCx, TyAndLayout}; -use rustc_middle::ty::{self, MayBeErased, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::{bug, mir}; use rustc_span::DUMMY_SP; use tracing::{debug, instrument, trace}; @@ -237,7 +237,7 @@ pub(crate) fn eval_to_valtree<'tcx>( cid: GlobalId<'tcx>, ) -> EvalToValTreeResult<'tcx> { if cfg!(debug_assertions) { - match typing_env.typing_mode() { + match typing_env.typing_mode().assert_not_erased() { ty::TypingMode::PostAnalysis => {} ty::TypingMode::Coherence | ty::TypingMode::Analysis { .. } @@ -247,7 +247,6 @@ pub(crate) fn eval_to_valtree<'tcx>( "Const eval should always happens in PostAnalysis mode. See the comment in `InterpCx::new` for more details." ) } - ty::TypingMode::ErasedNotCoherence(MayBeErased) => unreachable!(), } } let const_alloc = tcx.eval_to_allocation_raw(typing_env.as_query_input(cid))?; diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 06410df7e1f1..7dc6d292a94a 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -9,8 +9,8 @@ LayoutOfHelpers, TyAndLayout, }; use rustc_middle::ty::{ - self, GenericArgsRef, MayBeErased, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, TypingEnv, - TypingMode, Variance, + self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, TypingEnv, TypingMode, + Variance, }; use rustc_middle::{bug, mir, span_bug}; use rustc_span::Span; @@ -243,7 +243,7 @@ pub fn new( // types that are not specified in the opaque type. We also use MIR bodies whose opaque types have // already been revealed, so we'd be able to at least partially observe the hidden types anyways. if cfg!(debug_assertions) { - match typing_env.typing_mode() { + match typing_env.typing_mode().assert_not_erased() { TypingMode::PostAnalysis => {} TypingMode::Coherence | TypingMode::Analysis { .. } @@ -251,7 +251,6 @@ pub fn new( | TypingMode::PostBorrowckAnalysis { .. } => { bug!("Const eval should always happens in PostAnalysis mode."); } - TypingMode::ErasedNotCoherence(MayBeErased) => unreachable!(), } } diff --git a/compiler/rustc_mir_transform/src/elaborate_drop.rs b/compiler/rustc_mir_transform/src/elaborate_drop.rs index 48006bace447..6cd08cafbcc1 100644 --- a/compiler/rustc_mir_transform/src/elaborate_drop.rs +++ b/compiler/rustc_mir_transform/src/elaborate_drop.rs @@ -7,7 +7,7 @@ use rustc_middle::mir::*; use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::util::IntTypeExt; -use rustc_middle::ty::{self, GenericArg, GenericArgsRef, MayBeErased, Ty, TyCtxt, Unnormalized}; +use rustc_middle::ty::{self, GenericArg, GenericArgsRef, Ty, TyCtxt, Unnormalized}; use rustc_middle::{bug, span_bug, traits}; use rustc_span::{DUMMY_SP, Spanned, dummy_spanned}; use tracing::{debug, instrument}; @@ -547,7 +547,7 @@ fn move_paths_for_fields( let subpath = self.elaborator.field_subpath(variant_path, field_idx); let tcx = self.tcx(); - match self.elaborator.typing_env().typing_mode() { + match self.elaborator.typing_env().typing_mode().assert_not_erased() { ty::TypingMode::PostAnalysis => {} ty::TypingMode::Coherence | ty::TypingMode::Analysis { .. } @@ -555,7 +555,6 @@ fn move_paths_for_fields( | ty::TypingMode::PostBorrowckAnalysis { .. } => { bug!() } - ty::TypingMode::ErasedNotCoherence(MayBeErased) => unreachable!(), } let field_ty = field.ty(tcx, args); diff --git a/compiler/rustc_next_trait_solver/src/solve/mod.rs b/compiler/rustc_next_trait_solver/src/solve/mod.rs index 678cf2f9abe6..178a192a6630 100644 --- a/compiler/rustc_next_trait_solver/src/solve/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/mod.rs @@ -24,7 +24,7 @@ use derive_where::derive_where; use rustc_type_ir::inherent::*; pub use rustc_type_ir::solve::*; -use rustc_type_ir::{self as ty, Interner, MayBeErased, TyVid, TypingMode}; +use rustc_type_ir::{self as ty, Interner, TyVid, TypingMode}; use tracing::instrument; pub use self::eval_ctxt::{ @@ -358,7 +358,11 @@ fn structurally_normalize_term( } fn opaque_type_is_rigid(&self, def_id: I::DefId) -> bool { - match self.typing_mode() { + match self + .typing_mode() + // Caller should handle erased mode + .assert_not_erased() + { // Opaques are never rigid outside of analysis mode. TypingMode::Coherence | TypingMode::PostAnalysis => false, // During analysis, opaques are rigid unless they may be defined by @@ -368,8 +372,6 @@ fn opaque_type_is_rigid(&self, def_id: I::DefId) -> bool { | TypingMode::PostBorrowckAnalysis { defined_opaque_types: non_rigid_opaques } => { !def_id.as_local().is_some_and(|def_id| non_rigid_opaques.contains(&def_id)) } - // Caller should handle this variant - TypingMode::ErasedNotCoherence(MayBeErased) => unreachable!(), } } } diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs index 7996e9a44878..632311ebab1b 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs @@ -8,8 +8,7 @@ use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem}; use rustc_type_ir::solve::{FetchEligibleAssocItemResponse, RerunReason}; use rustc_type_ir::{ - self as ty, FieldInfo, Interner, MayBeErased, NormalizesTo, PredicateKind, Unnormalized, - Upcast as _, + self as ty, FieldInfo, Interner, NormalizesTo, PredicateKind, Unnormalized, Upcast as _, }; use tracing::instrument; diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs index 83d078c5d873..45dd2f25abd7 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs @@ -82,7 +82,7 @@ pub(super) fn normalize_opaque_type( // During HIR typeck, opaque types start out as unconstrained // inference variables. In borrowck we instead use the type // computed in HIR typeck as the initial value. - match self.typing_mode() { + match self.typing_mode().assert_not_erased() { TypingMode::Analysis { .. } => {} TypingMode::Borrowck { .. } => { let actual = cx @@ -98,7 +98,6 @@ pub(super) fn normalize_opaque_type( TypingMode::Coherence | TypingMode::PostBorrowckAnalysis { .. } | TypingMode::PostAnalysis => unreachable!(), - TypingMode::ErasedNotCoherence(MayBeErased) => todo!(), } } diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index 6e526e8dc548..84dbd53de83f 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -12,8 +12,8 @@ use rustc_middle::span_bug; use rustc_middle::traits::{ObligationCause, ObligationCauseCode}; use rustc_middle::ty::{ - self, AliasTerm, MayBeErased, Term, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, - TypeVisitable, TypeVisitableExt, TypingMode, Unnormalized, + self, AliasTerm, Term, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitable, + TypeVisitableExt, TypingMode, Unnormalized, }; use tracing::{debug, instrument}; @@ -138,14 +138,13 @@ pub(super) fn needs_normalization<'tcx, T: TypeVisitable>>( // Opaques are treated as rigid outside of `TypingMode::PostAnalysis`, // so we can ignore those. - match infcx.typing_mode_raw() { + match infcx.typing_mode_raw().assert_not_erased() { // FIXME(#132279): We likely want to reveal opaques during post borrowck analysis TypingMode::Coherence | TypingMode::Analysis { .. } | TypingMode::Borrowck { .. } | TypingMode::PostBorrowckAnalysis { .. } => flags.remove(ty::TypeFlags::HAS_TY_OPAQUE), TypingMode::PostAnalysis => {} - TypingMode::ErasedNotCoherence(MayBeErased) => unreachable!(), } value.has_type_flags(flags) diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 178533fb231a..c423f9925c6b 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -6,8 +6,8 @@ use rustc_middle::query::Providers; use rustc_middle::traits::{BuiltinImplSource, CodegenObligationError}; use rustc_middle::ty::{ - self, ClosureKind, GenericArgsRef, Instance, MayBeErased, PseudoCanonicalInput, TyCtxt, - TypeVisitableExt, Unnormalized, + self, ClosureKind, GenericArgsRef, Instance, PseudoCanonicalInput, TyCtxt, TypeVisitableExt, + Unnormalized, }; use rustc_span::sym; use rustc_trait_selection::traits; @@ -155,13 +155,12 @@ fn resolve_associated_item<'tcx>( // and the obligation is monomorphic, otherwise passes such as // transmute checking and polymorphic MIR optimizations could // get a result which isn't correct for all monomorphizations. - match typing_env.typing_mode() { + match typing_env.typing_mode().assert_not_erased() { ty::TypingMode::Coherence | ty::TypingMode::Analysis { .. } | ty::TypingMode::Borrowck { .. } | ty::TypingMode::PostBorrowckAnalysis { .. } => false, ty::TypingMode::PostAnalysis => !trait_ref.still_further_specializable(), - ty::TypingMode::ErasedNotCoherence(MayBeErased) => unreachable!(), } }; if !eligible {