diff options
Diffstat (limited to 'compiler/rustc_infer/src')
| -rw-r--r-- | compiler/rustc_infer/src/infer/canonical/canonicalizer.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/context.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/mod.rs | 31 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/opaque_types/mod.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/relate/generalize.rs | 10 |
5 files changed, 15 insertions, 39 deletions
diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index f87c43a0ecd..fe66d306ceb 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -72,7 +72,7 @@ impl<'tcx> InferCtxt<'tcx> { query_state, ) .unchecked_map(|(param_env, value)| param_env.and(value)); - CanonicalQueryInput { canonical, typing_mode: self.typing_mode(param_env) } + CanonicalQueryInput { canonical, typing_mode: self.typing_mode() } } /// Canonicalizes a query *response* `V`. When we canonicalize a diff --git a/compiler/rustc_infer/src/infer/context.rs b/compiler/rustc_infer/src/infer/context.rs index ecda9c6eb00..1968ed34752 100644 --- a/compiler/rustc_infer/src/infer/context.rs +++ b/compiler/rustc_infer/src/infer/context.rs @@ -20,11 +20,8 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> { self.next_trait_solver } - fn typing_mode( - &self, - param_env_for_debug_assertion: ty::ParamEnv<'tcx>, - ) -> ty::TypingMode<'tcx> { - self.typing_mode(param_env_for_debug_assertion) + fn typing_mode(&self) -> ty::TypingMode<'tcx> { + self.typing_mode() } fn universe(&self) -> ty::UniverseIndex { diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 7345c388c4f..555c1022a8a 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -43,7 +43,6 @@ use rustc_middle::ty::{ }; use rustc_span::Span; use rustc_span::symbol::Symbol; -use rustc_type_ir::solve::Reveal; use snapshot::undo_log::InferCtxtUndoLogs; use tracing::{debug, instrument}; use type_variable::TypeVariableOrigin; @@ -265,11 +264,12 @@ pub struct InferCtxt<'tcx> { lexical_region_resolutions: RefCell<Option<LexicalRegionResolutions<'tcx>>>, /// Caches the results of trait selection. This cache is used - /// for things that have to do with the parameters in scope. - pub selection_cache: select::SelectionCache<'tcx>, + /// for things that depends on inference variables or placeholders. + pub selection_cache: select::SelectionCache<'tcx, ty::ParamEnv<'tcx>>, - /// Caches the results of trait evaluation. - pub evaluation_cache: select::EvaluationCache<'tcx>, + /// Caches the results of trait evaluation. This cache is used + /// for things that depends on inference variables or placeholders. + pub evaluation_cache: select::EvaluationCache<'tcx, ty::ParamEnv<'tcx>>, /// The set of predicates on which errors have been reported, to /// avoid reporting the same error twice. @@ -624,22 +624,7 @@ impl<'tcx> InferCtxt<'tcx> { } #[inline(always)] - pub fn typing_mode( - &self, - param_env_for_debug_assertion: ty::ParamEnv<'tcx>, - ) -> TypingMode<'tcx> { - if cfg!(debug_assertions) { - match (param_env_for_debug_assertion.reveal(), self.typing_mode) { - (Reveal::All, TypingMode::PostAnalysis) - | (Reveal::UserFacing, TypingMode::Coherence | TypingMode::Analysis { .. }) => {} - (r, t) => unreachable!("TypingMode x Reveal mismatch: {r:?} {t:?}"), - } - } - self.typing_mode - } - - #[inline(always)] - pub fn typing_mode_unchecked(&self) -> TypingMode<'tcx> { + pub fn typing_mode(&self) -> TypingMode<'tcx> { self.typing_mode } @@ -1005,7 +990,7 @@ impl<'tcx> InferCtxt<'tcx> { #[inline(always)] pub fn can_define_opaque_ty(&self, id: impl Into<DefId>) -> bool { - match self.typing_mode_unchecked() { + match self.typing_mode() { TypingMode::Analysis { defining_opaque_types } => { id.into().as_local().is_some_and(|def_id| defining_opaque_types.contains(&def_id)) } @@ -1290,7 +1275,7 @@ impl<'tcx> InferCtxt<'tcx> { /// which contains the necessary information to use the trait system without /// using canonicalization or carrying this inference context around. pub fn typing_env(&self, param_env: ty::ParamEnv<'tcx>) -> ty::TypingEnv<'tcx> { - let typing_mode = match self.typing_mode(param_env) { + let typing_mode = match self.typing_mode() { ty::TypingMode::Coherence => ty::TypingMode::Coherence, // FIXME(#132279): This erases the `defining_opaque_types` as it isn't possible // to handle them without proper canonicalization. This means we may cause cycle diff --git a/compiler/rustc_infer/src/infer/opaque_types/mod.rs b/compiler/rustc_infer/src/infer/opaque_types/mod.rs index 5499fed1bdf..a608ea1ad57 100644 --- a/compiler/rustc_infer/src/infer/opaque_types/mod.rs +++ b/compiler/rustc_infer/src/infer/opaque_types/mod.rs @@ -101,7 +101,7 @@ impl<'tcx> InferCtxt<'tcx> { let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() { ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) if def_id.is_local() => { let def_id = def_id.expect_local(); - if let ty::TypingMode::Coherence = self.typing_mode(param_env) { + if let ty::TypingMode::Coherence = self.typing_mode() { // See comment on `insert_hidden_type` for why this is sufficient in coherence return Some(self.register_hidden_type( OpaqueTypeKey { def_id, args }, @@ -522,7 +522,7 @@ impl<'tcx> InferCtxt<'tcx> { // value being folded. In simple cases like `-> impl Foo`, // these are the same span, but not in cases like `-> (impl // Foo, impl Bar)`. - match self.typing_mode(param_env) { + match self.typing_mode() { ty::TypingMode::Coherence => { // During intercrate we do not define opaque types but instead always // force ambiguity unless the hidden type is known to not implement diff --git a/compiler/rustc_infer/src/infer/relate/generalize.rs b/compiler/rustc_infer/src/infer/relate/generalize.rs index 4c80bf4e07e..21c47967ead 100644 --- a/compiler/rustc_infer/src/infer/relate/generalize.rs +++ b/compiler/rustc_infer/src/infer/relate/generalize.rs @@ -520,10 +520,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> { // // cc trait-system-refactor-initiative#108 if self.infcx.next_trait_solver() - && !matches!( - self.infcx.typing_mode_unchecked(), - TypingMode::Coherence - ) + && !matches!(self.infcx.typing_mode(), TypingMode::Coherence) && self.in_alias { inner.type_variables().equate(vid, new_var_id); @@ -654,10 +651,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> { // See the comment for type inference variables // for more details. if self.infcx.next_trait_solver() - && !matches!( - self.infcx.typing_mode_unchecked(), - TypingMode::Coherence - ) + && !matches!(self.infcx.typing_mode(), TypingMode::Coherence) && self.in_alias { variable_table.union(vid, new_var_id); |
