From d2d70a73586ed8988b9b51548203f61aad8864c3 Mon Sep 17 00:00:00 2001 From: Fallible <118682743+fallible-algebra@users.noreply.github.com> Date: Tue, 8 Sep 2026 14:27:52 +0100 Subject: [PATCH 1/9] Remove many things lol --- compiler/rustc_infer/src/infer/at.rs | 192 ++++++++++++++++++ .../src/solve/normalize.rs | 37 ++-- .../src/traits/query/normalize.rs | 102 ++++++++++ 3 files changed, 314 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_infer/src/infer/at.rs b/compiler/rustc_infer/src/infer/at.rs index 341ea9a70dbc7..f948a5ee82bd9 100644 --- a/compiler/rustc_infer/src/infer/at.rs +++ b/compiler/rustc_infer/src/infer/at.rs @@ -46,6 +46,7 @@ pub enum DefineOpaqueTypes { No, } +#[deprecated("Get rid of this :(")] #[derive(Clone, Copy)] pub struct At<'a, 'tcx> { pub infcx: &'a InferCtxt<'tcx>, @@ -122,6 +123,197 @@ impl<'tcx> InferCtxt<'tcx> { forked.inner.borrow_mut().projection_cache().clear(); forked } + + pub fn sup_at( + self, + define_opaque_types: DefineOpaqueTypes, + expected: T, + actual: T, + param_env: ty::ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, + ) -> InferResult<'tcx, ()> + where + T: ToTrace<'tcx>, + { + if self.next_trait_solver { + NextSolverRelate::relate( + &self, + param_env, + expected, + ty::Contravariant, + actual, + cause.span, + ) + .map(|goals| self.goals_to_obligations_at(goals, cause)) + } else { + let mut op = TypeRelating::new( + &self, + ToTrace::to_trace(cause, expected, actual), + param_env, + define_opaque_types, + ty::Contravariant, + ); + op.relate(expected, actual)?; + Ok(InferOk { value: (), obligations: op.into_obligations() }) + } + } + + /// Makes `expected <: actual`. + pub fn sub_at( + self, + define_opaque_types: DefineOpaqueTypes, + expected: T, + actual: T, + param_env: ty::ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, + ) -> InferResult<'tcx, ()> + where + T: ToTrace<'tcx>, + { + if self.next_trait_solver { + NextSolverRelate::relate( + &self, + param_env, + expected, + ty::Covariant, + actual, + cause.span, + ) + .map(|goals| self.goals_to_obligations_at(goals, cause)) + } else { + let mut op = TypeRelating::new( + &self, + ToTrace::to_trace(cause, expected, actual), + param_env, + define_opaque_types, + ty::Covariant, + ); + op.relate(expected, actual)?; + Ok(InferOk { value: (), obligations: op.into_obligations() }) + } + } + + pub fn eq_at( + self, + define_opaque_types: DefineOpaqueTypes, + expected: T, + actual: T, + param_env: ty::ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, + ) -> InferResult<'tcx, ()> + where + T: ToTrace<'tcx>, + { + self.eq_trace_at( + define_opaque_types, + ToTrace::to_trace(cause, expected, actual), + expected, + actual, + param_env, + cause, + ) + } + + pub fn eq_trace_at( + self, + define_opaque_types: DefineOpaqueTypes, + trace: TypeTrace<'tcx>, + expected: T, + actual: T, + param_env: ty::ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, + ) -> InferResult<'tcx, ()> + where + T: Relate>, + { + if self.next_trait_solver { + NextSolverRelate::relate( + &self, + param_env, + expected, + ty::Invariant, + actual, + cause.span, + ) + .map(|goals| self.goals_to_obligations_at(goals, cause)) + } else { + let mut op = TypeRelating::new( + &self, + trace, + param_env, + define_opaque_types, + ty::Invariant, + ); + op.relate(expected, actual)?; + Ok(InferOk { value: (), obligations: op.into_obligations() }) + } + } + + pub fn relate_at( + self, + define_opaque_types: DefineOpaqueTypes, + expected: T, + variance: ty::Variance, + actual: T, + param_env: ty::ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, + ) -> InferResult<'tcx, ()> + where + T: ToTrace<'tcx>, + { + match variance { + ty::Covariant => self.sub_at(define_opaque_types, expected, actual, param_env, cause), + ty::Invariant => self.eq_at(define_opaque_types, expected, actual, param_env, cause), + ty::Contravariant => self.sup_at(define_opaque_types, expected, actual, param_env, cause), + + // We could make this make sense but it's not readily + // exposed and I don't feel like dealing with it. Note + // that bivariance in general does a bit more than just + // *nothing*, it checks that the types are the same + // "modulo variance" basically. - Niko + ty::Bivariant => panic!("Bivariant given to `relate()`"), + } + } + + /// Computes the least-upper-bound, or mutual supertype, of two + /// values. The order of the arguments doesn't matter, but since + /// this can result in an error (e.g., if asked to compute LUB of + /// u32 and i32), it is meaningful to call one of them the + /// "expected type". + pub fn lub_at(self, expected: T, actual: T, param_env: ty::ParamEnv<'tcx>, cause: &ObligationCause<'tcx>) -> InferResult<'tcx, T> + where + T: ToTrace<'tcx>, + { + let mut op = LatticeOp::new( + &self, + ToTrace::to_trace(cause, expected, actual), + param_env, + LatticeOpKind::Lub, + ); + let value = op.relate(expected, actual)?; + Ok(InferOk { value, obligations: op.into_obligations() }) + } + + fn goals_to_obligations_at( + &self, + goals: Vec>>, + cause: &ObligationCause<'tcx> + ) -> InferOk<'tcx, ()> { + InferOk { + value: (), + obligations: goals + .into_iter() + .map(|goal| { + Obligation::new( + self.tcx, + cause.clone(), + goal.param_env, + goal.predicate, + ) + }) + .collect(), + } + } } pub trait ToTrace<'tcx>: Relate> + Copy { diff --git a/compiler/rustc_trait_selection/src/solve/normalize.rs b/compiler/rustc_trait_selection/src/solve/normalize.rs index 9430b6c4b3307..e89e46defc283 100644 --- a/compiler/rustc_trait_selection/src/solve/normalize.rs +++ b/compiler/rustc_trait_selection/src/solve/normalize.rs @@ -18,11 +18,11 @@ use crate::solve::{Certainty, SolverDelegate}; use crate::traits::{BoundVarReplacer, ScrubbedTraitError}; /// see `normalize_with_universes`. -pub fn normalize<'tcx, T>(at: At<'_, 'tcx>, value: Unnormalized<'tcx, T>) -> Normalized<'tcx, T> +pub fn normalize<'tcx, T>(infcx: &InferCtxt<'tcx>, value: Unnormalized<'tcx, T>, param_env: ty::ParamEnv<'tcx>, cause: &ObligationCause<'tcx>) -> Normalized<'tcx, T> where T: TypeFoldable>, { - normalize_with_universes(at, value, vec![]) + normalize_with_universes(infcx, value, vec![], param_env, cause) } /// Like `deeply_normalize`, but we handle ambiguity and inference variables in this routine. @@ -33,14 +33,15 @@ where /// - otherwise: return the normalized result. It can be (partially) inferred /// even if the evaluation result is ambiguous. fn normalize_with_universes<'tcx, T>( - at: At<'_, 'tcx>, + infcx: &InferCtxt<'_, 'tcx>, value: Unnormalized<'tcx, T>, universes: Vec>, + param_env: ty::ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, ) -> Normalized<'tcx, T> where T: TypeFoldable>, { - let infcx = at.infcx; let value = value.skip_normalization(); let value = infcx.deeply_resolve_ignoring_regions(value); @@ -52,10 +53,10 @@ where let mut stalled_goals = vec![]; let mut folder = NormalizationFolder::new(infcx, universes.clone(), |alias_term| { let delegate = <&SolverDelegate<'tcx>>::from(infcx); - let infer_term = delegate.next_term_var_of_alias_kind(alias_term, at.cause.span); + let infer_term = delegate.next_term_var_of_alias_kind(alias_term, cause.span); let predicate = ty::ProjectionClause { projection_term: alias_term, term: infer_term }; - let goal = Goal::new(infcx.tcx, at.param_env, predicate); - let result = match delegate.evaluate_root_goal(goal, at.cause.span, None) { + let goal = Goal::new(infcx.tcx, param_env, predicate); + let result = match delegate.evaluate_root_goal(goal, cause.span, None) { Ok(result) => result, Err(err) => return Err(err), }; @@ -73,7 +74,7 @@ where let obligations = stalled_goals .into_iter() .map(|goal| { - Obligation::new(infcx.tcx, at.cause.clone(), goal.param_env, goal.predicate) + Obligation::new(infcx.tcx, cause.clone(), goal.param_env, goal.predicate) }) .collect(); Normalized { value, obligations } @@ -85,7 +86,7 @@ where } struct ReplaceAliasWithInfer<'me, 'tcx> { - at: At<'me, 'tcx>, + at: InferCtxt<'me, 'tcx>, obligations: PredicateObligations<'tcx>, universes: Vec>, } @@ -169,7 +170,7 @@ impl<'me, 'tcx> TypeFolder> for ReplaceAliasWithInfer<'me, 'tcx> { /// Deeply normalize all aliases in `value`. This does not handle inference and expects /// its input to be already fully resolved. pub fn deeply_normalize<'tcx, T, E>( - at: At<'_, 'tcx>, + infcx: &InferCtxt<'tcx>, value: Unnormalized<'tcx, T>, ) -> Result> where @@ -177,7 +178,7 @@ where E: FromSolverError<'tcx, NextSolverError<'tcx>>, { assert!(!value.as_ref().skip_normalization().has_escaping_bound_vars()); - deeply_normalize_with_skipped_universes(at, value, vec![]) + deeply_normalize_with_skipped_universes(infcx, value, vec![]) } /// Deeply normalize all aliases in `value`. This does not handle inference and expects @@ -187,7 +188,7 @@ where /// entered before passing `value` to the function. This is currently needed for /// `normalize_erasing_regions`, which skips binders as it walks through a type. pub fn deeply_normalize_with_skipped_universes<'tcx, T, E>( - at: At<'_, 'tcx>, + infcx: &InferCtxt<'tcx>, value: Unnormalized<'tcx, T>, universes: Vec>, ) -> Result> @@ -197,7 +198,7 @@ where { let (value, coroutine_goals) = deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals( - at, value, universes, + infcx, value, universes, )?; assert_eq!(coroutine_goals, vec![]); @@ -214,19 +215,21 @@ where /// This returns a set of stalled obligations involving coroutines if the typing mode of /// the underlying infcx has any stalled coroutine def ids. pub fn deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals<'tcx, T, E>( - at: At<'_, 'tcx>, + infcx: &InferCtxt<'_, 'tcx>, value: Unnormalized<'tcx, T>, universes: Vec>, + param_env: ty::ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, ) -> Result<(T, Vec>>), ThinVec> where T: TypeFoldable>, E: FromSolverError<'tcx, NextSolverError<'tcx>>, { - let Normalized { value, obligations } = normalize_with_universes(at, value, universes); + let Normalized { value, obligations } = normalize_with_universes(infcx, value, universes); - let mut fulfill_cx = FulfillmentCtxt::new(at.infcx); + let mut fulfill_cx = FulfillmentCtxt::new(infcx); for pred in obligations { - fulfill_cx.register_predicate_obligation(at.infcx, pred); + fulfill_cx.register_predicate_obligation(infcx, pred); } let errors = fulfill_cx.try_evaluate_obligations(at.infcx); diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 782697782f94c..7c712cb6d61a5 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -137,6 +137,108 @@ impl<'a, 'tcx> At<'a, 'tcx> { } } + +#[extension(pub trait QueryNormalizeExt<'tcx>)] +impl<'a, 'tcx> InferCtxt<'a, 'tcx> { + /// Normalize `value` in the context of the inference context, + /// yielding a resulting type, or an error if `value` cannot be + /// normalized. If you don't care about regions, you should prefer + /// `normalize_erasing_regions`, which is more efficient. + /// + /// If the normalization succeeds, returns back the normalized + /// value along with various outlives relations (in the form of + /// obligations that must be discharged). + /// + /// This normalization should *only* be used when the projection is well-formed and + /// does not have possible ambiguity (contains inference variables). + /// + /// After codegen, when lifetimes do not matter, it is preferable to instead + /// use [`TyCtxt::normalize_erasing_regions`], which wraps this procedure. + /// + /// N.B. Once the new solver is stabilized this method of normalization will + /// likely be removed as trait solver operations are already cached by the query + /// system making this redundant. + fn query_normalize( + self, + value: T, + param_env: ty::ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, + ) -> Result, NoSolution> + where + T: TypeFoldable>, + { + debug!( + "normalize::<{}>(value={:?}, param_env={:?}, cause={:?})", + std::any::type_name::(), + value, + param_env, + cause, + ); + + // This is actually a consequence by the way `normalize_erasing_regions` works currently. + // Because it needs to call the `normalize_generic_arg_after_erasing_regions`, it folds + // through tys and consts in a `TypeFoldable`. Importantly, it skips binders, leaving us + // with trying to normalize with escaping bound vars. + // + // Here, we just add the universes that we *would* have created had we passed through the binders. + // + // We *could* replace escaping bound vars eagerly here, but it doesn't seem really necessary. + // The rest of the code is already set up to be lazy about replacing bound vars, + // and only when we actually have to normalize. + let universes = if value.has_escaping_bound_vars() { + let mut max_visitor = + MaxEscapingBoundVarVisitor { outer_index: ty::INNERMOST, escaping: 0 }; + value.visit_with(&mut max_visitor); + vec![None; max_visitor.escaping] + } else { + vec![] + }; + + if self.next_trait_solver() { + match crate::solve::deeply_normalize_with_skipped_universes::<_, ScrubbedTraitError<'tcx>>( + self, + Unnormalized::new_wip(value), + universes, + ) { + Ok(value) => { + return Ok(Normalized { value, obligations: PredicateObligations::new() }); + } + Err(_errors) => { + return Err(NoSolution); + } + } + } + + if !needs_normalization(self.infcx, &value) { + return Ok(Normalized { value, obligations: PredicateObligations::new() }); + } + + let mut normalizer = QueryNormalizer { + infcx: &self, + cause: self, + param_env: self.param_env, + obligations: PredicateObligations::new(), + cache: SsoHashMap::new(), + anon_depth: 0, + universes, + }; + + let result = value.try_fold_with(&mut normalizer); + info!( + "normalize::<{}>: result={:?} with {} obligations", + std::any::type_name::(), + result, + normalizer.obligations.len(), + ); + debug!( + "normalize::<{}>: obligations={:?}", + std::any::type_name::(), + normalizer.obligations, + ); + result.map(|value| Normalized { value, obligations: normalizer.obligations }) + } +} + // Visitor to find the maximum escaping bound var struct MaxEscapingBoundVarVisitor { // The index which would count as escaping From e167c4184fcbd9a56639c7bc8d17cb966f05512f Mon Sep 17 00:00:00 2001 From: Fallible <118682743+fallible-algebra@users.noreply.github.com> Date: Mon, 21 Sep 2026 16:12:18 +0100 Subject: [PATCH 2/9] bweh --- compiler/rustc_hir_typeck/src/coercion.rs | 2 +- compiler/rustc_infer/src/infer/at.rs | 2 +- .../traits/fulfillment_errors.rs | 3 +- .../src/error_reporting/traits/suggestions.rs | 7 +- .../src/solve/normalize.rs | 71 +++++---- .../src/traits/coherence.rs | 2 +- .../src/traits/engine.rs | 20 ++- .../src/traits/normalize.rs | 31 ++-- .../src/traits/query/dropck_outlives.rs | 2 +- .../src/traits/query/normalize.rs | 135 ++---------------- .../src/traits/structural_normalize.rs | 42 +++--- .../src/normalize_erasing_regions.rs | 2 +- compiler/rustc_traits/src/type_op.rs | 3 +- 13 files changed, 115 insertions(+), 207 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index af00194a95bf0..47e712c37aea4 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1047,7 +1047,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { let a_sig = self.sig_for_fn_def_coercion(a, Some(b_hdr.safety()))?; let InferOk { value: a_sig, mut obligations } = - self.at(&self.cause, self.param_env).normalize(Unnormalized::new_wip(a_sig)); + self.normalize(self.cause.span.clone(), Unnormalized::new_wip(a_sig)); let a = Ty::new_fn_ptr(self.tcx, a_sig); let adjust = Adjust::Pointer(PointerCoercion::ReifyFnPointer(b_hdr.safety())); diff --git a/compiler/rustc_infer/src/infer/at.rs b/compiler/rustc_infer/src/infer/at.rs index f948a5ee82bd9..66a61d1ba56d3 100644 --- a/compiler/rustc_infer/src/infer/at.rs +++ b/compiler/rustc_infer/src/infer/at.rs @@ -46,7 +46,7 @@ pub enum DefineOpaqueTypes { No, } -#[deprecated("Get rid of this :(")] +// #[deprecated = "Get rid of this :("] #[derive(Clone, Copy)] pub struct At<'a, 'tcx> { pub infcx: &'a InferCtxt<'tcx>, diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index ed0ecf459c3b8..f136ec5d35892 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -3050,8 +3050,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let InferOk { value: cleaned_pred, .. } = self .infcx - .at(&ObligationCause::dummy(), param_env) - .normalize(Unnormalized::new_wip(cleaned_pred)); + .normalize(Unnormalized::new_wip(cleaned_pred), param_env, &ObligationCause::dummy(),); let obligation = Obligation::new(self.tcx, ObligationCause::dummy(), param_env, cleaned_pred); diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 47d2b7a8c98d5..f8564cc8da255 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -1617,7 +1617,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { // implied by wf, but also because that would possibly result in // erroneous errors later on. let InferOk { value: output, obligations: _ } = - self.at(&ObligationCause::dummy(), param_env).normalize(Unnormalized::new_wip(output)); + self.normalize(Unnormalized::new_wip(output), param_env, &ObligationCause::dummy()); if output.is_ty_var() { None } else { Some((def_id_or_name, output, inputs)) } } @@ -5034,8 +5034,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { ) }); let InferOk { value: projection_ty, .. } = self - .at(&obligation.cause, obligation.param_env) - .normalize(Unnormalized::new_wip(projection_ty)); + .normalize(Unnormalized::new_wip(projection_ty), obligation.param_env, &obligation.cause); debug!( normalized_projection_type = ?self.deeply_resolve_ignoring_regions(projection_ty) @@ -5520,7 +5519,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { // Extract `::Target` assoc type and check that it is `T` && let Some(deref_target_did) = tcx.lang_items().deref_target() && let projection = Ty::new_projection_from_args(tcx,ty::IsRigid::No, deref_target_did, tcx.mk_args(&[ty::GenericArg::from(found_ty)])) - && let InferOk { value: deref_target, obligations } = infcx.at(&ObligationCause::dummy(), param_env).normalize(Unnormalized::new_wip(projection)) + && let InferOk { value: deref_target, obligations } = infcx.normalize(Unnormalized::new_wip(projection), param_env, &ObligationCause::dummy()) && obligations.iter().all(|obligation| infcx.predicate_must_hold_modulo_regions(obligation)) && infcx.can_eq(param_env, deref_target, target_ty) { diff --git a/compiler/rustc_trait_selection/src/solve/normalize.rs b/compiler/rustc_trait_selection/src/solve/normalize.rs index e89e46defc283..591f1eb371bf7 100644 --- a/compiler/rustc_trait_selection/src/solve/normalize.rs +++ b/compiler/rustc_trait_selection/src/solve/normalize.rs @@ -1,5 +1,4 @@ use rustc_infer::infer::InferCtxt; -use rustc_infer::infer::at::At; use rustc_infer::traits::solve::Goal; use rustc_infer::traits::{ FromSolverError, Normalized, Obligation, PredicateObligations, TraitEngine, TraitErrors, @@ -33,7 +32,7 @@ where /// - otherwise: return the normalized result. It can be (partially) inferred /// even if the evaluation result is ambiguous. fn normalize_with_universes<'tcx, T>( - infcx: &InferCtxt<'_, 'tcx>, + infcx: &InferCtxt<'tcx>, value: Unnormalized<'tcx, T>, universes: Vec>, param_env: ty::ParamEnv<'tcx>, @@ -79,26 +78,29 @@ where .collect(); Normalized { value, obligations } } else { - let mut replacer = ReplaceAliasWithInfer { at, obligations: Default::default(), universes }; + let mut replacer = ReplaceAliasWithInfer { infcx, obligations: Default::default(), universes, param_env, cause }; let value = original_value.fold_with(&mut replacer); Normalized { value, obligations: replacer.obligations } } } struct ReplaceAliasWithInfer<'me, 'tcx> { - at: InferCtxt<'me, 'tcx>, + infcx: &'me InferCtxt<'tcx>, + param_env: ty::ParamEnv<'tcx>, + cause: &'me ObligationCause<'tcx>, obligations: PredicateObligations<'tcx>, universes: Vec>, + } impl<'me, 'tcx> ReplaceAliasWithInfer<'me, 'tcx> { - fn term_to_infer(&mut self, alias_term: ty::AliasTerm<'tcx>) -> ty::Term<'tcx> { - let infcx = self.at.infcx; - let infer_term = infcx.next_term_var_of_alias_kind(alias_term, self.at.cause.span); + fn term_to_infer(&mut self, alias_term: ty::AliasTerm<'tcx>, ) -> ty::Term<'tcx> { + let infcx = self.infcx; + let infer_term = infcx.next_term_var_of_alias_kind(alias_term, self.cause.span); let obligation = Obligation::new( infcx.tcx, - self.at.cause.clone(), - self.at.param_env, + self.cause.clone(), + self.param_env, ty::ProjectionClause { projection_term: alias_term, term: infer_term }, ); self.obligations.push(obligation); @@ -108,7 +110,7 @@ impl<'me, 'tcx> ReplaceAliasWithInfer<'me, 'tcx> { impl<'me, 'tcx> TypeFolder> for ReplaceAliasWithInfer<'me, 'tcx> { fn cx(&self) -> TyCtxt<'tcx> { - self.at.infcx.tcx + self.infcx.tcx } fn fold_binder>>( @@ -134,7 +136,7 @@ impl<'me, 'tcx> TypeFolder> for ReplaceAliasWithInfer<'me, 'tcx> { if ty.has_escaping_bound_vars() { let (replaced, ..) = - BoundVarReplacer::replace_bound_vars(self.at.infcx, &mut self.universes, alias); + BoundVarReplacer::replace_bound_vars(self.infcx, &mut self.universes, alias); let _ = self.term_to_infer(replaced.into()); ty } else { @@ -155,7 +157,7 @@ impl<'me, 'tcx> TypeFolder> for ReplaceAliasWithInfer<'me, 'tcx> { if ct.has_escaping_bound_vars() { let (replaced, ..) = BoundVarReplacer::replace_bound_vars( - self.at.infcx, + self.infcx, &mut self.universes, alias_const, ); @@ -172,13 +174,15 @@ impl<'me, 'tcx> TypeFolder> for ReplaceAliasWithInfer<'me, 'tcx> { pub fn deeply_normalize<'tcx, T, E>( infcx: &InferCtxt<'tcx>, value: Unnormalized<'tcx, T>, + param_env: ty::ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, ) -> Result> where T: TypeFoldable>, E: FromSolverError<'tcx, NextSolverError<'tcx>>, { assert!(!value.as_ref().skip_normalization().has_escaping_bound_vars()); - deeply_normalize_with_skipped_universes(infcx, value, vec![]) + deeply_normalize_with_skipped_universes(infcx, value, vec![], param_env, cause) } /// Deeply normalize all aliases in `value`. This does not handle inference and expects @@ -191,6 +195,8 @@ pub fn deeply_normalize_with_skipped_universes<'tcx, T, E>( infcx: &InferCtxt<'tcx>, value: Unnormalized<'tcx, T>, universes: Vec>, + param_env: ty::ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, ) -> Result> where T: TypeFoldable>, @@ -198,7 +204,7 @@ where { let (value, coroutine_goals) = deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals( - infcx, value, universes, + infcx, value, universes, param_env, cause, )?; assert_eq!(coroutine_goals, vec![]); @@ -215,7 +221,7 @@ where /// This returns a set of stalled obligations involving coroutines if the typing mode of /// the underlying infcx has any stalled coroutine def ids. pub fn deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals<'tcx, T, E>( - infcx: &InferCtxt<'_, 'tcx>, + infcx: &InferCtxt<'tcx>, value: Unnormalized<'tcx, T>, universes: Vec>, param_env: ty::ParamEnv<'tcx>, @@ -225,25 +231,25 @@ where T: TypeFoldable>, E: FromSolverError<'tcx, NextSolverError<'tcx>>, { - let Normalized { value, obligations } = normalize_with_universes(infcx, value, universes); + let Normalized { value, obligations } = normalize_with_universes(infcx, value, universes, param_env, cause); let mut fulfill_cx = FulfillmentCtxt::new(infcx); for pred in obligations { fulfill_cx.register_predicate_obligation(infcx, pred); } - let errors = fulfill_cx.try_evaluate_obligations(at.infcx); + let errors = fulfill_cx.try_evaluate_obligations(infcx); if let TraitErrors::HasErrors(errors) = errors { return Err(errors); } let stalled_coroutine_goals = fulfill_cx - .drain_stalled_obligations_for_coroutines(at.infcx) + .drain_stalled_obligations_for_coroutines(infcx) .into_iter() .map(|obl| obl.as_goal()) .collect(); - let errors = fulfill_cx.collect_remaining_errors(at.infcx); + let errors = fulfill_cx.collect_remaining_errors(infcx); if let TraitErrors::HasErrors(errors) = errors { return Err(errors); } @@ -258,26 +264,37 @@ pub(crate) fn deeply_normalize_for_diagnostics<'tcx, T: TypeFoldable T { t.fold_with(&mut DeeplyNormalizeForDiagnosticsFolder { - at: infcx.at(&ObligationCause::dummy(), param_env), + infcx, + cause: &ObligationCause::dummy(), + param_env, }) } +/// A type folder struct. +/// +/// This is isomorphic to what was previously called `At`. This should remain +/// specific to its use as a TypeFolder, and not expanded back into another +/// "God Object." struct DeeplyNormalizeForDiagnosticsFolder<'a, 'tcx> { - at: At<'a, 'tcx>, + pub infcx: &'a InferCtxt<'tcx>, + pub cause: &'a ObligationCause<'tcx>, + pub param_env: ty::ParamEnv<'tcx>, } impl<'tcx> TypeFolder> for DeeplyNormalizeForDiagnosticsFolder<'_, 'tcx> { fn cx(&self) -> TyCtxt<'tcx> { - self.at.infcx.tcx + self.infcx.tcx } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { - let infcx = self.at.infcx; + let infcx = self.infcx; let result: Result<_, ThinVec>> = infcx.commit_if_ok(|_| { deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals( - self.at, + self.infcx, Unnormalized::new_wip(ty), vec![None; ty.outer_exclusive_binder().as_usize()], + self.param_env, + self.cause, ) }); match result { @@ -287,12 +304,14 @@ impl<'tcx> TypeFolder> for DeeplyNormalizeForDiagnosticsFolder<'_, } fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { - let infcx = self.at.infcx; + let infcx = self.infcx; let result: Result<_, ThinVec>> = infcx.commit_if_ok(|_| { deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals( - self.at, + self.infcx, Unnormalized::new_wip(ct), vec![None; ct.outer_exclusive_binder().as_usize()], + self.param_env, + self.cause, ) }); match result { diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index d3c118b33e8ce..1b5b9582d9bd8 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -226,7 +226,7 @@ fn fresh_impl_header_normalized<'tcx>( let header = fresh_impl_header(infcx, impl_def_id, is_of_trait); let InferOk { value: mut header, obligations } = - infcx.at(&ObligationCause::dummy(), param_env).normalize(Unnormalized::new_wip(header)); + infcx.normalize(Unnormalized::new_wip(header), param_env, &ObligationCause::dummy()); header.predicates.extend(obligations.into_iter().map(|o| o.predicate)); header diff --git a/compiler/rustc_trait_selection/src/traits/engine.rs b/compiler/rustc_trait_selection/src/traits/engine.rs index 3e6d14625c6b2..d7e1f34a1b480 100644 --- a/compiler/rustc_trait_selection/src/traits/engine.rs +++ b/compiler/rustc_trait_selection/src/traits/engine.rs @@ -215,7 +215,7 @@ where param_env: ty::ParamEnv<'tcx>, value: Unnormalized<'tcx, T>, ) -> T { - let infer_ok = self.infcx.at(cause, param_env).normalize(value); + let infer_ok = self.infcx.normalize(value, param_env, cause); self.register_infer_ok_obligations(infer_ok) } @@ -428,10 +428,9 @@ where // implied_bounds.insert(ty); let cause = ObligationCause::misc(span, def_id); - match self - .infcx - .at(&cause, param_env) - .deeply_normalize(Unnormalized::new_wip(ty), &mut *self.engine.borrow_mut()) + let infcx = self.infcx; + match infcx + .deeply_normalize(Unnormalized::new_wip(ty), &mut *self.engine.borrow_mut(), param_env, &cause) { // Insert well-formed types, ignoring duplicates. Ok(normalized) => drop(implied_bounds.insert(normalized)), @@ -448,7 +447,7 @@ where param_env: ty::ParamEnv<'tcx>, value: Unnormalized<'tcx, T>, ) -> Result> { - self.infcx.at(cause, param_env).deeply_normalize(value, &mut *self.engine.borrow_mut()) + self.infcx.deeply_normalize(value, &mut *self.engine.borrow_mut(), param_env, cause) } pub fn structurally_normalize_ty( @@ -458,8 +457,7 @@ where value: Unnormalized<'tcx, Ty<'tcx>>, ) -> Result, ThinVec> { self.infcx - .at(cause, param_env) - .structurally_normalize_ty(value, &mut *self.engine.borrow_mut()) + .structurally_normalize_ty(value, &mut *self.engine.borrow_mut(), param_env, cause) } pub fn structurally_normalize_const( @@ -469,8 +467,7 @@ where value: Unnormalized<'tcx, ty::Const<'tcx>>, ) -> Result, ThinVec> { self.infcx - .at(cause, param_env) - .structurally_normalize_const(value, &mut *self.engine.borrow_mut()) + .structurally_normalize_const(value, &mut *self.engine.borrow_mut(), param_env, cause) } pub fn structurally_normalize_term( @@ -480,7 +477,6 @@ where value: Unnormalized<'tcx, ty::Term<'tcx>>, ) -> Result, ThinVec> { self.infcx - .at(cause, param_env) - .structurally_normalize_term(value, &mut *self.engine.borrow_mut()) + .structurally_normalize_term(value, &mut *self.engine.borrow_mut(), param_env, cause) } } diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index 5a66fafd57361..730e4d0a02e1e 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -1,7 +1,6 @@ //! Deeply normalize types using the old trait solver. use rustc_errors::msg; -use rustc_infer::infer::at::At; use rustc_infer::infer::{InferCtxt, InferOk}; use rustc_infer::traits::{ FromSolverError, Normalized, Obligation, PredicateObligations, TraitEngine, TraitErrors, @@ -22,7 +21,7 @@ use crate::error_reporting::traits::OverflowCause; use crate::solve::NextSolverError; #[extension(pub trait NormalizeExt<'tcx>)] -impl<'tcx> At<'_, 'tcx> { +impl<'tcx> InferCtxt<'tcx> { /// Normalize a value using the `AssocTypeNormalizer`. /// /// This normalization should be used when the type contains inference variables or the @@ -30,14 +29,16 @@ impl<'tcx> At<'_, 'tcx> { fn normalize>>( &self, value: Unnormalized<'tcx, T>, + param_env: ty::ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, ) -> InferOk<'tcx, T> { - if self.infcx.next_trait_solver() { - let Normalized { value, obligations } = crate::solve::normalize(*self, value); + if self.next_trait_solver() { + let Normalized { value, obligations } = crate::solve::normalize(self, value, param_env, cause); InferOk { value, obligations } } else { - let mut selcx = SelectionContext::new(self.infcx); + let mut selcx = SelectionContext::new(self); let Normalized { value, obligations } = - normalize_with_depth(&mut selcx, self.param_env, self.cause.clone(), 0, value); + normalize_with_depth(&mut selcx, param_env, cause.clone(), 0, value); InferOk { value, obligations } } } @@ -55,16 +56,18 @@ impl<'tcx> At<'_, 'tcx> { /// fulfillment context in the old solver. Once we have removed the old solver, we /// can remove the `fulfill_cx` parameter on this function. fn deeply_normalize( - self, + &self, value: Unnormalized<'tcx, T>, fulfill_cx: &mut dyn TraitEngine<'tcx, E>, + param_env: ty::ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, ) -> Result> where T: TypeFoldable>, E: FromSolverError<'tcx, NextSolverError<'tcx>>, { - if self.infcx.next_trait_solver() { - crate::solve::deeply_normalize(self, value) + if self.next_trait_solver() { + crate::solve::deeply_normalize(&self, value, param_env, cause) } else { if fulfill_cx.has_pending_obligations() { let pending_obligations = fulfill_cx.pending_obligations(); @@ -75,17 +78,17 @@ impl<'tcx> At<'_, 'tcx> { ); } let value = self - .normalize(value) - .into_value_registering_obligations(self.infcx, &mut *fulfill_cx); - let errors = fulfill_cx.evaluate_obligations_error_on_ambiguity(self.infcx); - let value = self.infcx.deeply_resolve_ignoring_regions(value); + .normalize(value, param_env, cause) + .into_value_registering_obligations(&self, &mut *fulfill_cx); + let errors = fulfill_cx.evaluate_obligations_error_on_ambiguity(&self); + let value = self.resolve_vars_if_possible(value); match errors { TraitErrors::NoErrors => Ok(value), TraitErrors::HasErrors(errors) => { // Drop pending obligations, since deep normalization may happen // in a loop and we don't want to trigger the assertion on the next // iteration due to pending ambiguous obligations we've left over. - let _ = fulfill_cx.collect_remaining_errors(self.infcx); + let _ = fulfill_cx.collect_remaining_errors(&self); Err(errors) } } diff --git a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs index 31d2e8620af90..e46b0cd5b1d1b 100644 --- a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs +++ b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs @@ -192,7 +192,7 @@ where // to push them onto the stack to be expanded. for ty in constraints.dtorck_types.drain(..) { let ty = if let Ok(Normalized { value: ty, obligations }) = - ocx.infcx.at(&cause, param_env).query_normalize(ty) + ocx.infcx.query_normalize(ty, param_env, cause.clone()) { ocx.register_obligations(obligations); diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 7c712cb6d61a5..a40ec6d776246 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -16,7 +16,6 @@ use tracing::{debug, info, instrument}; use super::NoSolution; use crate::error_reporting::InferCtxtErrorExt; use crate::error_reporting::traits::OverflowCause; -use crate::infer::at::At; use crate::infer::canonical::OriginalQueryValues; use crate::infer::{InferCtxt, InferOk}; use crate::traits::normalize::needs_normalization; @@ -26,120 +25,7 @@ use crate::traits::{ }; #[extension(pub trait QueryNormalizeExt<'tcx>)] -impl<'a, 'tcx> At<'a, 'tcx> { - /// Normalize `value` in the context of the inference context, - /// yielding a resulting type, or an error if `value` cannot be - /// normalized. If you don't care about regions, you should prefer - /// `normalize_erasing_regions`, which is more efficient. - /// - /// If the normalization succeeds, returns back the normalized - /// value along with various outlives relations (in the form of - /// obligations that must be discharged). - /// - /// This normalization should *only* be used when the projection is well-formed and - /// does not have possible ambiguity (contains inference variables). - /// - /// After codegen, when lifetimes do not matter, it is preferable to instead - /// use [`TyCtxt::normalize_erasing_regions`], which wraps this procedure. - /// - /// N.B. Once the new solver is stabilized this method of normalization will - /// likely be removed as trait solver operations are already cached by the query - /// system making this redundant. - fn query_normalize(self, value: T) -> Result, NoSolution> - where - T: TypeFoldable>, - { - debug!( - "normalize::<{}>(value={:?}, param_env={:?}, cause={:?})", - std::any::type_name::(), - value, - self.param_env, - self.cause, - ); - - // This is actually a consequence by the way `normalize_erasing_regions` works currently. - // Because it needs to call the `normalize_generic_arg_after_erasing_regions`, it folds - // through tys and consts in a `TypeFoldable`. Importantly, it skips binders, leaving us - // with trying to normalize with escaping bound vars. - // - // Here, we just add the universes that we *would* have created had we passed through the binders. - // - // We *could* replace escaping bound vars eagerly here, but it doesn't seem really necessary. - // The rest of the code is already set up to be lazy about replacing bound vars, - // and only when we actually have to normalize. - let universes = if value.has_escaping_bound_vars() { - let mut max_visitor = - MaxEscapingBoundVarVisitor { outer_index: ty::INNERMOST, escaping: 0 }; - value.visit_with(&mut max_visitor); - vec![None; max_visitor.escaping] - } else { - vec![] - }; - - if self.infcx.next_trait_solver() { - match crate::solve::deeply_normalize_with_skipped_universes::<_, FulfillmentError<'tcx>>( - self, - Unnormalized::new_wip(value), - universes, - ) { - Ok(value) => { - return Ok(Normalized { value, obligations: PredicateObligations::new() }); - } - Err(errors) => { - // We're imitating the old solver's behavior of eagerly reporting overflow - // errors here. Otherwise we might silently ignore such errors. See #161542. - if let Some((overflowed_obligation, suggest_higher_limit)) = - errors.into_iter().find_map(|e| match e.code { - FulfillmentErrorCode::Ambiguity { - overflow: Some(suggest_higher_limit), - } => Some((e.root_obligation, suggest_higher_limit)), - _ => None, - }) - { - self.infcx.err_ctxt().report_overflow_obligation( - &overflowed_obligation, - suggest_higher_limit, - ); - } else { - return Err(NoSolution); - } - } - } - } - - if !needs_normalization(self.infcx, &value) { - return Ok(Normalized { value, obligations: PredicateObligations::new() }); - } - - let mut normalizer = QueryNormalizer { - infcx: self.infcx, - cause: self.cause, - param_env: self.param_env, - obligations: PredicateObligations::new(), - cache: SsoHashMap::new(), - anon_depth: 0, - universes, - }; - - let result = value.try_fold_with(&mut normalizer); - info!( - "normalize::<{}>: result={:?} with {} obligations", - std::any::type_name::(), - result, - normalizer.obligations.len(), - ); - debug!( - "normalize::<{}>: obligations={:?}", - std::any::type_name::(), - normalizer.obligations, - ); - result.map(|value| Normalized { value, obligations: normalizer.obligations }) - } -} - - -#[extension(pub trait QueryNormalizeExt<'tcx>)] -impl<'a, 'tcx> InferCtxt<'a, 'tcx> { +impl<'tcx> InferCtxt<'tcx> { /// Normalize `value` in the context of the inference context, /// yielding a resulting type, or an error if `value` cannot be /// normalized. If you don't care about regions, you should prefer @@ -159,20 +45,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { /// likely be removed as trait solver operations are already cached by the query /// system making this redundant. fn query_normalize( - self, + &self, value: T, - param_env: ty::ParamEnv<'tcx>, - cause: &ObligationCause<'tcx>, + param_env: ty::ParamEnv<'tcx>, + cause: ObligationCause<'tcx>, ) -> Result, NoSolution> where T: TypeFoldable>, { debug!( - "normalize::<{}>(value={:?}, param_env={:?}, cause={:?})", + "normalize::<{}>(value={:?}, param_env={:?})", std::any::type_name::(), value, param_env, - cause, ); // This is actually a consequence by the way `normalize_erasing_regions` works currently. @@ -196,9 +81,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { if self.next_trait_solver() { match crate::solve::deeply_normalize_with_skipped_universes::<_, ScrubbedTraitError<'tcx>>( - self, + &self, Unnormalized::new_wip(value), universes, + param_env, + &cause, ) { Ok(value) => { return Ok(Normalized { value, obligations: PredicateObligations::new() }); @@ -209,14 +96,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } } - if !needs_normalization(self.infcx, &value) { + if !needs_normalization(&self, &value) { return Ok(Normalized { value, obligations: PredicateObligations::new() }); } let mut normalizer = QueryNormalizer { infcx: &self, - cause: self, - param_env: self.param_env, + cause: &cause, + param_env: param_env, obligations: PredicateObligations::new(), cache: SsoHashMap::new(), anon_depth: 0, diff --git a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs index 2313ceaabd1ca..d6a70f36d1909 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs @@ -1,19 +1,21 @@ -use rustc_infer::infer::at::At; -use rustc_infer::traits::{TraitEngine, TraitErrors}; +use rustc_infer::infer::InferCtxt; +use rustc_infer::traits::{ObligationCause, TraitEngine, TraitErrors}; use rustc_macros::extension; -use rustc_middle::ty::{self, Ty, Unnormalized}; +use rustc_middle::ty::{self, ParamEnv, Ty, Unnormalized}; use thin_vec::ThinVec; use crate::traits::{NormalizeExt, Obligation}; #[extension(pub trait StructurallyNormalizeExt<'tcx>)] -impl<'tcx> At<'_, 'tcx> { +impl<'tcx> InferCtxt<'tcx> { fn structurally_normalize_ty( &self, ty: Unnormalized<'tcx, Ty<'tcx>>, fulfill_cx: &mut dyn TraitEngine<'tcx, E>, + param_env: ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, ) -> Result, ThinVec> { - self.structurally_normalize_term(ty.map(Into::into), fulfill_cx) + self.structurally_normalize_term(ty.map(Into::into), fulfill_cx, param_env, cause) .map(|term| term.expect_type()) } @@ -21,12 +23,14 @@ impl<'tcx> At<'_, 'tcx> { &self, ct: Unnormalized<'tcx, ty::Const<'tcx>>, fulfill_cx: &mut dyn TraitEngine<'tcx, E>, + param_env: ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, ) -> Result, ThinVec> { - if self.infcx.tcx.features().generic_const_exprs() { - return Ok(super::evaluate_const(&self.infcx, ct.skip_normalization(), self.param_env)); + if self.tcx.features().generic_const_exprs() { + return Ok(super::evaluate_const(&self, ct.skip_normalization(), param_env)); } - self.structurally_normalize_term(ct.map(Into::into), fulfill_cx) + self.structurally_normalize_term(ct.map(Into::into), fulfill_cx, param_env, cause) .map(|term| term.expect_const()) } @@ -34,16 +38,18 @@ impl<'tcx> At<'_, 'tcx> { &self, term: Unnormalized<'tcx, ty::Term<'tcx>>, fulfill_cx: &mut dyn TraitEngine<'tcx, E>, + param_env: ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, ) -> Result, ThinVec> { assert!( !term.as_ref().skip_normalization().is_infer(), "should have resolved vars before calling" ); - if self.infcx.next_trait_solver() { + if self.next_trait_solver() { let term = term.skip_normalization(); - if !self.infcx.tcx.renormalize_rigid_aliases() && !term.is_non_rigid_alias() { + if !self.tcx.renormalize_rigid_aliases() && !term.is_non_rigid_alias() { return Ok(term); }; @@ -51,27 +57,27 @@ impl<'tcx> At<'_, 'tcx> { return Ok(term); }; - let new_infer = self.infcx.next_term_var_of_alias_kind(alias, self.cause.span); + let new_infer = self.next_term_var_of_alias_kind(alias, cause.span); // We simply emit an `Projection` goal here, since that will take care of // normalizing the LHS of the projection until it is a rigid projection // (or a not-yet-defined opaque in scope). let obligation = Obligation::new( - self.infcx.tcx, - self.cause.clone(), - self.param_env, + self.tcx, + cause.clone(), + param_env, ty::ProjectionClause { projection_term: alias, term: new_infer }, ); - fulfill_cx.register_predicate_obligation(self.infcx, obligation); - let errors = fulfill_cx.try_evaluate_obligations(self.infcx); + fulfill_cx.register_predicate_obligation(&self, obligation); + let errors = fulfill_cx.try_evaluate_obligations(&self); if let TraitErrors::HasErrors(errors) = errors { return Err(errors); } - Ok(self.infcx.deeply_resolve_ignoring_regions(new_infer)) + Ok(self.resolve_vars_if_possible(new_infer)) } else { - Ok(self.normalize(term).into_value_registering_obligations(self.infcx, fulfill_cx)) + Ok(self.normalize(term, param_env, cause).into_value_registering_obligations(&self, fulfill_cx)) } } } diff --git a/compiler/rustc_traits/src/normalize_erasing_regions.rs b/compiler/rustc_traits/src/normalize_erasing_regions.rs index 5ee83ae651713..18c2cb5c3682f 100644 --- a/compiler/rustc_traits/src/normalize_erasing_regions.rs +++ b/compiler/rustc_traits/src/normalize_erasing_regions.rs @@ -24,7 +24,7 @@ fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable> + Par let PseudoCanonicalInput { typing_env, value } = goal; let (infcx, param_env) = tcx.infer_ctxt().ignoring_regions().build_with_typing_env(typing_env); let cause = ObligationCause::dummy(); - match infcx.at(&cause, param_env).query_normalize(value) { + match infcx.query_normalize(value, param_env, cause) { Ok(Normalized { value: normalized_value, obligations: normalized_obligations }) => { // We don't care about the `obligations`; they are // always only region relations, and we are about to diff --git a/compiler/rustc_traits/src/type_op.rs b/compiler/rustc_traits/src/type_op.rs index 3ab1e80622623..0fada33cc2a67 100644 --- a/compiler/rustc_traits/src/type_op.rs +++ b/compiler/rustc_traits/src/type_op.rs @@ -48,8 +48,7 @@ where let ParamEnvAnd { param_env, value: Normalize { value } } = key; let Normalized { value, obligations } = ocx .infcx - .at(&ObligationCause::dummy(), param_env) - .query_normalize(value.skip_normalization())?; + .query_normalize(value.skip_normalization(), param_env, ObligationCause::dummy())?; ocx.register_obligations(obligations); Ok(value) } From fd1afa5ddac8fd4f47ecb94de30e4e88a8c91d71 Mon Sep 17 00:00:00 2001 From: Fallible <118682743+fallible-algebra@users.noreply.github.com> Date: Tue, 22 Sep 2026 14:44:43 +0100 Subject: [PATCH 3/9] arghh --- compiler/rustc_hir_typeck/src/coercion.rs | 3 ++- compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 47e712c37aea4..5ddac00618b5a 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1045,7 +1045,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { match b.kind() { ty::FnPtr(_, b_hdr) => { let a_sig = self.sig_for_fn_def_coercion(a, Some(b_hdr.safety()))?; - + // Okay so, what does this part of the code actually do? Lol! + // What is an inferok. let InferOk { value: a_sig, mut obligations } = self.normalize(self.cause.span.clone(), Unnormalized::new_wip(a_sig)); let a = Ty::new_fn_ptr(self.tcx, a_sig); diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 1ad6225a8c467..cc49764b022bc 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -466,7 +466,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { T: TypeFoldable>, { self.register_infer_ok_obligations( - self.at(&self.misc(span), self.param_env).normalize(value), + self.infcx.normalize(value, self.param_env, &self.misc(span)), ) } From 627099918fdcb42493a5fde1ab97ff059b961b16 Mon Sep 17 00:00:00 2001 From: Fallible <118682743+fallible-algebra@users.noreply.github.com> Date: Wed, 23 Sep 2026 11:50:30 +0100 Subject: [PATCH 4/9] Compiles doesn't it --- compiler/rustc_hir_typeck/src/coercion.rs | 10 +-- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 12 ++-- compiler/rustc_hir_typeck/src/method/mod.rs | 10 ++- compiler/rustc_hir_typeck/src/opaque_types.rs | 8 ++- compiler/rustc_hir_typeck/src/writeback.rs | 5 +- compiler/rustc_infer/src/infer/at.rs | 62 +++++++------------ .../traits/fulfillment_errors.rs | 8 ++- .../src/error_reporting/traits/suggestions.rs | 7 ++- .../src/solve/normalize.rs | 42 +++++++------ .../src/traits/engine.rs | 33 +++++++--- .../src/traits/normalize.rs | 3 +- .../src/traits/query/normalize.rs | 4 +- .../src/traits/structural_normalize.rs | 4 +- compiler/rustc_traits/src/type_op.rs | 8 ++- src/librustdoc/clean/mod.rs | 11 ++-- src/librustdoc/html/format.rs | 29 ++++----- src/tools/clippy/clippy_utils/src/ty/mod.rs | 6 +- 17 files changed, 141 insertions(+), 121 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 5ddac00618b5a..57b8c185f18c1 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1045,10 +1045,12 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { match b.kind() { ty::FnPtr(_, b_hdr) => { let a_sig = self.sig_for_fn_def_coercion(a, Some(b_hdr.safety()))?; - // Okay so, what does this part of the code actually do? Lol! - // What is an inferok. - let InferOk { value: a_sig, mut obligations } = - self.normalize(self.cause.span.clone(), Unnormalized::new_wip(a_sig)); + let InferOk { value: a_sig, mut obligations } = NormalizeExt::normalize( + &self.infcx, + Unnormalized::new_wip(a_sig), + self.param_env.clone(), + &self.cause, + ); let a = Ty::new_fn_ptr(self.tcx, a_sig); let adjust = Adjust::Pointer(PointerCoercion::ReifyFnPointer(b_hdr.safety())); diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index cc49764b022bc..e0cef41a659cf 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -465,9 +465,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { where T: TypeFoldable>, { - self.register_infer_ok_obligations( - self.infcx.normalize(value, self.param_env, &self.misc(span)), - ) + self.register_infer_ok_obligations(self.infcx.normalize( + value, + self.param_env, + &self.misc(span), + )) } pub(crate) fn require_type_meets( @@ -1520,9 +1522,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // We need to use a separate variable here as otherwise the temporary for // `self.fulfillment_cx.borrow_mut()` is alive in the `Err` branch, resulting // in a reentrant borrow, causing an ICE. - let result = self.at(&self.misc(sp), self.param_env).structurally_normalize_const( + let result = self.structurally_normalize_const( Unnormalized::new_wip(ct), &mut *self.fulfillment_cx.borrow_mut(), + self.param_env, + &self.misc(sp), ); match result { Ok(normalized_ct) => normalized_ct, diff --git a/compiler/rustc_hir_typeck/src/method/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs index 16127b7d87f3d..65c0ee203494b 100644 --- a/compiler/rustc_hir_typeck/src/method/mod.rs +++ b/compiler/rustc_hir_typeck/src/method/mod.rs @@ -427,8 +427,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn_sig, ); - let InferOk { value: fn_sig, obligations: o } = - self.at(&obligation.cause, self.param_env).normalize(Unnormalized::new_wip(fn_sig)); + let InferOk { value: fn_sig, obligations: o } = NormalizeExt::normalize( + &self.infcx, + Unnormalized::new_wip(fn_sig), + self.param_env, + &obligation.cause, + ); obligations.extend(o); // Register obligations for the parameters. This will include the @@ -447,7 +451,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { move |_, _| predicates_cause.clone(), |clause| { let InferOk { value: pred, obligations: o } = - self.at(&obligation.cause, self.param_env).normalize(clause); + NormalizeExt::normalize(&self.infcx, clause, self.param_env, &obligation.cause); normalization_obligations.extend(o); assert!(!pred.has_escaping_bound_vars()); pred diff --git a/compiler/rustc_hir_typeck/src/opaque_types.rs b/compiler/rustc_hir_typeck/src/opaque_types.rs index c96144d849944..6bc5b6c7bb696 100644 --- a/compiler/rustc_hir_typeck/src/opaque_types.rs +++ b/compiler/rustc_hir_typeck/src/opaque_types.rs @@ -246,8 +246,12 @@ impl<'tcx> FnCtxt<'_, 'tcx> { } let cause = ObligationCause::misc(hidden_type.span, self.body_def_id); - let at = self.at(&cause, self.param_env); - let hidden_type = match solve::deeply_normalize(at, Unnormalized::new_wip(hidden_type)) { + let hidden_type = match solve::deeply_normalize( + &self.infcx, + Unnormalized::new_wip(hidden_type), + self.param_env, + &cause, + ) { Ok(hidden_type) => hidden_type, Err(errors) => { let guar = self.err_ctxt().report_fulfillment_errors(errors); diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index 923c0d49936c8..ba66020aec777 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -968,12 +968,13 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> { let mut value = if self.should_normalize && self.fcx.next_trait_solver() { let body_def_id = tcx.hir_body_owner_def_id(self.body.id()); let cause = ObligationCause::misc(self.span.to_span(tcx), body_def_id); - let at = self.fcx.at(&cause, self.fcx.param_env); let universes = vec![None; outer_exclusive_binder(&value).as_usize()]; match solve::deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals( - at, + &self.fcx.infcx, Unnormalized::new_wip(value), universes, + self.fcx.param_env, + &cause, ) { Ok((value, goals)) => { self.nested_goals.extend(goals); diff --git a/compiler/rustc_infer/src/infer/at.rs b/compiler/rustc_infer/src/infer/at.rs index 66a61d1ba56d3..70cd799b2df3d 100644 --- a/compiler/rustc_infer/src/infer/at.rs +++ b/compiler/rustc_infer/src/infer/at.rs @@ -129,7 +129,7 @@ impl<'tcx> InferCtxt<'tcx> { define_opaque_types: DefineOpaqueTypes, expected: T, actual: T, - param_env: ty::ParamEnv<'tcx>, + param_env: ty::ParamEnv<'tcx>, cause: &ObligationCause<'tcx>, ) -> InferResult<'tcx, ()> where @@ -164,22 +164,15 @@ impl<'tcx> InferCtxt<'tcx> { define_opaque_types: DefineOpaqueTypes, expected: T, actual: T, - param_env: ty::ParamEnv<'tcx>, + param_env: ty::ParamEnv<'tcx>, cause: &ObligationCause<'tcx>, ) -> InferResult<'tcx, ()> where T: ToTrace<'tcx>, { if self.next_trait_solver { - NextSolverRelate::relate( - &self, - param_env, - expected, - ty::Covariant, - actual, - cause.span, - ) - .map(|goals| self.goals_to_obligations_at(goals, cause)) + NextSolverRelate::relate(&self, param_env, expected, ty::Covariant, actual, cause.span) + .map(|goals| self.goals_to_obligations_at(goals, cause)) } else { let mut op = TypeRelating::new( &self, @@ -198,7 +191,7 @@ impl<'tcx> InferCtxt<'tcx> { define_opaque_types: DefineOpaqueTypes, expected: T, actual: T, - param_env: ty::ParamEnv<'tcx>, + param_env: ty::ParamEnv<'tcx>, cause: &ObligationCause<'tcx>, ) -> InferResult<'tcx, ()> where @@ -220,30 +213,18 @@ impl<'tcx> InferCtxt<'tcx> { trace: TypeTrace<'tcx>, expected: T, actual: T, - param_env: ty::ParamEnv<'tcx>, + param_env: ty::ParamEnv<'tcx>, cause: &ObligationCause<'tcx>, ) -> InferResult<'tcx, ()> where T: Relate>, { if self.next_trait_solver { - NextSolverRelate::relate( - &self, - param_env, - expected, - ty::Invariant, - actual, - cause.span, - ) - .map(|goals| self.goals_to_obligations_at(goals, cause)) + NextSolverRelate::relate(&self, param_env, expected, ty::Invariant, actual, cause.span) + .map(|goals| self.goals_to_obligations_at(goals, cause)) } else { - let mut op = TypeRelating::new( - &self, - trace, - param_env, - define_opaque_types, - ty::Invariant, - ); + let mut op = + TypeRelating::new(&self, trace, param_env, define_opaque_types, ty::Invariant); op.relate(expected, actual)?; Ok(InferOk { value: (), obligations: op.into_obligations() }) } @@ -255,7 +236,7 @@ impl<'tcx> InferCtxt<'tcx> { expected: T, variance: ty::Variance, actual: T, - param_env: ty::ParamEnv<'tcx>, + param_env: ty::ParamEnv<'tcx>, cause: &ObligationCause<'tcx>, ) -> InferResult<'tcx, ()> where @@ -264,7 +245,9 @@ impl<'tcx> InferCtxt<'tcx> { match variance { ty::Covariant => self.sub_at(define_opaque_types, expected, actual, param_env, cause), ty::Invariant => self.eq_at(define_opaque_types, expected, actual, param_env, cause), - ty::Contravariant => self.sup_at(define_opaque_types, expected, actual, param_env, cause), + ty::Contravariant => { + self.sup_at(define_opaque_types, expected, actual, param_env, cause) + } // We could make this make sense but it's not readily // exposed and I don't feel like dealing with it. Note @@ -280,7 +263,13 @@ impl<'tcx> InferCtxt<'tcx> { /// this can result in an error (e.g., if asked to compute LUB of /// u32 and i32), it is meaningful to call one of them the /// "expected type". - pub fn lub_at(self, expected: T, actual: T, param_env: ty::ParamEnv<'tcx>, cause: &ObligationCause<'tcx>) -> InferResult<'tcx, T> + pub fn lub_at( + self, + expected: T, + actual: T, + param_env: ty::ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, + ) -> InferResult<'tcx, T> where T: ToTrace<'tcx>, { @@ -297,19 +286,14 @@ impl<'tcx> InferCtxt<'tcx> { fn goals_to_obligations_at( &self, goals: Vec>>, - cause: &ObligationCause<'tcx> + cause: &ObligationCause<'tcx>, ) -> InferOk<'tcx, ()> { InferOk { value: (), obligations: goals .into_iter() .map(|goal| { - Obligation::new( - self.tcx, - cause.clone(), - goal.param_env, - goal.predicate, - ) + Obligation::new(self.tcx, cause.clone(), goal.param_env, goal.predicate) }) .collect(), } diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index f136ec5d35892..a0fcfb0e2c240 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -3048,9 +3048,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let cleaned_pred = pred.fold_with(&mut ParamToVarFolder { infcx: self, var_map: Default::default() }); - let InferOk { value: cleaned_pred, .. } = self - .infcx - .normalize(Unnormalized::new_wip(cleaned_pred), param_env, &ObligationCause::dummy(),); + let InferOk { value: cleaned_pred, .. } = self.infcx.normalize( + Unnormalized::new_wip(cleaned_pred), + param_env, + &ObligationCause::dummy(), + ); let obligation = Obligation::new(self.tcx, ObligationCause::dummy(), param_env, cleaned_pred); diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index f8564cc8da255..6b6e7d2dd0e9b 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -5033,8 +5033,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { [trait_pred.self_ty()], ) }); - let InferOk { value: projection_ty, .. } = self - .normalize(Unnormalized::new_wip(projection_ty), obligation.param_env, &obligation.cause); + let InferOk { value: projection_ty, .. } = self.normalize( + Unnormalized::new_wip(projection_ty), + obligation.param_env, + &obligation.cause, + ); debug!( normalized_projection_type = ?self.deeply_resolve_ignoring_regions(projection_ty) diff --git a/compiler/rustc_trait_selection/src/solve/normalize.rs b/compiler/rustc_trait_selection/src/solve/normalize.rs index 591f1eb371bf7..ee25d4cbbed41 100644 --- a/compiler/rustc_trait_selection/src/solve/normalize.rs +++ b/compiler/rustc_trait_selection/src/solve/normalize.rs @@ -17,7 +17,12 @@ use crate::solve::{Certainty, SolverDelegate}; use crate::traits::{BoundVarReplacer, ScrubbedTraitError}; /// see `normalize_with_universes`. -pub fn normalize<'tcx, T>(infcx: &InferCtxt<'tcx>, value: Unnormalized<'tcx, T>, param_env: ty::ParamEnv<'tcx>, cause: &ObligationCause<'tcx>) -> Normalized<'tcx, T> +pub fn normalize<'tcx, T>( + infcx: &InferCtxt<'tcx>, + value: Unnormalized<'tcx, T>, + param_env: ty::ParamEnv<'tcx>, + cause: &ObligationCause<'tcx>, +) -> Normalized<'tcx, T> where T: TypeFoldable>, { @@ -35,7 +40,7 @@ fn normalize_with_universes<'tcx, T>( infcx: &InferCtxt<'tcx>, value: Unnormalized<'tcx, T>, universes: Vec>, - param_env: ty::ParamEnv<'tcx>, + param_env: ty::ParamEnv<'tcx>, cause: &ObligationCause<'tcx>, ) -> Normalized<'tcx, T> where @@ -72,13 +77,17 @@ where if let Ok(value) = value.try_fold_with(&mut folder) { let obligations = stalled_goals .into_iter() - .map(|goal| { - Obligation::new(infcx.tcx, cause.clone(), goal.param_env, goal.predicate) - }) + .map(|goal| Obligation::new(infcx.tcx, cause.clone(), goal.param_env, goal.predicate)) .collect(); Normalized { value, obligations } } else { - let mut replacer = ReplaceAliasWithInfer { infcx, obligations: Default::default(), universes, param_env, cause }; + let mut replacer = ReplaceAliasWithInfer { + infcx, + obligations: Default::default(), + universes, + param_env, + cause, + }; let value = original_value.fold_with(&mut replacer); Normalized { value, obligations: replacer.obligations } } @@ -86,15 +95,14 @@ where struct ReplaceAliasWithInfer<'me, 'tcx> { infcx: &'me InferCtxt<'tcx>, - param_env: ty::ParamEnv<'tcx>, + param_env: ty::ParamEnv<'tcx>, cause: &'me ObligationCause<'tcx>, obligations: PredicateObligations<'tcx>, universes: Vec>, - } impl<'me, 'tcx> ReplaceAliasWithInfer<'me, 'tcx> { - fn term_to_infer(&mut self, alias_term: ty::AliasTerm<'tcx>, ) -> ty::Term<'tcx> { + fn term_to_infer(&mut self, alias_term: ty::AliasTerm<'tcx>) -> ty::Term<'tcx> { let infcx = self.infcx; let infer_term = infcx.next_term_var_of_alias_kind(alias_term, self.cause.span); let obligation = Obligation::new( @@ -156,11 +164,8 @@ impl<'me, 'tcx> TypeFolder> for ReplaceAliasWithInfer<'me, 'tcx> { } if ct.has_escaping_bound_vars() { - let (replaced, ..) = BoundVarReplacer::replace_bound_vars( - self.infcx, - &mut self.universes, - alias_const, - ); + let (replaced, ..) = + BoundVarReplacer::replace_bound_vars(self.infcx, &mut self.universes, alias_const); let _ = self.term_to_infer(replaced.into()); ct } else { @@ -224,14 +229,15 @@ pub fn deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals<'tc infcx: &InferCtxt<'tcx>, value: Unnormalized<'tcx, T>, universes: Vec>, - param_env: ty::ParamEnv<'tcx>, + param_env: ty::ParamEnv<'tcx>, cause: &ObligationCause<'tcx>, ) -> Result<(T, Vec>>), ThinVec> where T: TypeFoldable>, E: FromSolverError<'tcx, NextSolverError<'tcx>>, { - let Normalized { value, obligations } = normalize_with_universes(infcx, value, universes, param_env, cause); + let Normalized { value, obligations } = + normalize_with_universes(infcx, value, universes, param_env, cause); let mut fulfill_cx = FulfillmentCtxt::new(infcx); for pred in obligations { @@ -271,9 +277,9 @@ pub(crate) fn deeply_normalize_for_diagnostics<'tcx, T: TypeFoldable { pub infcx: &'a InferCtxt<'tcx>, diff --git a/compiler/rustc_trait_selection/src/traits/engine.rs b/compiler/rustc_trait_selection/src/traits/engine.rs index d7e1f34a1b480..28f4dc5ac3c8b 100644 --- a/compiler/rustc_trait_selection/src/traits/engine.rs +++ b/compiler/rustc_trait_selection/src/traits/engine.rs @@ -429,9 +429,12 @@ where // implied_bounds.insert(ty); let cause = ObligationCause::misc(span, def_id); let infcx = self.infcx; - match infcx - .deeply_normalize(Unnormalized::new_wip(ty), &mut *self.engine.borrow_mut(), param_env, &cause) - { + match infcx.deeply_normalize( + Unnormalized::new_wip(ty), + &mut *self.engine.borrow_mut(), + param_env, + &cause, + ) { // Insert well-formed types, ignoring duplicates. Ok(normalized) => drop(implied_bounds.insert(normalized)), Err(normalization_errors) => errors.extend(normalization_errors), @@ -456,8 +459,12 @@ where param_env: ty::ParamEnv<'tcx>, value: Unnormalized<'tcx, Ty<'tcx>>, ) -> Result, ThinVec> { - self.infcx - .structurally_normalize_ty(value, &mut *self.engine.borrow_mut(), param_env, cause) + self.infcx.structurally_normalize_ty( + value, + &mut *self.engine.borrow_mut(), + param_env, + cause, + ) } pub fn structurally_normalize_const( @@ -466,8 +473,12 @@ where param_env: ty::ParamEnv<'tcx>, value: Unnormalized<'tcx, ty::Const<'tcx>>, ) -> Result, ThinVec> { - self.infcx - .structurally_normalize_const(value, &mut *self.engine.borrow_mut(), param_env, cause) + self.infcx.structurally_normalize_const( + value, + &mut *self.engine.borrow_mut(), + param_env, + cause, + ) } pub fn structurally_normalize_term( @@ -476,7 +487,11 @@ where param_env: ty::ParamEnv<'tcx>, value: Unnormalized<'tcx, ty::Term<'tcx>>, ) -> Result, ThinVec> { - self.infcx - .structurally_normalize_term(value, &mut *self.engine.borrow_mut(), param_env, cause) + self.infcx.structurally_normalize_term( + value, + &mut *self.engine.borrow_mut(), + param_env, + cause, + ) } } diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index 730e4d0a02e1e..0f1fd6aa040af 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -33,7 +33,8 @@ impl<'tcx> InferCtxt<'tcx> { cause: &ObligationCause<'tcx>, ) -> InferOk<'tcx, T> { if self.next_trait_solver() { - let Normalized { value, obligations } = crate::solve::normalize(self, value, param_env, cause); + let Normalized { value, obligations } = + crate::solve::normalize(self, value, param_env, cause); InferOk { value, obligations } } else { let mut selcx = SelectionContext::new(self); diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index a40ec6d776246..646d23e111602 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -45,7 +45,7 @@ impl<'tcx> InferCtxt<'tcx> { /// likely be removed as trait solver operations are already cached by the query /// system making this redundant. fn query_normalize( - &self, + &self, value: T, param_env: ty::ParamEnv<'tcx>, cause: ObligationCause<'tcx>, @@ -103,7 +103,7 @@ impl<'tcx> InferCtxt<'tcx> { let mut normalizer = QueryNormalizer { infcx: &self, cause: &cause, - param_env: param_env, + param_env, obligations: PredicateObligations::new(), cache: SsoHashMap::new(), anon_depth: 0, diff --git a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs index d6a70f36d1909..14dafd1dd04ed 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs @@ -77,7 +77,9 @@ impl<'tcx> InferCtxt<'tcx> { Ok(self.resolve_vars_if_possible(new_infer)) } else { - Ok(self.normalize(term, param_env, cause).into_value_registering_obligations(&self, fulfill_cx)) + Ok(self + .normalize(term, param_env, cause) + .into_value_registering_obligations(&self, fulfill_cx)) } } } diff --git a/compiler/rustc_traits/src/type_op.rs b/compiler/rustc_traits/src/type_op.rs index 0fada33cc2a67..4c773e6f269bd 100644 --- a/compiler/rustc_traits/src/type_op.rs +++ b/compiler/rustc_traits/src/type_op.rs @@ -46,9 +46,11 @@ where T: fmt::Debug + TypeFoldable>, { let ParamEnvAnd { param_env, value: Normalize { value } } = key; - let Normalized { value, obligations } = ocx - .infcx - .query_normalize(value.skip_normalization(), param_env, ObligationCause::dummy())?; + let Normalized { value, obligations } = ocx.infcx.query_normalize( + value.skip_normalization(), + param_env, + ObligationCause::dummy(), + )?; ocx.register_obligations(obligations); Ok(value) } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 09dbd279988f6..5465c097d9de8 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2026,9 +2026,8 @@ fn normalize<'tcx>( // Try to normalize `::T` to a type let infcx = cx.tcx.infer_ctxt().build(TypingMode::non_body_analysis()); let normalized = infcx - .at(&ObligationCause::dummy(), cx.param_env) - .query_normalize(ty) - .map(|resolved| infcx.deeply_resolve_ignoring_regions(resolved.value)); + .query_normalize(ty, cx.param_env, ObligationCause::dummy()) + .map(|resolved| infcx.resolve_vars_if_possible(resolved.value)); match normalized { Ok(normalized_value) => { debug!("normalized {ty:?} to {normalized_value:?}"); @@ -2604,8 +2603,7 @@ pub(crate) fn clean_variant_def_with_args<'tcx>( // note: we do not use try_normalize_erasing_regions since we // do care about showing the regions let ty = infcx - .at(&ObligationCause::dummy(), cx.param_env) - .query_normalize(ty) + .query_normalize(ty, cx.param_env, ObligationCause::dummy()) .map(|normalized| normalized.value) .unwrap_or(ty); @@ -2629,8 +2627,7 @@ pub(crate) fn clean_variant_def_with_args<'tcx>( // note: we do not use try_normalize_erasing_regions since we // do care about showing the regions let ty = infcx - .at(&ObligationCause::dummy(), cx.param_env) - .query_normalize(ty) + .query_normalize(ty, cx.param_env, ObligationCause::dummy()) .map(|normalized| normalized.value) .unwrap_or(ty); diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index f779fce47cd2f..355a6c81d3320 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -514,23 +514,18 @@ fn generate_item_def_id_path( // No need to try to infer the actual parent item if it's not an associated item from the `impl` // block. - if def_id != original_def_id - && let DefKind::Impl { of_trait } = tcx.def_kind(def_id) - { - let ty = impl_self_ty(tcx, def_id); - // If this is a dyn trait, we want to get the actual trait from which the method comes from. - // Since a `dyn trait` (as of 2026) can only be composed of a trait plus auto traits, we - // look for the trait and ignore auto traits. - if let ty::Dynamic(traits, _) = ty.kind() - && let Some(trait_def_id) = - traits.iter().find_map(|trait_| match trait_.skip_binder() { - ty::ExistentialPredicate::Trait(t) => Some(t.def_id), - ty::ExistentialPredicate::Projection(p) => Some(p.trait_ref(tcx).def_id), - ty::ExistentialPredicate::AutoTrait(_) => None, - }) - { - def_id = trait_def_id; - } else if let Some(new_def_id) = ty.ty_adt_def().map(|adt| adt.did()) { + if def_id != original_def_id && matches!(tcx.def_kind(def_id), DefKind::Impl { .. }) { + let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis()); + let ty = tcx.type_of(def_id); + let ty = infcx + .query_normalize( + ty::Binder::dummy(ty.instantiate_identity().skip_norm_wip()), + tcx.param_env(def_id), + ObligationCause::dummy(), + ) + .map(|resolved| infcx.resolve_vars_if_possible(resolved.value).skip_binder()) + .unwrap_or(ty.skip_binder()); + if let Some(new_def_id) = ty.ty_adt_def().map(|adt| adt.did()) { def_id = new_def_id; maybe_have_impl_not_in_def_crate = !of_trait && !original_def_id.is_local() diff --git a/src/tools/clippy/clippy_utils/src/ty/mod.rs b/src/tools/clippy/clippy_utils/src/ty/mod.rs index 89174b281b773..41d79accbd036 100644 --- a/src/tools/clippy/clippy_utils/src/ty/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ty/mod.rs @@ -1411,8 +1411,7 @@ pub fn make_normalized_projection_with_regions<'tcx>( let cause = ObligationCause::dummy(); let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env); match infcx - .at(&cause, param_env) - .query_normalize(Ty::new_alias(tcx, ty::IsRigid::No, ty)) + .query_normalize(Ty::new_alias(tcx, ty::IsRigid::No, ty), param_env, cause) { Ok(ty) => Some(ty.value), Err(e) => { @@ -1428,8 +1427,7 @@ pub fn normalize_with_regions<'tcx>(tcx: TyCtxt<'tcx>, typing_env: ty::TypingEnv let cause = ObligationCause::dummy(); let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env); infcx - .at(&cause, param_env) - .query_normalize(ty) + .query_normalize(ty, param_env, cause) .map_or(ty, |ty| ty.value) } From b2ad290b5439adefdabd2f355a2d9e6ee7336b0a Mon Sep 17 00:00:00 2001 From: Fallible <118682743+fallible-algebra@users.noreply.github.com> Date: Mon, 28 Sep 2026 11:49:41 +0100 Subject: [PATCH 5/9] Actually remove At --- .../src/coherence/orphan.rs | 4 +- compiler/rustc_hir_typeck/src/callee.rs | 9 +- compiler/rustc_hir_typeck/src/cast.rs | 3 +- compiler/rustc_hir_typeck/src/closure.rs | 8 +- compiler/rustc_hir_typeck/src/coercion.rs | 34 ++- compiler/rustc_hir_typeck/src/demand.rs | 24 +- compiler/rustc_hir_typeck/src/expr.rs | 4 +- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 4 +- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 15 +- .../rustc_hir_typeck/src/method/confirm.rs | 2 +- compiler/rustc_hir_typeck/src/method/probe.rs | 4 +- compiler/rustc_infer/src/infer/at.rs | 221 +----------------- .../src/infer/canonical/query_response.rs | 26 +-- compiler/rustc_infer/src/infer/mod.rs | 4 +- .../rustc_infer/src/infer/opaque_types/mod.rs | 30 ++- .../rustc_infer/src/infer/relate/lattice.rs | 35 ++- compiler/rustc_lint/src/runtime_symbols.rs | 2 +- .../src/error_reporting/infer/mod.rs | 4 +- .../src/error_reporting/traits/suggestions.rs | 10 +- .../src/traits/auto_trait.rs | 4 +- .../src/traits/coherence.rs | 115 ++++----- .../src/traits/effects.rs | 9 +- .../src/traits/engine.rs | 18 +- .../src/traits/fulfill.rs | 22 +- .../src/traits/project.rs | 10 +- .../src/traits/select/confirmation.rs | 48 +++- .../src/traits/select/mod.rs | 90 ++++--- src/librustdoc/clean/blanket_impl.rs | 4 +- 28 files changed, 352 insertions(+), 411 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 496994096d69b..4e045a2fb8028 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -371,10 +371,12 @@ fn orphan_check<'tcx>( for (arg, id_arg) in std::iter::zip(args, ty::GenericArgs::identity_for_item(tcx, impl_def_id)) { - let _ = infcx.at(&cause, ty::ParamEnv::empty()).eq( + let _ = infcx.eq_at( DefineOpaqueTypes::No, arg, id_arg, + ty::ParamEnv::empty(), + &cause, ); } infcx.deeply_resolve_ignoring_regions(tys) diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index 025c64896edb7..e6ca171638ce3 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -730,8 +730,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // adjustments search for mapped arguments. let cause = self.cause(call_expr.span, ObligationCauseCode::Misc); if self - .at(&cause, self.param_env) - .sup(DefineOpaqueTypes::Yes, formal_input_tys[0], adjusted_arg_type) + .sup_at( + DefineOpaqueTypes::Yes, + formal_input_tys[0], + adjusted_arg_type, + self.param_env, + &cause, + ) .is_err() { return do_check(); diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 02e6b8188a876..7e82ff46a8523 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -1091,8 +1091,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { // This is `fcx.demand_eqtype`, but inlined to give a better error. let cause = fcx.misc(self.span); if fcx - .at(&cause, fcx.param_env) - .eq(DefineOpaqueTypes::Yes, src_obj, dst_obj) + .eq_at(DefineOpaqueTypes::Yes, src_obj, dst_obj, fcx.param_env, &cause) .map(|infer_ok| fcx.register_infer_ok_obligations(infer_ok)) .is_err() { diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 79b4eff9153b0..6b111f4af78c8 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -798,20 +798,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) { // Check that E' = S'. let cause = self.misc(hir_ty.span); - let InferOk { value: (), obligations } = self.at(&cause, self.param_env).eq( + let InferOk { value: (), obligations } = self.eq_at( DefineOpaqueTypes::Yes, *expected_ty, supplied_ty, + self.param_env, + &cause, )?; all_obligations.extend(obligations); } let supplied_output_ty = supplied_sig.output(); let cause = &self.misc(decl.output.span()); - let InferOk { value: (), obligations } = self.at(cause, self.param_env).eq( + let InferOk { value: (), obligations } = self.eq_at( DefineOpaqueTypes::Yes, expected_sigs.liberated_sig.output(), supplied_output_ty, + self.param_env, + cause, )?; all_obligations.extend(obligations); diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 57b8c185f18c1..e6c364dbe1ee0 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -165,12 +165,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { self.commit_if_ok(|snapshot| { let outer_universe = self.infcx.universe(); - let at = self.at(&self.cause, self.fcx.param_env); - let res = if self.use_lub { - at.lub(b, a) + self.lub_at(b, a, self.fcx.param_env, &self.cause) } else { - at.sup(DefineOpaqueTypes::Yes, b, a) + self.sup_at(DefineOpaqueTypes::Yes, b, a, self.fcx.param_env, &self.cause) .map(|InferOk { value: (), obligations }| InferOk { value: b, obligations }) }; @@ -1375,7 +1373,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Err(TypeError::Mismatch) } } else { - self.at(cause, self.param_env).lub(prev_ty, new_ty) + self.lub_at(prev_ty, new_ty, self.param_env, cause) }; self.leak_check(outer_universe, Some(snapshot))?; @@ -1414,8 +1412,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // The signature must match. let (a_sig, b_sig) = self.normalize(new.span, Unnormalized::new_wip((a_sig, b_sig))); let sig = self - .at(cause, self.param_env) - .lub(a_sig, b_sig) + .lub_at(a_sig, b_sig, self.param_env, cause) .map(|ok| self.register_infer_ok_obligations(ok))?; // Reify both sides and return the reified fn pointer type. @@ -1729,17 +1726,18 @@ impl<'tcx> CoerceMany<'tcx> { // // Another example is `break` with no argument expression. assert!(expression_ty.is_unit(), "if let hack without unit type"); - fcx.at(cause, fcx.param_env) - .eq( - // needed for tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs - DefineOpaqueTypes::Yes, - expected, - found, - ) - .map(|infer_ok| { - fcx.register_infer_ok_obligations(infer_ok); - expression_ty - }) + fcx.eq_at( + // needed for tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs + DefineOpaqueTypes::Yes, + expected, + found, + fcx.param_env, + cause, + ) + .map(|infer_ok| { + fcx.register_infer_ok_obligations(infer_ok); + expression_ty + }) }; debug!(?result); diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index e1ad43f0c00c9..14388a99bf7c7 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -190,8 +190,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected: Ty<'tcx>, actual: Ty<'tcx>, ) -> Result<(), Diag<'a>> { - self.at(cause, self.param_env) - .sup(DefineOpaqueTypes::Yes, expected, actual) + self.sup_at(DefineOpaqueTypes::Yes, expected, actual, self.param_env, cause) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) .map_err(|e| { self.err_ctxt().report_mismatched_types(cause, self.param_env, expected, actual, e) @@ -219,8 +218,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected: Ty<'tcx>, actual: Ty<'tcx>, ) -> Result<(), Diag<'a>> { - self.at(cause, self.param_env) - .eq(DefineOpaqueTypes::Yes, expected, actual) + self.eq_at(DefineOpaqueTypes::Yes, expected, actual, self.param_env, cause) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) .map_err(|e| { self.err_ctxt().report_mismatched_types(cause, self.param_env, expected, actual, e) @@ -416,8 +414,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } }; let _ = self - .at(&ObligationCause::dummy(), self.param_env) - .eq(DefineOpaqueTypes::Yes, *input_arg, arg_ty) + .eq_at( + DefineOpaqueTypes::Yes, + *input_arg, + arg_ty, + self.param_env, + &ObligationCause::dummy(), + ) .ok()?; self.select_obligations_where_possible(|errs| { // Yeet the errors, we're already reporting errors. @@ -498,8 +501,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .ok() .and_then(|method| { let _ = self - .at(&ObligationCause::dummy(), self.param_env) - .eq(DefineOpaqueTypes::Yes, ideal_rcvr_ty, expected_ty) + .eq_at( + DefineOpaqueTypes::Yes, + ideal_rcvr_ty, + expected_ty, + self.param_env, + &ObligationCause::dummy(), + ) .ok()?; Some(method) }); diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index dbe5a51b25b45..df124c10cb057 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -2101,7 +2101,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Some(_) = remaining_fields.remove(&ident) { let target_ty = self.field_ty(base_expr.span, f, args); let cause = self.misc(base_expr.span); - match self.at(&cause, self.param_env).sup( + match self.sup_at( // We're already using inference variables for any params, // and don't allow converting between different structs, // so there is no way this ever actually defines an opaque @@ -2109,6 +2109,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { DefineOpaqueTypes::Yes, target_ty, fru_ty, + self.param_env, + &cause, ) { Ok(InferOk { obligations, value: () }) => { self.register_predicates(obligations) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index e0cef41a659cf..4304314f43634 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -1449,10 +1449,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // This also occurs for an enum variant on a type alias. let impl_ty = self.normalize(span, tcx.type_of(impl_def_id).instantiate(tcx, args)); let self_ty = self.normalize(span, Unnormalized::new_wip(self_ty)); - match self.at(&self.misc(span), self.param_env).eq( + match self.eq_at( DefineOpaqueTypes::Yes, impl_ty, self_ty, + self.param_env, + &self.misc(span), ) { Ok(ok) => self.register_infer_ok_obligations(ok), Err(_) => { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 937182c2030da..8fef69cae4c8f 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -396,10 +396,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // 3. Check if the formal type is actually equal to the checked one // and register any such obligations for future type checks. - let formal_ty_error = self.at(&self.misc(provided_arg.span), self.param_env).eq( + let formal_ty_error = self.eq_at( DefineOpaqueTypes::Yes, formal_input_ty, coerced_ty, + self.param_env, + &self.misc(provided_arg.span), ); // If neither check failed, the types are compatible @@ -3223,9 +3225,14 @@ impl<'a, 'tcx> ArgMatchingCtxt<'a, 'tcx> { // Using probe here, since we don't want this subtyping to affect inference. let subtyping_error = self.probe(|_| { - self.at(&self.misc(arg_span), self.param_env) - .sup(DefineOpaqueTypes::Yes, formal_input_ty, coerced_ty) - .err() + self.sup_at( + DefineOpaqueTypes::Yes, + formal_input_ty, + coerced_ty, + self.param_env, + &self.misc(arg_span), + ) + .err() }); // Same as above: if either the coerce type or the checked type is an error type, diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index 4518e419aea0f..96ec440b95f74 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -560,7 +560,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { self_ty, method_self_ty, self.span, pick ); let cause = self.cause(self.self_expr.span, ObligationCauseCode::Misc); - match self.at(&cause, self.param_env).sup(DefineOpaqueTypes::Yes, method_self_ty, self_ty) { + match self.sup_at(DefineOpaqueTypes::Yes, method_self_ty, self_ty, self.param_env, &cause) { Ok(InferOk { obligations, value: () }) => { self.register_predicates(obligations); } diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index aee246a61fb1e..3b6cdf6eb6f08 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -1971,10 +1971,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { self.xform_self_ty(candidate.item, trait_ref.self_ty(), trait_ref.args); // Guide the trait selection to show impls that have methods whose type matches // up with the `self` parameter of the method. - let _ = self.at(&ObligationCause::dummy(), self.param_env).sup( + let _ = self.sup_at( DefineOpaqueTypes::Yes, xform_self_ty, self_ty, + self.param_env, + &ObligationCause::dummy(), ); match self.select_trait_candidate_for_diagnostics(trait_ref) { Ok(Some(traits::ImplSource::UserDefined(ref impl_data))) => { diff --git a/compiler/rustc_infer/src/infer/at.rs b/compiler/rustc_infer/src/infer/at.rs index 70cd799b2df3d..5339860c8721d 100644 --- a/compiler/rustc_infer/src/infer/at.rs +++ b/compiler/rustc_infer/src/infer/at.rs @@ -46,24 +46,7 @@ pub enum DefineOpaqueTypes { No, } -// #[deprecated = "Get rid of this :("] -#[derive(Clone, Copy)] -pub struct At<'a, 'tcx> { - pub infcx: &'a InferCtxt<'tcx>, - pub cause: &'a ObligationCause<'tcx>, - pub param_env: ty::ParamEnv<'tcx>, -} - impl<'tcx> InferCtxt<'tcx> { - #[inline] - pub fn at<'a>( - &'a self, - cause: &'a ObligationCause<'tcx>, - param_env: ty::ParamEnv<'tcx>, - ) -> At<'a, 'tcx> { - At { infcx: self, cause, param_env } - } - /// Forks the inference context, creating a new inference context with the same inference /// variables in the same state. This can be used to "branch off" many tests from the same /// common state. @@ -125,7 +108,7 @@ impl<'tcx> InferCtxt<'tcx> { } pub fn sup_at( - self, + &self, define_opaque_types: DefineOpaqueTypes, expected: T, actual: T, @@ -137,7 +120,7 @@ impl<'tcx> InferCtxt<'tcx> { { if self.next_trait_solver { NextSolverRelate::relate( - &self, + self, param_env, expected, ty::Contravariant, @@ -160,7 +143,7 @@ impl<'tcx> InferCtxt<'tcx> { /// Makes `expected <: actual`. pub fn sub_at( - self, + &self, define_opaque_types: DefineOpaqueTypes, expected: T, actual: T, @@ -171,7 +154,7 @@ impl<'tcx> InferCtxt<'tcx> { T: ToTrace<'tcx>, { if self.next_trait_solver { - NextSolverRelate::relate(&self, param_env, expected, ty::Covariant, actual, cause.span) + NextSolverRelate::relate(self, param_env, expected, ty::Covariant, actual, cause.span) .map(|goals| self.goals_to_obligations_at(goals, cause)) } else { let mut op = TypeRelating::new( @@ -187,7 +170,7 @@ impl<'tcx> InferCtxt<'tcx> { } pub fn eq_at( - self, + &self, define_opaque_types: DefineOpaqueTypes, expected: T, actual: T, @@ -208,7 +191,7 @@ impl<'tcx> InferCtxt<'tcx> { } pub fn eq_trace_at( - self, + &self, define_opaque_types: DefineOpaqueTypes, trace: TypeTrace<'tcx>, expected: T, @@ -220,7 +203,7 @@ impl<'tcx> InferCtxt<'tcx> { T: Relate>, { if self.next_trait_solver { - NextSolverRelate::relate(&self, param_env, expected, ty::Invariant, actual, cause.span) + NextSolverRelate::relate(self, param_env, expected, ty::Invariant, actual, cause.span) .map(|goals| self.goals_to_obligations_at(goals, cause)) } else { let mut op = @@ -231,7 +214,7 @@ impl<'tcx> InferCtxt<'tcx> { } pub fn relate_at( - self, + &self, define_opaque_types: DefineOpaqueTypes, expected: T, variance: ty::Variance, @@ -264,7 +247,7 @@ impl<'tcx> InferCtxt<'tcx> { /// u32 and i32), it is meaningful to call one of them the /// "expected type". pub fn lub_at( - self, + &self, expected: T, actual: T, param_env: ty::ParamEnv<'tcx>, @@ -304,192 +287,6 @@ pub trait ToTrace<'tcx>: Relate> + Copy { fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx>; } -impl<'a, 'tcx> At<'a, 'tcx> { - /// Makes `actual <: expected`. For example, if type-checking a - /// call like `foo(x)`, where `foo: fn(i32)`, you might have - /// `sup(i32, x)`, since the "expected" type is the type that - /// appears in the signature. - pub fn sup( - self, - define_opaque_types: DefineOpaqueTypes, - expected: T, - actual: T, - ) -> InferResult<'tcx, ()> - where - T: ToTrace<'tcx>, - { - if self.infcx.next_trait_solver { - NextSolverRelate::relate( - self.infcx, - self.param_env, - expected, - ty::Contravariant, - actual, - self.cause.span, - ) - .map(|goals| self.goals_to_obligations(goals)) - } else { - let mut op = TypeRelating::new( - self.infcx, - ToTrace::to_trace(self.cause, expected, actual), - self.param_env, - define_opaque_types, - ty::Contravariant, - ); - op.relate(expected, actual)?; - Ok(InferOk { value: (), obligations: op.into_obligations() }) - } - } - - /// Makes `expected <: actual`. - pub fn sub( - self, - define_opaque_types: DefineOpaqueTypes, - expected: T, - actual: T, - ) -> InferResult<'tcx, ()> - where - T: ToTrace<'tcx>, - { - if self.infcx.next_trait_solver { - NextSolverRelate::relate( - self.infcx, - self.param_env, - expected, - ty::Covariant, - actual, - self.cause.span, - ) - .map(|goals| self.goals_to_obligations(goals)) - } else { - let mut op = TypeRelating::new( - self.infcx, - ToTrace::to_trace(self.cause, expected, actual), - self.param_env, - define_opaque_types, - ty::Covariant, - ); - op.relate(expected, actual)?; - Ok(InferOk { value: (), obligations: op.into_obligations() }) - } - } - - /// Makes `expected == actual`. - pub fn eq( - self, - define_opaque_types: DefineOpaqueTypes, - expected: T, - actual: T, - ) -> InferResult<'tcx, ()> - where - T: ToTrace<'tcx>, - { - self.eq_trace( - define_opaque_types, - ToTrace::to_trace(self.cause, expected, actual), - expected, - actual, - ) - } - - /// Makes `expected == actual`. - pub fn eq_trace( - self, - define_opaque_types: DefineOpaqueTypes, - trace: TypeTrace<'tcx>, - expected: T, - actual: T, - ) -> InferResult<'tcx, ()> - where - T: Relate>, - { - if self.infcx.next_trait_solver { - NextSolverRelate::relate( - self.infcx, - self.param_env, - expected, - ty::Invariant, - actual, - self.cause.span, - ) - .map(|goals| self.goals_to_obligations(goals)) - } else { - let mut op = TypeRelating::new( - self.infcx, - trace, - self.param_env, - define_opaque_types, - ty::Invariant, - ); - op.relate(expected, actual)?; - Ok(InferOk { value: (), obligations: op.into_obligations() }) - } - } - - pub fn relate( - self, - define_opaque_types: DefineOpaqueTypes, - expected: T, - variance: ty::Variance, - actual: T, - ) -> InferResult<'tcx, ()> - where - T: ToTrace<'tcx>, - { - match variance { - ty::Covariant => self.sub(define_opaque_types, expected, actual), - ty::Invariant => self.eq(define_opaque_types, expected, actual), - ty::Contravariant => self.sup(define_opaque_types, expected, actual), - - // We could make this make sense but it's not readily - // exposed and I don't feel like dealing with it. Note - // that bivariance in general does a bit more than just - // *nothing*, it checks that the types are the same - // "modulo variance" basically. - ty::Bivariant => panic!("Bivariant given to `relate()`"), - } - } - - /// Computes the least-upper-bound, or mutual supertype, of two - /// values. The order of the arguments doesn't matter, but since - /// this can result in an error (e.g., if asked to compute LUB of - /// u32 and i32), it is meaningful to call one of them the - /// "expected type". - pub fn lub(self, expected: T, actual: T) -> InferResult<'tcx, T> - where - T: ToTrace<'tcx>, - { - let mut op = LatticeOp::new( - self.infcx, - ToTrace::to_trace(self.cause, expected, actual), - self.param_env, - LatticeOpKind::Lub, - ); - let value = op.relate(expected, actual)?; - Ok(InferOk { value, obligations: op.into_obligations() }) - } - - fn goals_to_obligations( - &self, - goals: Vec>>, - ) -> InferOk<'tcx, ()> { - InferOk { - value: (), - obligations: goals - .into_iter() - .map(|goal| { - Obligation::new( - self.infcx.tcx, - self.cause.clone(), - goal.param_env, - goal.predicate, - ) - }) - .collect(), - } - } -} - impl<'tcx> ToTrace<'tcx> for Ty<'tcx> { fn to_trace(cause: &ObligationCause<'tcx>, a: Self, b: Self) -> TypeTrace<'tcx> { TypeTrace { diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index 3a245a5b25759..956697726118b 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -305,16 +305,14 @@ impl<'tcx> InferCtxt<'tcx> { (GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => { obligations.extend( - self.at(&cause, param_env) - .eq(DefineOpaqueTypes::Yes, v1, v2)? + self.eq_at(DefineOpaqueTypes::Yes, v1, v2, param_env, cause)? .into_obligations(), ); } (GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => { obligations.extend( - self.at(&cause, param_env) - .eq(DefineOpaqueTypes::Yes, v1, v2)? + self.eq_at(DefineOpaqueTypes::Yes, v1, v2, param_env, cause)? .into_obligations(), ); } @@ -523,13 +521,14 @@ impl<'tcx> InferCtxt<'tcx> { // variable that got constrained to the opaque type itself. In that case we want to equate // the generic args of the opaque with the generic params of its hidden type version. obligations.extend( - self.at(cause, param_env) - .eq( - DefineOpaqueTypes::Yes, - Ty::new_opaque(self.tcx, ty::IsRigid::No, a.def_id.to_def_id(), a.args), - b, - )? - .obligations, + self.eq_at( + DefineOpaqueTypes::Yes, + Ty::new_opaque(self.tcx, ty::IsRigid::No, a.def_id.to_def_id(), a.args), + b, + param_env, + cause, + )? + .obligations, ); } @@ -582,8 +581,7 @@ impl<'tcx> InferCtxt<'tcx> { match (value1.kind(), value2.kind()) { (GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => { obligations.extend( - self.at(cause, param_env) - .eq(DefineOpaqueTypes::Yes, v1, v2)? + self.eq_at(DefineOpaqueTypes::Yes, v1, v2, param_env, cause)? .into_obligations(), ); } @@ -601,7 +599,7 @@ impl<'tcx> InferCtxt<'tcx> { ); } (GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => { - let ok = self.at(cause, param_env).eq(DefineOpaqueTypes::Yes, v1, v2)?; + let ok = self.eq_at(DefineOpaqueTypes::Yes, v1, v2, param_env, cause)?; obligations.extend(ok.into_obligations()); } _ => { diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index e02cc9a7acd1f..bed6179307eae 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -881,9 +881,9 @@ impl<'tcx> InferCtxt<'tcx> { self.enter_forall(predicate, |ty::SubtypePredicate { a_is_expected, a, b }| { if a_is_expected { - Ok(self.at(cause, param_env).sub(DefineOpaqueTypes::Yes, a, b)) + Ok(self.sub_at(DefineOpaqueTypes::Yes, a, b, param_env, cause)) } else { - Ok(self.at(cause, param_env).sup(DefineOpaqueTypes::Yes, b, a)) + Ok(self.sup_at(DefineOpaqueTypes::Yes, b, a, param_env, cause)) } }) } diff --git a/compiler/rustc_infer/src/infer/opaque_types/mod.rs b/compiler/rustc_infer/src/infer/opaque_types/mod.rs index 3cca843157b8f..a308f3da86439 100644 --- a/compiler/rustc_infer/src/infer/opaque_types/mod.rs +++ b/compiler/rustc_infer/src/infer/opaque_types/mod.rs @@ -245,11 +245,16 @@ impl<'tcx> InferCtxt<'tcx> { .register(opaque_type_key, ProvisionalHiddenType { ty: hidden_ty, span }); if let Some(prev) = prev { goals.extend( - self.at(&ObligationCause::dummy_with_span(span), param_env) - .eq(DefineOpaqueTypes::Yes, prev, hidden_ty)? - .obligations - .into_iter() - .map(|obligation| obligation.as_goal()), + self.eq_at( + DefineOpaqueTypes::Yes, + prev, + hidden_ty, + param_env, + &ObligationCause::dummy_with_span(span), + )? + .obligations + .into_iter() + .map(|obligation| obligation.as_goal()), ); } } @@ -275,11 +280,16 @@ impl<'tcx> InferCtxt<'tcx> { }); goals.extend( - self.at(&ObligationCause::dummy_with_span(span), param_env) - .eq(DefineOpaqueTypes::Yes, hidden_ty, actual)? - .obligations - .into_iter() - .map(|obligation| obligation.as_goal()), + self.eq_at( + DefineOpaqueTypes::Yes, + hidden_ty, + actual, + param_env, + &ObligationCause::dummy_with_span(span), + )? + .obligations + .into_iter() + .map(|obligation| obligation.as_goal()), ); } mode @ (ty::TypingMode::PostBorrowck { .. } diff --git a/compiler/rustc_infer/src/infer/relate/lattice.rs b/compiler/rustc_infer/src/infer/relate/lattice.rs index 648bccbb618bc..821da42281f9f 100644 --- a/compiler/rustc_infer/src/infer/relate/lattice.rs +++ b/compiler/rustc_infer/src/infer/relate/lattice.rs @@ -99,8 +99,14 @@ impl<'tcx> TypeRelation> for LatticeOp<'_, 'tcx> { ty::Invariant => { self.obligations.extend( self.infcx - .at(&self.trace.cause, self.param_env) - .eq_trace(DefineOpaqueTypes::Yes, self.trace.clone(), a, b)? + .eq_trace_at( + DefineOpaqueTypes::Yes, + self.trace.clone(), + a, + b, + self.param_env, + &self.trace.cause, + )? .into_obligations(), ); Ok(a) @@ -255,15 +261,30 @@ impl<'infcx, 'tcx> LatticeOp<'infcx, 'tcx> { // relates `v` to `a` first, which may help us to avoid unnecessary // type variable obligations. See caller for details. fn relate_bound(&mut self, v: Ty<'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, ()> { - let at = self.infcx.at(&self.trace.cause, self.param_env); match self.kind { LatticeOpKind::Glb => { - self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, v, a)?.into_obligations()); - self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, v, b)?.into_obligations()); + self.obligations.extend( + self.infcx + .sub_at(DefineOpaqueTypes::Yes, v, a, self.param_env, &self.trace.cause)? + .into_obligations(), + ); + self.obligations.extend( + self.infcx + .sub_at(DefineOpaqueTypes::Yes, v, b, self.param_env, &self.trace.cause)? + .into_obligations(), + ); } LatticeOpKind::Lub => { - self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, a, v)?.into_obligations()); - self.obligations.extend(at.sub(DefineOpaqueTypes::Yes, b, v)?.into_obligations()); + self.obligations.extend( + self.infcx + .sub_at(DefineOpaqueTypes::Yes, a, v, self.param_env, &self.trace.cause)? + .into_obligations(), + ); + self.obligations.extend( + self.infcx + .sub_at(DefineOpaqueTypes::Yes, b, v, self.param_env, &self.trace.cause)? + .into_obligations(), + ); } } Ok(()) diff --git a/compiler/rustc_lint/src/runtime_symbols.rs b/compiler/rustc_lint/src/runtime_symbols.rs index f0e186c34ca0f..32ef57e092b8d 100644 --- a/compiler/rustc_lint/src/runtime_symbols.rs +++ b/compiler/rustc_lint/src/runtime_symbols.rs @@ -220,7 +220,7 @@ fn check<'tcx>( // Compare the two signatures with an inference context let infcx = cx.tcx.infer_ctxt().build(cx.typing_mode()); let cause = rustc_middle::traits::ObligationCause::misc(sp, did); - let result = infcx.at(&cause, cx.param_env).eq(DefineOpaqueTypes::No, lang_sig, user_sig); + let result = infcx.eq_at(DefineOpaqueTypes::No, lang_sig, user_sig, cx.param_env, &cause); // If they don't match, emit our own mismatch signatures if result.is_err() { diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index d83df2dfdf291..47521ad9be69e 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -277,10 +277,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let expected_trait_ref = alias.trait_ref(tcx); - if let Err(_) = self.infcx.at(&ObligationCause::dummy(), param_env).eq( + if let Err(_) = self.infcx.eq_at( DefineOpaqueTypes::No, expected_trait_ref, impl_trait_ref, + param_env, + &ObligationCause::dummy(), ) { return false; } diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 6b6e7d2dd0e9b..350aad274d976 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -5392,11 +5392,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { for (expected, actual) in zipped { self.probe(|_| { match self - .at(&ObligationCause::misc(expr.span, body_def_id), param_env) // Doesn't actually matter if we define opaque types here, this is just used for // diagnostics, and the result is never kept around. - .eq(DefineOpaqueTypes::Yes, expected, actual) - { + .eq_at( + DefineOpaqueTypes::Yes, + expected, + actual, + param_env, + &ObligationCause::misc(expr.span, body_def_id), + ) { Ok(_) => (), // We ignore nested obligations here for now. Err(err) => type_diffs.push(err), } diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 71dee3de72cb8..98ae7f5b25ba2 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -872,10 +872,12 @@ impl<'tcx> AutoTraitFinder<'tcx> { match (evaluate(c1), evaluate(c2)) { (Ok(c1), Ok(c2)) => { - match selcx.infcx.at(&obligation.cause, obligation.param_env).eq( + match selcx.infcx.eq_at( DefineOpaqueTypes::Yes, c1, c2, + obligation.param_env, + &obligation.cause, ) { Ok(_) => (), Err(_) => return false, diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 1b5b9582d9bd8..f0523a43345f7 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -354,18 +354,23 @@ fn equate_impl_headers<'tcx>( impl1: &ImplHeader<'tcx>, impl2: &ImplHeader<'tcx>, ) -> Option> { - let result = - match (impl1.trait_ref, impl2.trait_ref) { - (Some(impl1_ref), Some(impl2_ref)) => infcx - .at(&ObligationCause::dummy(), param_env) - .eq(DefineOpaqueTypes::Yes, impl1_ref, impl2_ref), - (None, None) => infcx.at(&ObligationCause::dummy(), param_env).eq( - DefineOpaqueTypes::Yes, - impl1.self_ty, - impl2.self_ty, - ), - _ => bug!("equate_impl_headers given mismatched impl kinds"), - }; + let result = match (impl1.trait_ref, impl2.trait_ref) { + (Some(impl1_ref), Some(impl2_ref)) => infcx.eq_at( + DefineOpaqueTypes::Yes, + impl1_ref, + impl2_ref, + param_env, + &ObligationCause::dummy(), + ), + (None, None) => infcx.eq_at( + DefineOpaqueTypes::Yes, + impl1.self_ty, + impl2.self_ty, + param_env, + &ObligationCause::dummy(), + ), + _ => bug!("equate_impl_headers given mismatched impl kinds"), + }; result.map(|infer_ok| infer_ok.obligations).ok() } @@ -582,20 +587,20 @@ fn plug_infer_with_placeholders<'tcx>( fn visit_ty(&mut self, ty: Ty<'tcx>) { let ty = self.infcx.shallow_resolve(ty); if ty.is_ty_var() { - let Ok(InferOk { value: (), obligations }) = - self.infcx.at(&ObligationCause::dummy(), ty::ParamEnv::empty()).eq( - // Comparing against a type variable never registers hidden types anyway - DefineOpaqueTypes::Yes, - ty, - Ty::new_placeholder( - self.infcx.tcx, - ty::PlaceholderType::new( - self.universe, - ty::BoundTy { var: self.next_var(), kind: ty::BoundTyKind::Anon }, - ), + let Ok(InferOk { value: (), obligations }) = self.infcx.eq_at( + // Comparing against a type variable never registers hidden types anyway + DefineOpaqueTypes::Yes, + ty, + Ty::new_placeholder( + self.infcx.tcx, + ty::PlaceholderType::new( + self.universe, + ty::BoundTy { var: self.next_var(), kind: ty::BoundTyKind::Anon }, ), - ) - else { + ), + ty::ParamEnv::empty(), + &ObligationCause::dummy(), + ) else { bug!("we always expect to be able to plug an infer var with placeholder") }; assert_eq!(obligations.len(), 0); @@ -607,21 +612,21 @@ fn plug_infer_with_placeholders<'tcx>( fn visit_const(&mut self, ct: ty::Const<'tcx>) { let ct = self.infcx.shallow_resolve_const(ct); if ct.is_ct_infer() { - let Ok(InferOk { value: (), obligations }) = - self.infcx.at(&ObligationCause::dummy(), ty::ParamEnv::empty()).eq( - // The types of the constants are the same, so there is no hidden type - // registration happening anyway. - DefineOpaqueTypes::Yes, - ct, - ty::Const::new_placeholder( - self.infcx.tcx, - ty::PlaceholderConst::new( - self.universe, - ty::BoundConst::new(self.next_var()), - ), + let Ok(InferOk { value: (), obligations }) = self.infcx.eq_at( + // The types of the constants are the same, so there is no hidden type + // registration happening anyway. + DefineOpaqueTypes::Yes, + ct, + ty::Const::new_placeholder( + self.infcx.tcx, + ty::PlaceholderConst::new( + self.universe, + ty::BoundConst::new(self.next_var()), ), - ) - else { + ), + ty::ParamEnv::empty(), + &ObligationCause::dummy(), + ) else { bug!("we always expect to be able to plug an infer var with placeholder") }; assert_eq!(obligations.len(), 0); @@ -639,23 +644,23 @@ fn plug_infer_with_placeholders<'tcx>( .unwrap_region_constraints() .shallow_resolve_region_var(self.infcx.tcx, vid); if r.is_var() { - let Ok(InferOk { value: (), obligations }) = - self.infcx.at(&ObligationCause::dummy(), ty::ParamEnv::empty()).eq( - // Lifetimes don't contain opaque types (or any types for that matter). - DefineOpaqueTypes::Yes, - r, - ty::Region::new_placeholder( - self.infcx.tcx, - ty::PlaceholderRegion::new( - self.universe, - ty::BoundRegion { - var: self.next_var(), - kind: ty::BoundRegionKind::Anon, - }, - ), + let Ok(InferOk { value: (), obligations }) = self.infcx.eq_at( + // Lifetimes don't contain opaque types (or any types for that matter). + DefineOpaqueTypes::Yes, + r, + ty::Region::new_placeholder( + self.infcx.tcx, + ty::PlaceholderRegion::new( + self.universe, + ty::BoundRegion { + var: self.next_var(), + kind: ty::BoundRegionKind::Anon, + }, ), - ) - else { + ), + ty::ParamEnv::empty(), + &ObligationCause::dummy(), + ) else { bug!("we always expect to be able to plug an infer var with placeholder") }; assert_eq!(obligations.len(), 0); diff --git a/compiler/rustc_trait_selection/src/traits/effects.rs b/compiler/rustc_trait_selection/src/traits/effects.rs index 5892e376126eb..faabfecbbb561 100644 --- a/compiler/rustc_trait_selection/src/traits/effects.rs +++ b/compiler/rustc_trait_selection/src/traits/effects.rs @@ -113,8 +113,13 @@ fn match_candidate<'tcx>( nested.extend( selcx .infcx - .at(&obligation.cause, obligation.param_env) - .eq(DefineOpaqueTypes::Yes, obligation.predicate.trait_ref, candidate.trait_ref)? + .eq_at( + DefineOpaqueTypes::Yes, + obligation.predicate.trait_ref, + candidate.trait_ref, + obligation.param_env, + &obligation.cause, + )? .into_obligations(), ); diff --git a/compiler/rustc_trait_selection/src/traits/engine.rs b/compiler/rustc_trait_selection/src/traits/engine.rs index 28f4dc5ac3c8b..7e4b4ea9a93ff 100644 --- a/compiler/rustc_trait_selection/src/traits/engine.rs +++ b/compiler/rustc_trait_selection/src/traits/engine.rs @@ -227,8 +227,7 @@ where actual: T, ) -> Result<(), TypeError<'tcx>> { self.infcx - .at(cause, param_env) - .eq(DefineOpaqueTypes::Yes, expected, actual) + .eq_at(DefineOpaqueTypes::Yes, expected, actual, param_env, cause) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } @@ -241,8 +240,7 @@ where actual: T, ) -> Result<(), TypeError<'tcx>> { self.infcx - .at(cause, param_env) - .eq_trace(DefineOpaqueTypes::Yes, trace, expected, actual) + .eq_trace_at(DefineOpaqueTypes::Yes, trace, expected, actual, param_env, cause) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } @@ -255,8 +253,7 @@ where actual: T, ) -> Result<(), TypeError<'tcx>> { self.infcx - .at(cause, param_env) - .sub(DefineOpaqueTypes::Yes, expected, actual) + .sub_at(DefineOpaqueTypes::Yes, expected, actual, param_env, cause) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } @@ -269,8 +266,7 @@ where actual: T, ) -> Result<(), TypeError<'tcx>> { self.infcx - .at(cause, param_env) - .relate(DefineOpaqueTypes::Yes, expected, variance, actual) + .relate_at(DefineOpaqueTypes::Yes, expected, variance, actual, param_env, cause) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } @@ -283,8 +279,7 @@ where actual: T, ) -> Result<(), TypeError<'tcx>> { self.infcx - .at(cause, param_env) - .sup(DefineOpaqueTypes::Yes, expected, actual) + .sup_at(DefineOpaqueTypes::Yes, expected, actual, param_env, cause) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } @@ -297,8 +292,7 @@ where actual: T, ) -> Result> { self.infcx - .at(cause, param_env) - .lub(expected, actual) + .lub_at(expected, actual, param_env, cause) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index aae323ae1671f..a9272357be7eb 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -577,11 +577,13 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { } }; - match infcx.at(&obligation.cause, obligation.param_env).eq( + match infcx.eq_at( // Only really exercised by generic_const_exprs DefineOpaqueTypes::Yes, ct_ty, ty, + obligation.param_env, + &obligation.cause, ) { Ok(inf_ok) => ProcessResult::Changed(mk_pending( obligation, @@ -727,13 +729,14 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { ) => { if let Ok(new_obligations) = infcx - .at(&obligation.cause, obligation.param_env) // Can define opaque types as this is only reachable with // `generic_const_exprs` - .eq( + .eq_at( DefineOpaqueTypes::Yes, ty::AliasTerm::from(a), ty::AliasTerm::from(b), + obligation.param_env, + &obligation.cause, ) { return ProcessResult::Changed(mk_pending( @@ -745,10 +748,15 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { (_, ty::ConstKind::Alias(_, _)) | (ty::ConstKind::Alias(_, _), _) => (), (_, _) => { if let Ok(new_obligations) = infcx - .at(&obligation.cause, obligation.param_env) // Can define opaque types as this is only reachable with // `generic_const_exprs` - .eq(DefineOpaqueTypes::Yes, c1, c2) + .eq_at( + DefineOpaqueTypes::Yes, + c1, + c2, + obligation.param_env, + &obligation.cause, + ) { return ProcessResult::Changed(mk_pending( obligation, @@ -788,12 +796,14 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { match (evaluate(c1), evaluate(c2)) { (Ok(c1), Ok(c2)) => { - match self.selcx.infcx.at(&obligation.cause, obligation.param_env).eq( + match self.selcx.infcx.eq_at( // Can define opaque types as this is only reachable with // `generic_const_exprs` DefineOpaqueTypes::Yes, c1, c2, + obligation.param_env, + &obligation.cause, ) { Ok(inf_ok) => ProcessResult::Changed(mk_pending( obligation, diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 6f7c46089632f..03c40e0f8638e 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -235,10 +235,12 @@ fn project_and_unify_term<'cx, 'tcx>( obligations.extend(new); // Need to define opaque types to support nested opaque types like `impl Fn() -> impl Trait` - match infcx.at(&obligation.cause, obligation.param_env).eq( + match infcx.eq_at( DefineOpaqueTypes::Yes, normalized, actual, + obligation.param_env, + &obligation.cause, ) { Ok(InferOk { obligations: inferred_obligations, value: () }) => { obligations.extend(inferred_obligations); @@ -636,7 +638,7 @@ pub fn compute_inherent_assoc_term_args<'a, 'b, 'tcx>( self_ty.skip_normalization() }; - match selcx.infcx.at(&cause, param_env).eq(DefineOpaqueTypes::Yes, impl_ty, self_ty) { + match selcx.infcx.eq_at(DefineOpaqueTypes::Yes, impl_ty, self_ty, param_env, &cause) { Ok(mut ok) => obligations.append(&mut ok.obligations), Err(_) => { tcx.dcx().span_bug( @@ -2019,10 +2021,12 @@ fn confirm_param_env_candidate<'cx, 'tcx>( debug!(?cache_projection, ?obligation_projection); - match infcx.at(cause, param_env).eq( + match infcx.eq_at( DefineOpaqueTypes::Yes, cache_projection, obligation_projection, + param_env, + cause, ) { Ok(InferOk { value: _, obligations }) => { nested_obligations.extend(obligations); diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 81517955181ee..2028d02a9bc87 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -189,8 +189,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligations.extend( self.infcx - .at(&obligation.cause, obligation.param_env) - .eq(DefineOpaqueTypes::No, placeholder_trait_predicate, candidate) + .eq_at( + DefineOpaqueTypes::No, + placeholder_trait_predicate, + candidate, + obligation.param_env, + &obligation.cause, + ) .map(|InferOk { obligations, .. }| obligations) .map_err(|_| SelectionError::Unimplemented)?, ); @@ -525,8 +530,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { nested.extend( self.infcx - .at(&obligation.cause, obligation.param_env) - .eq(DefineOpaqueTypes::No, trait_predicate.trait_ref, upcast_trait_ref) + .eq_at( + DefineOpaqueTypes::No, + trait_predicate.trait_ref, + upcast_trait_ref, + obligation.param_env, + &obligation.cause, + ) .map(|InferOk { obligations, .. }| obligations) .map_err(|_| SelectionError::Unimplemented)?, ); @@ -977,8 +987,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // needed to define opaque types for tests/ui/type-alias-impl-trait/assoc-projection-ice.rs self.infcx - .at(&obligation.cause, obligation.param_env) - .eq(DefineOpaqueTypes::Yes, obligation_trait_ref, found_trait_ref) + .eq_at( + DefineOpaqueTypes::Yes, + obligation_trait_ref, + found_trait_ref, + obligation.param_env, + &obligation.cause, + ) .map(|InferOk { mut obligations, .. }| { obligations.extend(nested); obligations @@ -1084,8 +1099,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // only the **lifetime bound** is changed. let InferOk { mut obligations, .. } = self .infcx - .at(&obligation.cause, obligation.param_env) - .sup(DefineOpaqueTypes::Yes, target, source_trait) + .sup_at( + DefineOpaqueTypes::Yes, + target, + source_trait, + obligation.param_env, + &obligation.cause, + ) .map_err(|_| SelectionError::Unimplemented)?; // Register one obligation for 'a: 'b. @@ -1151,8 +1171,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { (&ty::Array(a, _), &ty::Slice(b)) => { let InferOk { obligations, .. } = self .infcx - .at(&obligation.cause, obligation.param_env) - .eq(DefineOpaqueTypes::Yes, b, a) + .eq_at(DefineOpaqueTypes::Yes, b, a, obligation.param_env, &obligation.cause) .map_err(|_| SelectionError::Unimplemented)?; ImplSource::Builtin(BuiltinImplSource::Misc, obligations) @@ -1199,8 +1218,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let new_struct = Ty::new_adt(tcx, def, args); let InferOk { obligations, .. } = self .infcx - .at(&obligation.cause, obligation.param_env) - .eq(DefineOpaqueTypes::Yes, target, new_struct) + .eq_at( + DefineOpaqueTypes::Yes, + target, + new_struct, + obligation.param_env, + &obligation.cause, + ) .map_err(|_| SelectionError::Unimplemented)?; nested.extend(obligations); diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 4846d75339cd6..1bd2bbaa238fe 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -881,13 +881,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { { if let Ok(InferOk { obligations, value: () }) = self .infcx - .at(&obligation.cause, obligation.param_env) // Can define opaque types as this is only reachable with // `generic_const_exprs` - .eq( + .eq_at( DefineOpaqueTypes::Yes, ty::AliasTerm::from(a), ty::AliasTerm::from(b), + obligation.param_env, + &obligation.cause, ) { return self @@ -898,10 +899,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { (_, _) => { if let Ok(InferOk { obligations, value: () }) = self .infcx - .at(&obligation.cause, obligation.param_env) // Can define opaque types as this is only reachable with // `generic_const_exprs` - .eq(DefineOpaqueTypes::Yes, c1, c2) + .eq_at( + DefineOpaqueTypes::Yes, + c1, + c2, + obligation.param_env, + &obligation.cause, + ) { return self .evaluate_predicates_recursively(previous_stack, obligations); @@ -925,12 +931,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { match (evaluate(c1), evaluate(c2)) { (Ok(c1), Ok(c2)) => { - match self.infcx.at(&obligation.cause, obligation.param_env).eq( + match self.infcx.eq_at( // Can define opaque types as this is only reachable with // `generic_const_exprs` DefineOpaqueTypes::Yes, c1, c2, + obligation.param_env, + &obligation.cause, ) { Ok(inf_ok) => self.evaluate_predicates_recursively( previous_stack, @@ -980,11 +988,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } }; - match self.infcx.at(&obligation.cause, obligation.param_env).eq( + match self.infcx.eq_at( // Only really exercised by generic_const_exprs DefineOpaqueTypes::Yes, ct_ty, ty, + obligation.param_env, + &obligation.cause, ) { Ok(inf_ok) => self .evaluate_predicates_recursively(previous_stack, inf_ok.into_obligations()), @@ -1691,8 +1701,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ty::Unnormalized::new_wip(trait_bound), ); self.infcx - .at(&obligation.cause, obligation.param_env) - .eq(DefineOpaqueTypes::No, placeholder_trait_ref, trait_bound) + .eq_at( + DefineOpaqueTypes::No, + placeholder_trait_ref, + trait_bound, + obligation.param_env, + &obligation.cause, + ) .map(|InferOk { obligations: _, value: () }| { // This method is called within a probe, so we can't have // inference variables and placeholders escape. @@ -1753,8 +1768,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let is_match = self .infcx - .at(&obligation.cause, obligation.param_env) - .eq(DefineOpaqueTypes::No, obligation.predicate, infer_projection) + .eq_at( + DefineOpaqueTypes::No, + obligation.predicate, + infer_projection, + obligation.param_env, + &obligation.cause, + ) .is_ok_and(|InferOk { obligations, value: () }| { self.evaluate_predicates_recursively( TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()), @@ -2513,8 +2533,13 @@ impl<'tcx> SelectionContext<'_, 'tcx> { let InferOk { obligations, .. } = self .infcx - .at(&cause, obligation.param_env) - .eq(DefineOpaqueTypes::No, placeholder_obligation_trait_ref, impl_trait_ref) + .eq_at( + DefineOpaqueTypes::No, + placeholder_obligation_trait_ref, + impl_trait_ref, + obligation.param_env, + &cause, + ) .map_err(|e| { debug!("match_impl: failed eq_trait_refs due to `{}`", e.to_string(self.tcx())) })?; @@ -2597,7 +2622,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { HigherRankedType, hr_source_principal, ); - self.infcx.at(&obligation.cause, obligation.param_env).eq_trace( + self.infcx.eq_trace_at( DefineOpaqueTypes::Yes, ToTrace::to_trace( &obligation.cause, @@ -2606,6 +2631,8 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ), target_principal, source_principal, + obligation.param_env, + &obligation.cause, ) }) .map_err(|_| SelectionError::Unimplemented)? @@ -2634,18 +2661,18 @@ impl<'tcx> SelectionContext<'_, 'tcx> { HigherRankedType, hr_source_projection, ); - self.infcx - .at(&obligation.cause, obligation.param_env) - .eq_trace( - DefineOpaqueTypes::Yes, - ToTrace::to_trace( - &obligation.cause, - hr_target_projection, - hr_source_projection, - ), - target_projection, - source_projection, - ) + self.infcx.eq_trace_at( + DefineOpaqueTypes::Yes, + ToTrace::to_trace( + &obligation.cause, + hr_target_projection, + hr_source_projection, + ), + target_projection, + source_projection, + obligation.param_env, + &obligation.cause, + ) }) .is_ok() }) @@ -2666,7 +2693,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { HigherRankedType, hr_source_projection, ); - self.infcx.at(&obligation.cause, obligation.param_env).eq_trace( + self.infcx.eq_trace_at( DefineOpaqueTypes::Yes, ToTrace::to_trace( &obligation.cause, @@ -2675,6 +2702,8 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ), target_projection, source_projection, + obligation.param_env, + &obligation.cause, ) }) .map_err(|_| SelectionError::Unimplemented)? @@ -2727,8 +2756,13 @@ impl<'tcx> SelectionContext<'_, 'tcx> { poly_trait_ref, ); self.infcx - .at(&obligation.cause, obligation.param_env) - .eq(DefineOpaqueTypes::No, predicate.trait_ref, trait_ref) + .eq_at( + DefineOpaqueTypes::No, + predicate.trait_ref, + trait_ref, + obligation.param_env, + &obligation.cause, + ) .map(|InferOk { obligations, .. }| obligations) .map_err(|_| ()) } diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 7b4af6ac0dbcb..5d18726b2f450 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -48,10 +48,12 @@ pub(crate) fn synthesize_blanket_impls( // Require the type the impl is implemented on to match // our type, and ignore the impl if there was a mismatch. - let Ok(eq_result) = infcx.at(&traits::ObligationCause::dummy(), param_env).eq( + let Ok(eq_result) = infcx.eq_at( DefineOpaqueTypes::Yes, impl_trait_ref.self_ty(), impl_ty, + param_env, + &traits::ObligationCause::dummy(), ) else { continue; }; From 5934b62074456f021218c8dad5159059efe2b345 Mon Sep 17 00:00:00 2001 From: Fallible <118682743+fallible-algebra@users.noreply.github.com> Date: Mon, 28 Sep 2026 12:30:45 +0100 Subject: [PATCH 6/9] Reorder method params --- .../src/coherence/orphan.rs | 4 +- compiler/rustc_hir_typeck/src/callee.rs | 4 +- compiler/rustc_hir_typeck/src/cast.rs | 2 +- compiler/rustc_hir_typeck/src/closure.rs | 8 ++-- compiler/rustc_hir_typeck/src/coercion.rs | 12 ++--- compiler/rustc_hir_typeck/src/demand.rs | 12 ++--- compiler/rustc_hir_typeck/src/expr.rs | 4 +- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 4 +- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 8 ++-- .../rustc_hir_typeck/src/method/confirm.rs | 2 +- compiler/rustc_hir_typeck/src/method/probe.rs | 4 +- compiler/rustc_infer/src/infer/at.rs | 42 +++++++++--------- .../src/infer/canonical/query_response.rs | 12 ++--- compiler/rustc_infer/src/infer/mod.rs | 4 +- .../rustc_infer/src/infer/opaque_types/mod.rs | 8 ++-- .../rustc_infer/src/infer/relate/lattice.rs | 12 ++--- compiler/rustc_lint/src/runtime_symbols.rs | 2 +- .../src/error_reporting/infer/mod.rs | 4 +- .../src/error_reporting/traits/suggestions.rs | 4 +- .../src/traits/auto_trait.rs | 4 +- .../src/traits/coherence.rs | 20 ++++----- .../src/traits/effects.rs | 4 +- .../src/traits/engine.rs | 12 ++--- .../src/traits/fulfill.rs | 16 +++---- .../src/traits/project.rs | 10 ++--- .../src/traits/select/confirmation.rs | 22 +++++----- .../src/traits/select/mod.rs | 44 +++++++++---------- src/librustdoc/clean/blanket_impl.rs | 4 +- 28 files changed, 144 insertions(+), 144 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 4e045a2fb8028..df5bf8b9c8b46 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -372,11 +372,11 @@ fn orphan_check<'tcx>( std::iter::zip(args, ty::GenericArgs::identity_for_item(tcx, impl_def_id)) { let _ = infcx.eq_at( + &cause, + ty::ParamEnv::empty(), DefineOpaqueTypes::No, arg, id_arg, - ty::ParamEnv::empty(), - &cause, ); } infcx.deeply_resolve_ignoring_regions(tys) diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index e6ca171638ce3..e21ae111da401 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -731,11 +731,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let cause = self.cause(call_expr.span, ObligationCauseCode::Misc); if self .sup_at( + &cause, + self.param_env, DefineOpaqueTypes::Yes, formal_input_tys[0], adjusted_arg_type, - self.param_env, - &cause, ) .is_err() { diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 7e82ff46a8523..4300ac4edf1ff 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -1091,7 +1091,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { // This is `fcx.demand_eqtype`, but inlined to give a better error. let cause = fcx.misc(self.span); if fcx - .eq_at(DefineOpaqueTypes::Yes, src_obj, dst_obj, fcx.param_env, &cause) + .eq_at(&cause, fcx.param_env, DefineOpaqueTypes::Yes, src_obj, dst_obj) .map(|infer_ok| fcx.register_infer_ok_obligations(infer_ok)) .is_err() { diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 6b111f4af78c8..1ef1fbb62fd3f 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -799,11 +799,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Check that E' = S'. let cause = self.misc(hir_ty.span); let InferOk { value: (), obligations } = self.eq_at( + &cause, + self.param_env, DefineOpaqueTypes::Yes, *expected_ty, supplied_ty, - self.param_env, - &cause, )?; all_obligations.extend(obligations); } @@ -811,11 +811,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let supplied_output_ty = supplied_sig.output(); let cause = &self.misc(decl.output.span()); let InferOk { value: (), obligations } = self.eq_at( + cause, + self.param_env, DefineOpaqueTypes::Yes, expected_sigs.liberated_sig.output(), supplied_output_ty, - self.param_env, - cause, )?; all_obligations.extend(obligations); diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index e6c364dbe1ee0..8508877732ad4 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -166,9 +166,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { let outer_universe = self.infcx.universe(); let res = if self.use_lub { - self.lub_at(b, a, self.fcx.param_env, &self.cause) + self.lub_at(&self.cause, self.fcx.param_env, b, a) } else { - self.sup_at(DefineOpaqueTypes::Yes, b, a, self.fcx.param_env, &self.cause) + self.sup_at(&self.cause, self.fcx.param_env, DefineOpaqueTypes::Yes, b, a) .map(|InferOk { value: (), obligations }| InferOk { value: b, obligations }) }; @@ -1373,7 +1373,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Err(TypeError::Mismatch) } } else { - self.lub_at(prev_ty, new_ty, self.param_env, cause) + self.lub_at(cause, self.param_env, prev_ty, new_ty) }; self.leak_check(outer_universe, Some(snapshot))?; @@ -1412,7 +1412,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // The signature must match. let (a_sig, b_sig) = self.normalize(new.span, Unnormalized::new_wip((a_sig, b_sig))); let sig = self - .lub_at(a_sig, b_sig, self.param_env, cause) + .lub_at(cause, self.param_env, a_sig, b_sig) .map(|ok| self.register_infer_ok_obligations(ok))?; // Reify both sides and return the reified fn pointer type. @@ -1728,11 +1728,11 @@ impl<'tcx> CoerceMany<'tcx> { assert!(expression_ty.is_unit(), "if let hack without unit type"); fcx.eq_at( // needed for tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs + cause, + fcx.param_env, DefineOpaqueTypes::Yes, expected, found, - fcx.param_env, - cause, ) .map(|infer_ok| { fcx.register_infer_ok_obligations(infer_ok); diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 14388a99bf7c7..8328620926de5 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -190,7 +190,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected: Ty<'tcx>, actual: Ty<'tcx>, ) -> Result<(), Diag<'a>> { - self.sup_at(DefineOpaqueTypes::Yes, expected, actual, self.param_env, cause) + self.sup_at(cause, self.param_env, DefineOpaqueTypes::Yes, expected, actual) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) .map_err(|e| { self.err_ctxt().report_mismatched_types(cause, self.param_env, expected, actual, e) @@ -218,7 +218,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected: Ty<'tcx>, actual: Ty<'tcx>, ) -> Result<(), Diag<'a>> { - self.eq_at(DefineOpaqueTypes::Yes, expected, actual, self.param_env, cause) + self.eq_at(cause, self.param_env, DefineOpaqueTypes::Yes, expected, actual) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) .map_err(|e| { self.err_ctxt().report_mismatched_types(cause, self.param_env, expected, actual, e) @@ -415,11 +415,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let _ = self .eq_at( + &ObligationCause::dummy(), + self.param_env, DefineOpaqueTypes::Yes, *input_arg, arg_ty, - self.param_env, - &ObligationCause::dummy(), ) .ok()?; self.select_obligations_where_possible(|errs| { @@ -502,11 +502,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .and_then(|method| { let _ = self .eq_at( + &ObligationCause::dummy(), + self.param_env, DefineOpaqueTypes::Yes, ideal_rcvr_ty, expected_ty, - self.param_env, - &ObligationCause::dummy(), ) .ok()?; Some(method) diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index df124c10cb057..db2add7e35457 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -2106,11 +2106,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // and don't allow converting between different structs, // so there is no way this ever actually defines an opaque // type. Thus choosing `Yes` is fine. + &cause, + self.param_env, DefineOpaqueTypes::Yes, target_ty, fru_ty, - self.param_env, - &cause, ) { Ok(InferOk { obligations, value: () }) => { self.register_predicates(obligations) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 4304314f43634..b0bddc44d0a37 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -1450,11 +1450,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let impl_ty = self.normalize(span, tcx.type_of(impl_def_id).instantiate(tcx, args)); let self_ty = self.normalize(span, Unnormalized::new_wip(self_ty)); match self.eq_at( + &self.misc(span), + self.param_env, DefineOpaqueTypes::Yes, impl_ty, self_ty, - self.param_env, - &self.misc(span), ) { Ok(ok) => self.register_infer_ok_obligations(ok), Err(_) => { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 8fef69cae4c8f..6e47a55111c91 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -397,11 +397,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // 3. Check if the formal type is actually equal to the checked one // and register any such obligations for future type checks. let formal_ty_error = self.eq_at( + &self.misc(provided_arg.span), + self.param_env, DefineOpaqueTypes::Yes, formal_input_ty, coerced_ty, - self.param_env, - &self.misc(provided_arg.span), ); // If neither check failed, the types are compatible @@ -3226,11 +3226,11 @@ impl<'a, 'tcx> ArgMatchingCtxt<'a, 'tcx> { // Using probe here, since we don't want this subtyping to affect inference. let subtyping_error = self.probe(|_| { self.sup_at( + &self.misc(arg_span), + self.param_env, DefineOpaqueTypes::Yes, formal_input_ty, coerced_ty, - self.param_env, - &self.misc(arg_span), ) .err() }); diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index 96ec440b95f74..b7d2e75aec03a 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -560,7 +560,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { self_ty, method_self_ty, self.span, pick ); let cause = self.cause(self.self_expr.span, ObligationCauseCode::Misc); - match self.sup_at(DefineOpaqueTypes::Yes, method_self_ty, self_ty, self.param_env, &cause) { + match self.sup_at(&cause, self.param_env, DefineOpaqueTypes::Yes, method_self_ty, self_ty) { Ok(InferOk { obligations, value: () }) => { self.register_predicates(obligations); } diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 3b6cdf6eb6f08..745e73dc9bd88 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -1972,11 +1972,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // Guide the trait selection to show impls that have methods whose type matches // up with the `self` parameter of the method. let _ = self.sup_at( + &ObligationCause::dummy(), + self.param_env, DefineOpaqueTypes::Yes, xform_self_ty, self_ty, - self.param_env, - &ObligationCause::dummy(), ); match self.select_trait_candidate_for_diagnostics(trait_ref) { Ok(Some(traits::ImplSource::UserDefined(ref impl_data))) => { diff --git a/compiler/rustc_infer/src/infer/at.rs b/compiler/rustc_infer/src/infer/at.rs index 5339860c8721d..356c7ceda0a02 100644 --- a/compiler/rustc_infer/src/infer/at.rs +++ b/compiler/rustc_infer/src/infer/at.rs @@ -109,11 +109,11 @@ impl<'tcx> InferCtxt<'tcx> { pub fn sup_at( &self, + cause: &ObligationCause<'tcx>, + param_env: ty::ParamEnv<'tcx>, define_opaque_types: DefineOpaqueTypes, expected: T, actual: T, - param_env: ty::ParamEnv<'tcx>, - cause: &ObligationCause<'tcx>, ) -> InferResult<'tcx, ()> where T: ToTrace<'tcx>, @@ -127,7 +127,7 @@ impl<'tcx> InferCtxt<'tcx> { actual, cause.span, ) - .map(|goals| self.goals_to_obligations_at(goals, cause)) + .map(|goals| self.goals_to_obligations_at(cause, goals)) } else { let mut op = TypeRelating::new( &self, @@ -144,18 +144,18 @@ impl<'tcx> InferCtxt<'tcx> { /// Makes `expected <: actual`. pub fn sub_at( &self, + cause: &ObligationCause<'tcx>, + param_env: ty::ParamEnv<'tcx>, define_opaque_types: DefineOpaqueTypes, expected: T, actual: T, - param_env: ty::ParamEnv<'tcx>, - cause: &ObligationCause<'tcx>, ) -> InferResult<'tcx, ()> where T: ToTrace<'tcx>, { if self.next_trait_solver { NextSolverRelate::relate(self, param_env, expected, ty::Covariant, actual, cause.span) - .map(|goals| self.goals_to_obligations_at(goals, cause)) + .map(|goals| self.goals_to_obligations_at(cause, goals)) } else { let mut op = TypeRelating::new( &self, @@ -171,40 +171,40 @@ impl<'tcx> InferCtxt<'tcx> { pub fn eq_at( &self, + cause: &ObligationCause<'tcx>, + param_env: ty::ParamEnv<'tcx>, define_opaque_types: DefineOpaqueTypes, expected: T, actual: T, - param_env: ty::ParamEnv<'tcx>, - cause: &ObligationCause<'tcx>, ) -> InferResult<'tcx, ()> where T: ToTrace<'tcx>, { self.eq_trace_at( + cause, + param_env, define_opaque_types, ToTrace::to_trace(cause, expected, actual), expected, actual, - param_env, - cause, ) } pub fn eq_trace_at( &self, + cause: &ObligationCause<'tcx>, + param_env: ty::ParamEnv<'tcx>, define_opaque_types: DefineOpaqueTypes, trace: TypeTrace<'tcx>, expected: T, actual: T, - param_env: ty::ParamEnv<'tcx>, - cause: &ObligationCause<'tcx>, ) -> InferResult<'tcx, ()> where T: Relate>, { if self.next_trait_solver { NextSolverRelate::relate(self, param_env, expected, ty::Invariant, actual, cause.span) - .map(|goals| self.goals_to_obligations_at(goals, cause)) + .map(|goals| self.goals_to_obligations_at(cause, goals)) } else { let mut op = TypeRelating::new(&self, trace, param_env, define_opaque_types, ty::Invariant); @@ -215,21 +215,21 @@ impl<'tcx> InferCtxt<'tcx> { pub fn relate_at( &self, + cause: &ObligationCause<'tcx>, + param_env: ty::ParamEnv<'tcx>, define_opaque_types: DefineOpaqueTypes, expected: T, variance: ty::Variance, actual: T, - param_env: ty::ParamEnv<'tcx>, - cause: &ObligationCause<'tcx>, ) -> InferResult<'tcx, ()> where T: ToTrace<'tcx>, { match variance { - ty::Covariant => self.sub_at(define_opaque_types, expected, actual, param_env, cause), - ty::Invariant => self.eq_at(define_opaque_types, expected, actual, param_env, cause), + ty::Covariant => self.sub_at(cause, param_env, define_opaque_types, expected, actual), + ty::Invariant => self.eq_at(cause, param_env, define_opaque_types, expected, actual), ty::Contravariant => { - self.sup_at(define_opaque_types, expected, actual, param_env, cause) + self.sup_at(cause, param_env, define_opaque_types, expected, actual) } // We could make this make sense but it's not readily @@ -248,10 +248,10 @@ impl<'tcx> InferCtxt<'tcx> { /// "expected type". pub fn lub_at( &self, + cause: &ObligationCause<'tcx>, + param_env: ty::ParamEnv<'tcx>, expected: T, actual: T, - param_env: ty::ParamEnv<'tcx>, - cause: &ObligationCause<'tcx>, ) -> InferResult<'tcx, T> where T: ToTrace<'tcx>, @@ -268,8 +268,8 @@ impl<'tcx> InferCtxt<'tcx> { fn goals_to_obligations_at( &self, - goals: Vec>>, cause: &ObligationCause<'tcx>, + goals: Vec>>, ) -> InferOk<'tcx, ()> { InferOk { value: (), diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index 956697726118b..1d1dbc7b7afce 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -305,14 +305,14 @@ impl<'tcx> InferCtxt<'tcx> { (GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => { obligations.extend( - self.eq_at(DefineOpaqueTypes::Yes, v1, v2, param_env, cause)? + self.eq_at(cause, param_env, DefineOpaqueTypes::Yes, v1, v2)? .into_obligations(), ); } (GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => { obligations.extend( - self.eq_at(DefineOpaqueTypes::Yes, v1, v2, param_env, cause)? + self.eq_at(cause, param_env, DefineOpaqueTypes::Yes, v1, v2)? .into_obligations(), ); } @@ -522,11 +522,11 @@ impl<'tcx> InferCtxt<'tcx> { // the generic args of the opaque with the generic params of its hidden type version. obligations.extend( self.eq_at( + cause, + param_env, DefineOpaqueTypes::Yes, Ty::new_opaque(self.tcx, ty::IsRigid::No, a.def_id.to_def_id(), a.args), b, - param_env, - cause, )? .obligations, ); @@ -581,7 +581,7 @@ impl<'tcx> InferCtxt<'tcx> { match (value1.kind(), value2.kind()) { (GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => { obligations.extend( - self.eq_at(DefineOpaqueTypes::Yes, v1, v2, param_env, cause)? + self.eq_at(cause, param_env, DefineOpaqueTypes::Yes, v1, v2)? .into_obligations(), ); } @@ -599,7 +599,7 @@ impl<'tcx> InferCtxt<'tcx> { ); } (GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => { - let ok = self.eq_at(DefineOpaqueTypes::Yes, v1, v2, param_env, cause)?; + let ok = self.eq_at(cause, param_env, DefineOpaqueTypes::Yes, v1, v2)?; obligations.extend(ok.into_obligations()); } _ => { diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index bed6179307eae..2e30f13200090 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -881,9 +881,9 @@ impl<'tcx> InferCtxt<'tcx> { self.enter_forall(predicate, |ty::SubtypePredicate { a_is_expected, a, b }| { if a_is_expected { - Ok(self.sub_at(DefineOpaqueTypes::Yes, a, b, param_env, cause)) + Ok(self.sub_at(cause, param_env, DefineOpaqueTypes::Yes, a, b)) } else { - Ok(self.sup_at(DefineOpaqueTypes::Yes, b, a, param_env, cause)) + Ok(self.sup_at(cause, param_env, DefineOpaqueTypes::Yes, b, a)) } }) } diff --git a/compiler/rustc_infer/src/infer/opaque_types/mod.rs b/compiler/rustc_infer/src/infer/opaque_types/mod.rs index a308f3da86439..3f8b18cab3179 100644 --- a/compiler/rustc_infer/src/infer/opaque_types/mod.rs +++ b/compiler/rustc_infer/src/infer/opaque_types/mod.rs @@ -246,11 +246,11 @@ impl<'tcx> InferCtxt<'tcx> { if let Some(prev) = prev { goals.extend( self.eq_at( + &ObligationCause::dummy_with_span(span), + param_env, DefineOpaqueTypes::Yes, prev, hidden_ty, - param_env, - &ObligationCause::dummy_with_span(span), )? .obligations .into_iter() @@ -281,11 +281,11 @@ impl<'tcx> InferCtxt<'tcx> { goals.extend( self.eq_at( + &ObligationCause::dummy_with_span(span), + param_env, DefineOpaqueTypes::Yes, hidden_ty, actual, - param_env, - &ObligationCause::dummy_with_span(span), )? .obligations .into_iter() diff --git a/compiler/rustc_infer/src/infer/relate/lattice.rs b/compiler/rustc_infer/src/infer/relate/lattice.rs index 821da42281f9f..51a0b51b5a303 100644 --- a/compiler/rustc_infer/src/infer/relate/lattice.rs +++ b/compiler/rustc_infer/src/infer/relate/lattice.rs @@ -100,12 +100,12 @@ impl<'tcx> TypeRelation> for LatticeOp<'_, 'tcx> { self.obligations.extend( self.infcx .eq_trace_at( + &self.trace.cause, + self.param_env, DefineOpaqueTypes::Yes, self.trace.clone(), a, b, - self.param_env, - &self.trace.cause, )? .into_obligations(), ); @@ -265,24 +265,24 @@ impl<'infcx, 'tcx> LatticeOp<'infcx, 'tcx> { LatticeOpKind::Glb => { self.obligations.extend( self.infcx - .sub_at(DefineOpaqueTypes::Yes, v, a, self.param_env, &self.trace.cause)? + .sub_at(&self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, v, a)? .into_obligations(), ); self.obligations.extend( self.infcx - .sub_at(DefineOpaqueTypes::Yes, v, b, self.param_env, &self.trace.cause)? + .sub_at(&self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, v, b)? .into_obligations(), ); } LatticeOpKind::Lub => { self.obligations.extend( self.infcx - .sub_at(DefineOpaqueTypes::Yes, a, v, self.param_env, &self.trace.cause)? + .sub_at(&self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, a, v)? .into_obligations(), ); self.obligations.extend( self.infcx - .sub_at(DefineOpaqueTypes::Yes, b, v, self.param_env, &self.trace.cause)? + .sub_at(&self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, b, v)? .into_obligations(), ); } diff --git a/compiler/rustc_lint/src/runtime_symbols.rs b/compiler/rustc_lint/src/runtime_symbols.rs index 32ef57e092b8d..d62f1d129d821 100644 --- a/compiler/rustc_lint/src/runtime_symbols.rs +++ b/compiler/rustc_lint/src/runtime_symbols.rs @@ -220,7 +220,7 @@ fn check<'tcx>( // Compare the two signatures with an inference context let infcx = cx.tcx.infer_ctxt().build(cx.typing_mode()); let cause = rustc_middle::traits::ObligationCause::misc(sp, did); - let result = infcx.eq_at(DefineOpaqueTypes::No, lang_sig, user_sig, cx.param_env, &cause); + let result = infcx.eq_at(&cause, cx.param_env, DefineOpaqueTypes::No, lang_sig, user_sig); // If they don't match, emit our own mismatch signatures if result.is_err() { diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index 47521ad9be69e..a7f2a860ab868 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -278,11 +278,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let expected_trait_ref = alias.trait_ref(tcx); if let Err(_) = self.infcx.eq_at( + &ObligationCause::dummy(), + param_env, DefineOpaqueTypes::No, expected_trait_ref, impl_trait_ref, - param_env, - &ObligationCause::dummy(), ) { return false; } diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 350aad274d976..f11323e552efb 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -5395,11 +5395,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { // Doesn't actually matter if we define opaque types here, this is just used for // diagnostics, and the result is never kept around. .eq_at( + &ObligationCause::misc(expr.span, body_def_id), + param_env, DefineOpaqueTypes::Yes, expected, actual, - param_env, - &ObligationCause::misc(expr.span, body_def_id), ) { Ok(_) => (), // We ignore nested obligations here for now. Err(err) => type_diffs.push(err), diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 98ae7f5b25ba2..be0d3183ae251 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -873,11 +873,11 @@ impl<'tcx> AutoTraitFinder<'tcx> { match (evaluate(c1), evaluate(c2)) { (Ok(c1), Ok(c2)) => { match selcx.infcx.eq_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, c1, c2, - obligation.param_env, - &obligation.cause, ) { Ok(_) => (), Err(_) => return false, diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index f0523a43345f7..097e15a39500e 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -356,18 +356,18 @@ fn equate_impl_headers<'tcx>( ) -> Option> { let result = match (impl1.trait_ref, impl2.trait_ref) { (Some(impl1_ref), Some(impl2_ref)) => infcx.eq_at( + &ObligationCause::dummy(), + param_env, DefineOpaqueTypes::Yes, impl1_ref, impl2_ref, - param_env, - &ObligationCause::dummy(), ), (None, None) => infcx.eq_at( + &ObligationCause::dummy(), + param_env, DefineOpaqueTypes::Yes, impl1.self_ty, impl2.self_ty, - param_env, - &ObligationCause::dummy(), ), _ => bug!("equate_impl_headers given mismatched impl kinds"), }; @@ -589,6 +589,8 @@ fn plug_infer_with_placeholders<'tcx>( if ty.is_ty_var() { let Ok(InferOk { value: (), obligations }) = self.infcx.eq_at( // Comparing against a type variable never registers hidden types anyway + &ObligationCause::dummy(), + ty::ParamEnv::empty(), DefineOpaqueTypes::Yes, ty, Ty::new_placeholder( @@ -598,8 +600,6 @@ fn plug_infer_with_placeholders<'tcx>( ty::BoundTy { var: self.next_var(), kind: ty::BoundTyKind::Anon }, ), ), - ty::ParamEnv::empty(), - &ObligationCause::dummy(), ) else { bug!("we always expect to be able to plug an infer var with placeholder") }; @@ -615,6 +615,8 @@ fn plug_infer_with_placeholders<'tcx>( let Ok(InferOk { value: (), obligations }) = self.infcx.eq_at( // The types of the constants are the same, so there is no hidden type // registration happening anyway. + &ObligationCause::dummy(), + ty::ParamEnv::empty(), DefineOpaqueTypes::Yes, ct, ty::Const::new_placeholder( @@ -624,8 +626,6 @@ fn plug_infer_with_placeholders<'tcx>( ty::BoundConst::new(self.next_var()), ), ), - ty::ParamEnv::empty(), - &ObligationCause::dummy(), ) else { bug!("we always expect to be able to plug an infer var with placeholder") }; @@ -646,6 +646,8 @@ fn plug_infer_with_placeholders<'tcx>( if r.is_var() { let Ok(InferOk { value: (), obligations }) = self.infcx.eq_at( // Lifetimes don't contain opaque types (or any types for that matter). + &ObligationCause::dummy(), + ty::ParamEnv::empty(), DefineOpaqueTypes::Yes, r, ty::Region::new_placeholder( @@ -658,8 +660,6 @@ fn plug_infer_with_placeholders<'tcx>( }, ), ), - ty::ParamEnv::empty(), - &ObligationCause::dummy(), ) else { bug!("we always expect to be able to plug an infer var with placeholder") }; diff --git a/compiler/rustc_trait_selection/src/traits/effects.rs b/compiler/rustc_trait_selection/src/traits/effects.rs index faabfecbbb561..8d8a86cdfbcbe 100644 --- a/compiler/rustc_trait_selection/src/traits/effects.rs +++ b/compiler/rustc_trait_selection/src/traits/effects.rs @@ -114,11 +114,11 @@ fn match_candidate<'tcx>( selcx .infcx .eq_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, obligation.predicate.trait_ref, candidate.trait_ref, - obligation.param_env, - &obligation.cause, )? .into_obligations(), ); diff --git a/compiler/rustc_trait_selection/src/traits/engine.rs b/compiler/rustc_trait_selection/src/traits/engine.rs index 7e4b4ea9a93ff..df16c9f0eb3a3 100644 --- a/compiler/rustc_trait_selection/src/traits/engine.rs +++ b/compiler/rustc_trait_selection/src/traits/engine.rs @@ -227,7 +227,7 @@ where actual: T, ) -> Result<(), TypeError<'tcx>> { self.infcx - .eq_at(DefineOpaqueTypes::Yes, expected, actual, param_env, cause) + .eq_at(cause, param_env, DefineOpaqueTypes::Yes, expected, actual) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } @@ -240,7 +240,7 @@ where actual: T, ) -> Result<(), TypeError<'tcx>> { self.infcx - .eq_trace_at(DefineOpaqueTypes::Yes, trace, expected, actual, param_env, cause) + .eq_trace_at(cause, param_env, DefineOpaqueTypes::Yes, trace, expected, actual) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } @@ -253,7 +253,7 @@ where actual: T, ) -> Result<(), TypeError<'tcx>> { self.infcx - .sub_at(DefineOpaqueTypes::Yes, expected, actual, param_env, cause) + .sub_at(cause, param_env, DefineOpaqueTypes::Yes, expected, actual) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } @@ -266,7 +266,7 @@ where actual: T, ) -> Result<(), TypeError<'tcx>> { self.infcx - .relate_at(DefineOpaqueTypes::Yes, expected, variance, actual, param_env, cause) + .relate_at(cause, param_env, DefineOpaqueTypes::Yes, expected, variance, actual) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } @@ -279,7 +279,7 @@ where actual: T, ) -> Result<(), TypeError<'tcx>> { self.infcx - .sup_at(DefineOpaqueTypes::Yes, expected, actual, param_env, cause) + .sup_at(cause, param_env, DefineOpaqueTypes::Yes, expected, actual) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } @@ -292,7 +292,7 @@ where actual: T, ) -> Result> { self.infcx - .lub_at(expected, actual, param_env, cause) + .lub_at(cause, param_env, expected, actual) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index a9272357be7eb..5a203b2f932e3 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -579,11 +579,11 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { match infcx.eq_at( // Only really exercised by generic_const_exprs + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, ct_ty, ty, - obligation.param_env, - &obligation.cause, ) { Ok(inf_ok) => ProcessResult::Changed(mk_pending( obligation, @@ -732,11 +732,11 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { // Can define opaque types as this is only reachable with // `generic_const_exprs` .eq_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, ty::AliasTerm::from(a), ty::AliasTerm::from(b), - obligation.param_env, - &obligation.cause, ) { return ProcessResult::Changed(mk_pending( @@ -751,11 +751,11 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { // Can define opaque types as this is only reachable with // `generic_const_exprs` .eq_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, c1, c2, - obligation.param_env, - &obligation.cause, ) { return ProcessResult::Changed(mk_pending( @@ -799,11 +799,11 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { match self.selcx.infcx.eq_at( // Can define opaque types as this is only reachable with // `generic_const_exprs` + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, c1, c2, - obligation.param_env, - &obligation.cause, ) { Ok(inf_ok) => ProcessResult::Changed(mk_pending( obligation, diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 03c40e0f8638e..0e8b5610365dc 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -236,11 +236,11 @@ fn project_and_unify_term<'cx, 'tcx>( // Need to define opaque types to support nested opaque types like `impl Fn() -> impl Trait` match infcx.eq_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, normalized, actual, - obligation.param_env, - &obligation.cause, ) { Ok(InferOk { obligations: inferred_obligations, value: () }) => { obligations.extend(inferred_obligations); @@ -638,7 +638,7 @@ pub fn compute_inherent_assoc_term_args<'a, 'b, 'tcx>( self_ty.skip_normalization() }; - match selcx.infcx.eq_at(DefineOpaqueTypes::Yes, impl_ty, self_ty, param_env, &cause) { + match selcx.infcx.eq_at(&cause, param_env, DefineOpaqueTypes::Yes, impl_ty, self_ty) { Ok(mut ok) => obligations.append(&mut ok.obligations), Err(_) => { tcx.dcx().span_bug( @@ -2022,11 +2022,11 @@ fn confirm_param_env_candidate<'cx, 'tcx>( debug!(?cache_projection, ?obligation_projection); match infcx.eq_at( + cause, + param_env, DefineOpaqueTypes::Yes, cache_projection, obligation_projection, - param_env, - cause, ) { Ok(InferOk { value: _, obligations }) => { nested_obligations.extend(obligations); diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 2028d02a9bc87..c880847f1050e 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -190,11 +190,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligations.extend( self.infcx .eq_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::No, placeholder_trait_predicate, candidate, - obligation.param_env, - &obligation.cause, ) .map(|InferOk { obligations, .. }| obligations) .map_err(|_| SelectionError::Unimplemented)?, @@ -531,11 +531,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { nested.extend( self.infcx .eq_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::No, trait_predicate.trait_ref, upcast_trait_ref, - obligation.param_env, - &obligation.cause, ) .map(|InferOk { obligations, .. }| obligations) .map_err(|_| SelectionError::Unimplemented)?, @@ -988,11 +988,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // needed to define opaque types for tests/ui/type-alias-impl-trait/assoc-projection-ice.rs self.infcx .eq_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, obligation_trait_ref, found_trait_ref, - obligation.param_env, - &obligation.cause, ) .map(|InferOk { mut obligations, .. }| { obligations.extend(nested); @@ -1100,11 +1100,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let InferOk { mut obligations, .. } = self .infcx .sup_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, target, source_trait, - obligation.param_env, - &obligation.cause, ) .map_err(|_| SelectionError::Unimplemented)?; @@ -1171,7 +1171,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { (&ty::Array(a, _), &ty::Slice(b)) => { let InferOk { obligations, .. } = self .infcx - .eq_at(DefineOpaqueTypes::Yes, b, a, obligation.param_env, &obligation.cause) + .eq_at(&obligation.cause, obligation.param_env, DefineOpaqueTypes::Yes, b, a) .map_err(|_| SelectionError::Unimplemented)?; ImplSource::Builtin(BuiltinImplSource::Misc, obligations) @@ -1219,11 +1219,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let InferOk { obligations, .. } = self .infcx .eq_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, target, new_struct, - obligation.param_env, - &obligation.cause, ) .map_err(|_| SelectionError::Unimplemented)?; nested.extend(obligations); diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 1bd2bbaa238fe..b497a17f3c915 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -884,11 +884,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Can define opaque types as this is only reachable with // `generic_const_exprs` .eq_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, ty::AliasTerm::from(a), ty::AliasTerm::from(b), - obligation.param_env, - &obligation.cause, ) { return self @@ -902,11 +902,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Can define opaque types as this is only reachable with // `generic_const_exprs` .eq_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, c1, c2, - obligation.param_env, - &obligation.cause, ) { return self @@ -934,11 +934,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { match self.infcx.eq_at( // Can define opaque types as this is only reachable with // `generic_const_exprs` + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, c1, c2, - obligation.param_env, - &obligation.cause, ) { Ok(inf_ok) => self.evaluate_predicates_recursively( previous_stack, @@ -990,11 +990,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { match self.infcx.eq_at( // Only really exercised by generic_const_exprs + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, ct_ty, ty, - obligation.param_env, - &obligation.cause, ) { Ok(inf_ok) => self .evaluate_predicates_recursively(previous_stack, inf_ok.into_obligations()), @@ -1702,11 +1702,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ); self.infcx .eq_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::No, placeholder_trait_ref, trait_bound, - obligation.param_env, - &obligation.cause, ) .map(|InferOk { obligations: _, value: () }| { // This method is called within a probe, so we can't have @@ -1769,11 +1769,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let is_match = self .infcx .eq_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::No, obligation.predicate, infer_projection, - obligation.param_env, - &obligation.cause, ) .is_ok_and(|InferOk { obligations, value: () }| { self.evaluate_predicates_recursively( @@ -2534,11 +2534,11 @@ impl<'tcx> SelectionContext<'_, 'tcx> { let InferOk { obligations, .. } = self .infcx .eq_at( + &cause, + obligation.param_env, DefineOpaqueTypes::No, placeholder_obligation_trait_ref, impl_trait_ref, - obligation.param_env, - &cause, ) .map_err(|e| { debug!("match_impl: failed eq_trait_refs due to `{}`", e.to_string(self.tcx())) @@ -2623,6 +2623,8 @@ impl<'tcx> SelectionContext<'_, 'tcx> { hr_source_principal, ); self.infcx.eq_trace_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, ToTrace::to_trace( &obligation.cause, @@ -2631,8 +2633,6 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ), target_principal, source_principal, - obligation.param_env, - &obligation.cause, ) }) .map_err(|_| SelectionError::Unimplemented)? @@ -2662,6 +2662,8 @@ impl<'tcx> SelectionContext<'_, 'tcx> { hr_source_projection, ); self.infcx.eq_trace_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, ToTrace::to_trace( &obligation.cause, @@ -2670,8 +2672,6 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ), target_projection, source_projection, - obligation.param_env, - &obligation.cause, ) }) .is_ok() @@ -2694,6 +2694,8 @@ impl<'tcx> SelectionContext<'_, 'tcx> { hr_source_projection, ); self.infcx.eq_trace_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::Yes, ToTrace::to_trace( &obligation.cause, @@ -2702,8 +2704,6 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ), target_projection, source_projection, - obligation.param_env, - &obligation.cause, ) }) .map_err(|_| SelectionError::Unimplemented)? @@ -2757,11 +2757,11 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ); self.infcx .eq_at( + &obligation.cause, + obligation.param_env, DefineOpaqueTypes::No, predicate.trait_ref, trait_ref, - obligation.param_env, - &obligation.cause, ) .map(|InferOk { obligations, .. }| obligations) .map_err(|_| ()) diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 5d18726b2f450..d3e78cfd23968 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -49,11 +49,11 @@ pub(crate) fn synthesize_blanket_impls( // Require the type the impl is implemented on to match // our type, and ignore the impl if there was a mismatch. let Ok(eq_result) = infcx.eq_at( + &traits::ObligationCause::dummy(), + param_env, DefineOpaqueTypes::Yes, impl_trait_ref.self_ty(), impl_ty, - param_env, - &traits::ObligationCause::dummy(), ) else { continue; }; From 48dcf59d7e795657d4e17d8510297582c9a4de75 Mon Sep 17 00:00:00 2001 From: Fallible <118682743+fallible-algebra@users.noreply.github.com> Date: Wed, 30 Sep 2026 13:29:25 +0100 Subject: [PATCH 7/9] Update method names and remove some remaining At calls (attempt 2) --- .../src/coherence/builtin/coerce_shared.rs | 10 ++++++++-- compiler/rustc_trait_selection/src/regions.rs | 4 +++- .../src/traits/normalize.rs | 2 +- .../src/traits/query/normalize.rs | 17 ++++++----------- .../src/traits/structural_normalize.rs | 2 +- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/html/format.rs | 16 ++++++++++++---- 7 files changed, 32 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin/coerce_shared.rs b/compiler/rustc_hir_analysis/src/coherence/builtin/coerce_shared.rs index 4d685ec3c6810..f4c8d72c2e4cb 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin/coerce_shared.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin/coerce_shared.rs @@ -779,8 +779,14 @@ fn field_tys_satisfy_relation_after_normalization_and_resolution<'tcx>( match relation { FieldRelation::Equal => { if infcx - .at(&cause, param_env) - .relate(DefineOpaqueTypes::Yes, source_ty, ty::Variance::Invariant, target_ty) + .relate_at( + &cause, + param_env, + DefineOpaqueTypes::Yes, + source_ty, + ty::Variance::Invariant, + target_ty, + ) .is_err() { return false; diff --git a/compiler/rustc_trait_selection/src/regions.rs b/compiler/rustc_trait_selection/src/regions.rs index f54d774e32670..7cbb312d35fc8 100644 --- a/compiler/rustc_trait_selection/src/regions.rs +++ b/compiler/rustc_trait_selection/src/regions.rs @@ -99,8 +99,10 @@ pub fn ty_known_to_outlive<'tcx>( // Types in region obligations should be normalized. let ty = if infcx.next_trait_solver() { let Ok(ty) = crate::solve::deeply_normalize::<_, ScrubbedTraitError<'tcx>>( - infcx.at(&ObligationCause::dummy_with_span(DUMMY_SP), param_env), + infcx, ty, + param_env, + &ObligationCause::dummy_with_span(DUMMY_SP), ) else { return Err(()); }; diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index 0f1fd6aa040af..0d88dfe6a87d8 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -82,7 +82,7 @@ impl<'tcx> InferCtxt<'tcx> { .normalize(value, param_env, cause) .into_value_registering_obligations(&self, &mut *fulfill_cx); let errors = fulfill_cx.evaluate_obligations_error_on_ambiguity(&self); - let value = self.resolve_vars_if_possible(value); + let value = self.deeply_resolve_ignoring_regions(value); match errors { TraitErrors::NoErrors => Ok(value), TraitErrors::HasErrors(errors) => { diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 646d23e111602..5331030c24699 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -19,10 +19,7 @@ use crate::error_reporting::traits::OverflowCause; use crate::infer::canonical::OriginalQueryValues; use crate::infer::{InferCtxt, InferOk}; use crate::traits::normalize::needs_normalization; -use crate::traits::{ - BoundVarReplacer, FulfillmentError, FulfillmentErrorCode, Normalized, ObligationCause, - PlaceholderReplacer, -}; +use crate::traits::{BoundVarReplacer, Normalized, ObligationCause, PlaceholderReplacer}; #[extension(pub trait QueryNormalizeExt<'tcx>)] impl<'tcx> InferCtxt<'tcx> { @@ -80,13 +77,11 @@ impl<'tcx> InferCtxt<'tcx> { }; if self.next_trait_solver() { - match crate::solve::deeply_normalize_with_skipped_universes::<_, ScrubbedTraitError<'tcx>>( - &self, - Unnormalized::new_wip(value), - universes, - param_env, - &cause, - ) { + match crate::solve::deeply_normalize_with_skipped_universes::< + _, + rustc_infer::traits::ScrubbedTraitError<'tcx>, + >(&self, Unnormalized::new_wip(value), universes, param_env, &cause) + { Ok(value) => { return Ok(Normalized { value, obligations: PredicateObligations::new() }); } diff --git a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs index 14dafd1dd04ed..2e096a9a46d75 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs @@ -75,7 +75,7 @@ impl<'tcx> InferCtxt<'tcx> { return Err(errors); } - Ok(self.resolve_vars_if_possible(new_infer)) + Ok(self.deeply_resolve_ignoring_regions(new_infer)) } else { Ok(self .normalize(term, param_env, cause) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5465c097d9de8..8db6fbe90ed98 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2027,7 +2027,7 @@ fn normalize<'tcx>( let infcx = cx.tcx.infer_ctxt().build(TypingMode::non_body_analysis()); let normalized = infcx .query_normalize(ty, cx.param_env, ObligationCause::dummy()) - .map(|resolved| infcx.resolve_vars_if_possible(resolved.value)); + .map(|resolved| infcx.deeply_resolve_ignoring_regions(resolved.value)); match normalized { Ok(normalized_value) => { debug!("normalized {ty:?} to {normalized_value:?}"); diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 355a6c81d3320..9f8d864e5639a 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -18,10 +18,13 @@ use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::def::{DefKind, MacroKinds}; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; +use rustc_infer::infer::TyCtxtInferExt; +use rustc_infer::traits::ObligationCause; use rustc_metadata::creader::CStore; use rustc_middle::ty::{self, Ty, TyCtxt, TypingMode}; use rustc_span::symbol::kw; use rustc_span::{Ident, Symbol}; +use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt; use tracing::{debug, trace}; use super::url_parts_builder::UrlPartsBuilder; @@ -420,8 +423,11 @@ fn impl_self_ty(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Ty<'_> { let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis()); let ty = tcx.type_of(impl_def_id); infcx - .at(&ObligationCause::dummy(), tcx.param_env(impl_def_id)) - .query_normalize(ty::Binder::dummy(ty.instantiate_identity().skip_norm_wip())) + .query_normalize( + ty::Binder::dummy(ty.instantiate_identity().skip_norm_wip()), + tcx.param_env(impl_def_id), + ObligationCause::dummy(), + ) .map(|resolved| infcx.deeply_resolve_ignoring_regions(resolved.value).skip_binder()) .unwrap_or(ty.skip_binder()) } @@ -514,7 +520,9 @@ fn generate_item_def_id_path( // No need to try to infer the actual parent item if it's not an associated item from the `impl` // block. - if def_id != original_def_id && matches!(tcx.def_kind(def_id), DefKind::Impl { .. }) { + if def_id != original_def_id + && let DefKind::Impl { of_trait } = tcx.def_kind(def_id) + { let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis()); let ty = tcx.type_of(def_id); let ty = infcx @@ -523,7 +531,7 @@ fn generate_item_def_id_path( tcx.param_env(def_id), ObligationCause::dummy(), ) - .map(|resolved| infcx.resolve_vars_if_possible(resolved.value).skip_binder()) + .map(|resolved| infcx.deeply_resolve_ignoring_regions(resolved.value).skip_binder()) .unwrap_or(ty.skip_binder()); if let Some(new_def_id) = ty.ty_adt_def().map(|adt| adt.did()) { def_id = new_def_id; From 3debba760c7902f38953f17cc630f4dd234a37fb Mon Sep 17 00:00:00 2001 From: Fallible <118682743+fallible-algebra@users.noreply.github.com> Date: Wed, 30 Sep 2026 13:44:23 +0100 Subject: [PATCH 8/9] no 'at' suffixes --- .../src/coherence/builtin/coerce_shared.rs | 2 +- .../src/coherence/orphan.rs | 2 +- compiler/rustc_hir_typeck/src/callee.rs | 2 +- compiler/rustc_hir_typeck/src/cast.rs | 2 +- compiler/rustc_hir_typeck/src/closure.rs | 4 ++-- compiler/rustc_hir_typeck/src/coercion.rs | 10 ++++----- compiler/rustc_hir_typeck/src/demand.rs | 8 +++---- compiler/rustc_hir_typeck/src/expr.rs | 2 +- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 2 +- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 4 ++-- .../rustc_hir_typeck/src/method/confirm.rs | 2 +- compiler/rustc_hir_typeck/src/method/probe.rs | 2 +- compiler/rustc_infer/src/infer/at.rs | 20 ++++++++--------- .../src/infer/canonical/query_response.rs | 10 ++++----- compiler/rustc_infer/src/infer/mod.rs | 4 ++-- .../rustc_infer/src/infer/opaque_types/mod.rs | 4 ++-- .../rustc_infer/src/infer/relate/lattice.rs | 10 ++++----- compiler/rustc_lint/src/runtime_symbols.rs | 2 +- .../src/error_reporting/infer/mod.rs | 2 +- .../src/error_reporting/traits/suggestions.rs | 2 +- .../src/traits/auto_trait.rs | 2 +- .../src/traits/coherence.rs | 10 ++++----- .../src/traits/effects.rs | 2 +- .../src/traits/engine.rs | 12 +++++----- .../src/traits/fulfill.rs | 8 +++---- .../src/traits/project.rs | 6 ++--- .../src/traits/select/confirmation.rs | 12 +++++----- .../src/traits/select/mod.rs | 22 +++++++++---------- src/librustdoc/clean/blanket_impl.rs | 2 +- 29 files changed, 86 insertions(+), 86 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin/coerce_shared.rs b/compiler/rustc_hir_analysis/src/coherence/builtin/coerce_shared.rs index f4c8d72c2e4cb..5fbc87aed6340 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin/coerce_shared.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin/coerce_shared.rs @@ -779,7 +779,7 @@ fn field_tys_satisfy_relation_after_normalization_and_resolution<'tcx>( match relation { FieldRelation::Equal => { if infcx - .relate_at( + .relate( &cause, param_env, DefineOpaqueTypes::Yes, diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index df5bf8b9c8b46..6d418e2d9f720 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -371,7 +371,7 @@ fn orphan_check<'tcx>( for (arg, id_arg) in std::iter::zip(args, ty::GenericArgs::identity_for_item(tcx, impl_def_id)) { - let _ = infcx.eq_at( + let _ = infcx.eq( &cause, ty::ParamEnv::empty(), DefineOpaqueTypes::No, diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index e21ae111da401..5ff9b5134b00a 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -730,7 +730,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // adjustments search for mapped arguments. let cause = self.cause(call_expr.span, ObligationCauseCode::Misc); if self - .sup_at( + .sup( &cause, self.param_env, DefineOpaqueTypes::Yes, diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 4300ac4edf1ff..fc050669ca1b3 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -1091,7 +1091,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { // This is `fcx.demand_eqtype`, but inlined to give a better error. let cause = fcx.misc(self.span); if fcx - .eq_at(&cause, fcx.param_env, DefineOpaqueTypes::Yes, src_obj, dst_obj) + .eq(&cause, fcx.param_env, DefineOpaqueTypes::Yes, src_obj, dst_obj) .map(|infer_ok| fcx.register_infer_ok_obligations(infer_ok)) .is_err() { diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 1ef1fbb62fd3f..3c5de55bcac89 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -798,7 +798,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) { // Check that E' = S'. let cause = self.misc(hir_ty.span); - let InferOk { value: (), obligations } = self.eq_at( + let InferOk { value: (), obligations } = self.eq( &cause, self.param_env, DefineOpaqueTypes::Yes, @@ -810,7 +810,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let supplied_output_ty = supplied_sig.output(); let cause = &self.misc(decl.output.span()); - let InferOk { value: (), obligations } = self.eq_at( + let InferOk { value: (), obligations } = self.eq( cause, self.param_env, DefineOpaqueTypes::Yes, diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 8508877732ad4..710f30c3483bf 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -166,9 +166,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { let outer_universe = self.infcx.universe(); let res = if self.use_lub { - self.lub_at(&self.cause, self.fcx.param_env, b, a) + self.lub(&self.cause, self.fcx.param_env, b, a) } else { - self.sup_at(&self.cause, self.fcx.param_env, DefineOpaqueTypes::Yes, b, a) + self.sup(&self.cause, self.fcx.param_env, DefineOpaqueTypes::Yes, b, a) .map(|InferOk { value: (), obligations }| InferOk { value: b, obligations }) }; @@ -1373,7 +1373,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Err(TypeError::Mismatch) } } else { - self.lub_at(cause, self.param_env, prev_ty, new_ty) + self.lub(cause, self.param_env, prev_ty, new_ty) }; self.leak_check(outer_universe, Some(snapshot))?; @@ -1412,7 +1412,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // The signature must match. let (a_sig, b_sig) = self.normalize(new.span, Unnormalized::new_wip((a_sig, b_sig))); let sig = self - .lub_at(cause, self.param_env, a_sig, b_sig) + .lub(cause, self.param_env, a_sig, b_sig) .map(|ok| self.register_infer_ok_obligations(ok))?; // Reify both sides and return the reified fn pointer type. @@ -1726,7 +1726,7 @@ impl<'tcx> CoerceMany<'tcx> { // // Another example is `break` with no argument expression. assert!(expression_ty.is_unit(), "if let hack without unit type"); - fcx.eq_at( + fcx.eq( // needed for tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs cause, fcx.param_env, diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 8328620926de5..1922734a5304f 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -190,7 +190,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected: Ty<'tcx>, actual: Ty<'tcx>, ) -> Result<(), Diag<'a>> { - self.sup_at(cause, self.param_env, DefineOpaqueTypes::Yes, expected, actual) + self.sup(cause, self.param_env, DefineOpaqueTypes::Yes, expected, actual) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) .map_err(|e| { self.err_ctxt().report_mismatched_types(cause, self.param_env, expected, actual, e) @@ -218,7 +218,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected: Ty<'tcx>, actual: Ty<'tcx>, ) -> Result<(), Diag<'a>> { - self.eq_at(cause, self.param_env, DefineOpaqueTypes::Yes, expected, actual) + self.eq(cause, self.param_env, DefineOpaqueTypes::Yes, expected, actual) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) .map_err(|e| { self.err_ctxt().report_mismatched_types(cause, self.param_env, expected, actual, e) @@ -414,7 +414,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } }; let _ = self - .eq_at( + .eq( &ObligationCause::dummy(), self.param_env, DefineOpaqueTypes::Yes, @@ -501,7 +501,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .ok() .and_then(|method| { let _ = self - .eq_at( + .eq( &ObligationCause::dummy(), self.param_env, DefineOpaqueTypes::Yes, diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index db2add7e35457..b3f20c873cc42 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -2101,7 +2101,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Some(_) = remaining_fields.remove(&ident) { let target_ty = self.field_ty(base_expr.span, f, args); let cause = self.misc(base_expr.span); - match self.sup_at( + match self.sup( // We're already using inference variables for any params, // and don't allow converting between different structs, // so there is no way this ever actually defines an opaque diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index b0bddc44d0a37..705411bc8c974 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -1449,7 +1449,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // This also occurs for an enum variant on a type alias. let impl_ty = self.normalize(span, tcx.type_of(impl_def_id).instantiate(tcx, args)); let self_ty = self.normalize(span, Unnormalized::new_wip(self_ty)); - match self.eq_at( + match self.eq( &self.misc(span), self.param_env, DefineOpaqueTypes::Yes, diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 6e47a55111c91..71b0249012bad 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -396,7 +396,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // 3. Check if the formal type is actually equal to the checked one // and register any such obligations for future type checks. - let formal_ty_error = self.eq_at( + let formal_ty_error = self.eq( &self.misc(provided_arg.span), self.param_env, DefineOpaqueTypes::Yes, @@ -3225,7 +3225,7 @@ impl<'a, 'tcx> ArgMatchingCtxt<'a, 'tcx> { // Using probe here, since we don't want this subtyping to affect inference. let subtyping_error = self.probe(|_| { - self.sup_at( + self.sup( &self.misc(arg_span), self.param_env, DefineOpaqueTypes::Yes, diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index b7d2e75aec03a..6097d4de5079a 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -560,7 +560,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { self_ty, method_self_ty, self.span, pick ); let cause = self.cause(self.self_expr.span, ObligationCauseCode::Misc); - match self.sup_at(&cause, self.param_env, DefineOpaqueTypes::Yes, method_self_ty, self_ty) { + match self.sup(&cause, self.param_env, DefineOpaqueTypes::Yes, method_self_ty, self_ty) { Ok(InferOk { obligations, value: () }) => { self.register_predicates(obligations); } diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 745e73dc9bd88..2328949f58ed4 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -1971,7 +1971,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { self.xform_self_ty(candidate.item, trait_ref.self_ty(), trait_ref.args); // Guide the trait selection to show impls that have methods whose type matches // up with the `self` parameter of the method. - let _ = self.sup_at( + let _ = self.sup( &ObligationCause::dummy(), self.param_env, DefineOpaqueTypes::Yes, diff --git a/compiler/rustc_infer/src/infer/at.rs b/compiler/rustc_infer/src/infer/at.rs index 356c7ceda0a02..b9f4a323d7125 100644 --- a/compiler/rustc_infer/src/infer/at.rs +++ b/compiler/rustc_infer/src/infer/at.rs @@ -107,7 +107,7 @@ impl<'tcx> InferCtxt<'tcx> { forked } - pub fn sup_at( + pub fn sup( &self, cause: &ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, @@ -142,7 +142,7 @@ impl<'tcx> InferCtxt<'tcx> { } /// Makes `expected <: actual`. - pub fn sub_at( + pub fn sub( &self, cause: &ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, @@ -169,7 +169,7 @@ impl<'tcx> InferCtxt<'tcx> { } } - pub fn eq_at( + pub fn eq( &self, cause: &ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, @@ -180,7 +180,7 @@ impl<'tcx> InferCtxt<'tcx> { where T: ToTrace<'tcx>, { - self.eq_trace_at( + self.eq_trace( cause, param_env, define_opaque_types, @@ -190,7 +190,7 @@ impl<'tcx> InferCtxt<'tcx> { ) } - pub fn eq_trace_at( + pub fn eq_trace( &self, cause: &ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, @@ -213,7 +213,7 @@ impl<'tcx> InferCtxt<'tcx> { } } - pub fn relate_at( + pub fn relate( &self, cause: &ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, @@ -226,10 +226,10 @@ impl<'tcx> InferCtxt<'tcx> { T: ToTrace<'tcx>, { match variance { - ty::Covariant => self.sub_at(cause, param_env, define_opaque_types, expected, actual), - ty::Invariant => self.eq_at(cause, param_env, define_opaque_types, expected, actual), + ty::Covariant => self.sub(cause, param_env, define_opaque_types, expected, actual), + ty::Invariant => self.eq(cause, param_env, define_opaque_types, expected, actual), ty::Contravariant => { - self.sup_at(cause, param_env, define_opaque_types, expected, actual) + self.sup(cause, param_env, define_opaque_types, expected, actual) } // We could make this make sense but it's not readily @@ -246,7 +246,7 @@ impl<'tcx> InferCtxt<'tcx> { /// this can result in an error (e.g., if asked to compute LUB of /// u32 and i32), it is meaningful to call one of them the /// "expected type". - pub fn lub_at( + pub fn lub( &self, cause: &ObligationCause<'tcx>, param_env: ty::ParamEnv<'tcx>, diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index 1d1dbc7b7afce..9070d5e91f20c 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -305,14 +305,14 @@ impl<'tcx> InferCtxt<'tcx> { (GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => { obligations.extend( - self.eq_at(cause, param_env, DefineOpaqueTypes::Yes, v1, v2)? + self.eq(cause, param_env, DefineOpaqueTypes::Yes, v1, v2)? .into_obligations(), ); } (GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => { obligations.extend( - self.eq_at(cause, param_env, DefineOpaqueTypes::Yes, v1, v2)? + self.eq(cause, param_env, DefineOpaqueTypes::Yes, v1, v2)? .into_obligations(), ); } @@ -521,7 +521,7 @@ impl<'tcx> InferCtxt<'tcx> { // variable that got constrained to the opaque type itself. In that case we want to equate // the generic args of the opaque with the generic params of its hidden type version. obligations.extend( - self.eq_at( + self.eq( cause, param_env, DefineOpaqueTypes::Yes, @@ -581,7 +581,7 @@ impl<'tcx> InferCtxt<'tcx> { match (value1.kind(), value2.kind()) { (GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => { obligations.extend( - self.eq_at(cause, param_env, DefineOpaqueTypes::Yes, v1, v2)? + self.eq(cause, param_env, DefineOpaqueTypes::Yes, v1, v2)? .into_obligations(), ); } @@ -599,7 +599,7 @@ impl<'tcx> InferCtxt<'tcx> { ); } (GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => { - let ok = self.eq_at(cause, param_env, DefineOpaqueTypes::Yes, v1, v2)?; + let ok = self.eq(cause, param_env, DefineOpaqueTypes::Yes, v1, v2)?; obligations.extend(ok.into_obligations()); } _ => { diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 2e30f13200090..27a0736c9d6e9 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -881,9 +881,9 @@ impl<'tcx> InferCtxt<'tcx> { self.enter_forall(predicate, |ty::SubtypePredicate { a_is_expected, a, b }| { if a_is_expected { - Ok(self.sub_at(cause, param_env, DefineOpaqueTypes::Yes, a, b)) + Ok(self.sub(cause, param_env, DefineOpaqueTypes::Yes, a, b)) } else { - Ok(self.sup_at(cause, param_env, DefineOpaqueTypes::Yes, b, a)) + Ok(self.sup(cause, param_env, DefineOpaqueTypes::Yes, b, a)) } }) } diff --git a/compiler/rustc_infer/src/infer/opaque_types/mod.rs b/compiler/rustc_infer/src/infer/opaque_types/mod.rs index 3f8b18cab3179..5a17b1668747b 100644 --- a/compiler/rustc_infer/src/infer/opaque_types/mod.rs +++ b/compiler/rustc_infer/src/infer/opaque_types/mod.rs @@ -245,7 +245,7 @@ impl<'tcx> InferCtxt<'tcx> { .register(opaque_type_key, ProvisionalHiddenType { ty: hidden_ty, span }); if let Some(prev) = prev { goals.extend( - self.eq_at( + self.eq( &ObligationCause::dummy_with_span(span), param_env, DefineOpaqueTypes::Yes, @@ -280,7 +280,7 @@ impl<'tcx> InferCtxt<'tcx> { }); goals.extend( - self.eq_at( + self.eq( &ObligationCause::dummy_with_span(span), param_env, DefineOpaqueTypes::Yes, diff --git a/compiler/rustc_infer/src/infer/relate/lattice.rs b/compiler/rustc_infer/src/infer/relate/lattice.rs index 51a0b51b5a303..c0742a88d8a9f 100644 --- a/compiler/rustc_infer/src/infer/relate/lattice.rs +++ b/compiler/rustc_infer/src/infer/relate/lattice.rs @@ -99,7 +99,7 @@ impl<'tcx> TypeRelation> for LatticeOp<'_, 'tcx> { ty::Invariant => { self.obligations.extend( self.infcx - .eq_trace_at( + .eq_trace( &self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, @@ -265,24 +265,24 @@ impl<'infcx, 'tcx> LatticeOp<'infcx, 'tcx> { LatticeOpKind::Glb => { self.obligations.extend( self.infcx - .sub_at(&self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, v, a)? + .sub(&self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, v, a)? .into_obligations(), ); self.obligations.extend( self.infcx - .sub_at(&self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, v, b)? + .sub(&self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, v, b)? .into_obligations(), ); } LatticeOpKind::Lub => { self.obligations.extend( self.infcx - .sub_at(&self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, a, v)? + .sub(&self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, a, v)? .into_obligations(), ); self.obligations.extend( self.infcx - .sub_at(&self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, b, v)? + .sub(&self.trace.cause, self.param_env, DefineOpaqueTypes::Yes, b, v)? .into_obligations(), ); } diff --git a/compiler/rustc_lint/src/runtime_symbols.rs b/compiler/rustc_lint/src/runtime_symbols.rs index d62f1d129d821..0c29f9acd8d57 100644 --- a/compiler/rustc_lint/src/runtime_symbols.rs +++ b/compiler/rustc_lint/src/runtime_symbols.rs @@ -220,7 +220,7 @@ fn check<'tcx>( // Compare the two signatures with an inference context let infcx = cx.tcx.infer_ctxt().build(cx.typing_mode()); let cause = rustc_middle::traits::ObligationCause::misc(sp, did); - let result = infcx.eq_at(&cause, cx.param_env, DefineOpaqueTypes::No, lang_sig, user_sig); + let result = infcx.eq(&cause, cx.param_env, DefineOpaqueTypes::No, lang_sig, user_sig); // If they don't match, emit our own mismatch signatures if result.is_err() { diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index a7f2a860ab868..e84dbc74c4ff6 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -277,7 +277,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let expected_trait_ref = alias.trait_ref(tcx); - if let Err(_) = self.infcx.eq_at( + if let Err(_) = self.infcx.eq( &ObligationCause::dummy(), param_env, DefineOpaqueTypes::No, diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index f11323e552efb..f658c6a135b1d 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -5394,7 +5394,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { match self // Doesn't actually matter if we define opaque types here, this is just used for // diagnostics, and the result is never kept around. - .eq_at( + .eq( &ObligationCause::misc(expr.span, body_def_id), param_env, DefineOpaqueTypes::Yes, diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index be0d3183ae251..683c16a8b6249 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -872,7 +872,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { match (evaluate(c1), evaluate(c2)) { (Ok(c1), Ok(c2)) => { - match selcx.infcx.eq_at( + match selcx.infcx.eq( &obligation.cause, obligation.param_env, DefineOpaqueTypes::Yes, diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 097e15a39500e..b3756933c9dfa 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -355,14 +355,14 @@ fn equate_impl_headers<'tcx>( impl2: &ImplHeader<'tcx>, ) -> Option> { let result = match (impl1.trait_ref, impl2.trait_ref) { - (Some(impl1_ref), Some(impl2_ref)) => infcx.eq_at( + (Some(impl1_ref), Some(impl2_ref)) => infcx.eq( &ObligationCause::dummy(), param_env, DefineOpaqueTypes::Yes, impl1_ref, impl2_ref, ), - (None, None) => infcx.eq_at( + (None, None) => infcx.eq( &ObligationCause::dummy(), param_env, DefineOpaqueTypes::Yes, @@ -587,7 +587,7 @@ fn plug_infer_with_placeholders<'tcx>( fn visit_ty(&mut self, ty: Ty<'tcx>) { let ty = self.infcx.shallow_resolve(ty); if ty.is_ty_var() { - let Ok(InferOk { value: (), obligations }) = self.infcx.eq_at( + let Ok(InferOk { value: (), obligations }) = self.infcx.eq( // Comparing against a type variable never registers hidden types anyway &ObligationCause::dummy(), ty::ParamEnv::empty(), @@ -612,7 +612,7 @@ fn plug_infer_with_placeholders<'tcx>( fn visit_const(&mut self, ct: ty::Const<'tcx>) { let ct = self.infcx.shallow_resolve_const(ct); if ct.is_ct_infer() { - let Ok(InferOk { value: (), obligations }) = self.infcx.eq_at( + let Ok(InferOk { value: (), obligations }) = self.infcx.eq( // The types of the constants are the same, so there is no hidden type // registration happening anyway. &ObligationCause::dummy(), @@ -644,7 +644,7 @@ fn plug_infer_with_placeholders<'tcx>( .unwrap_region_constraints() .shallow_resolve_region_var(self.infcx.tcx, vid); if r.is_var() { - let Ok(InferOk { value: (), obligations }) = self.infcx.eq_at( + let Ok(InferOk { value: (), obligations }) = self.infcx.eq( // Lifetimes don't contain opaque types (or any types for that matter). &ObligationCause::dummy(), ty::ParamEnv::empty(), diff --git a/compiler/rustc_trait_selection/src/traits/effects.rs b/compiler/rustc_trait_selection/src/traits/effects.rs index 8d8a86cdfbcbe..3f4524eb30872 100644 --- a/compiler/rustc_trait_selection/src/traits/effects.rs +++ b/compiler/rustc_trait_selection/src/traits/effects.rs @@ -113,7 +113,7 @@ fn match_candidate<'tcx>( nested.extend( selcx .infcx - .eq_at( + .eq( &obligation.cause, obligation.param_env, DefineOpaqueTypes::Yes, diff --git a/compiler/rustc_trait_selection/src/traits/engine.rs b/compiler/rustc_trait_selection/src/traits/engine.rs index df16c9f0eb3a3..77c6fdac985c8 100644 --- a/compiler/rustc_trait_selection/src/traits/engine.rs +++ b/compiler/rustc_trait_selection/src/traits/engine.rs @@ -227,7 +227,7 @@ where actual: T, ) -> Result<(), TypeError<'tcx>> { self.infcx - .eq_at(cause, param_env, DefineOpaqueTypes::Yes, expected, actual) + .eq(cause, param_env, DefineOpaqueTypes::Yes, expected, actual) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } @@ -240,7 +240,7 @@ where actual: T, ) -> Result<(), TypeError<'tcx>> { self.infcx - .eq_trace_at(cause, param_env, DefineOpaqueTypes::Yes, trace, expected, actual) + .eq_trace(cause, param_env, DefineOpaqueTypes::Yes, trace, expected, actual) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } @@ -253,7 +253,7 @@ where actual: T, ) -> Result<(), TypeError<'tcx>> { self.infcx - .sub_at(cause, param_env, DefineOpaqueTypes::Yes, expected, actual) + .sub(cause, param_env, DefineOpaqueTypes::Yes, expected, actual) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } @@ -266,7 +266,7 @@ where actual: T, ) -> Result<(), TypeError<'tcx>> { self.infcx - .relate_at(cause, param_env, DefineOpaqueTypes::Yes, expected, variance, actual) + .relate(cause, param_env, DefineOpaqueTypes::Yes, expected, variance, actual) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } @@ -279,7 +279,7 @@ where actual: T, ) -> Result<(), TypeError<'tcx>> { self.infcx - .sup_at(cause, param_env, DefineOpaqueTypes::Yes, expected, actual) + .sup(cause, param_env, DefineOpaqueTypes::Yes, expected, actual) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } @@ -292,7 +292,7 @@ where actual: T, ) -> Result> { self.infcx - .lub_at(cause, param_env, expected, actual) + .lub(cause, param_env, expected, actual) .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 5a203b2f932e3..334ffe977abbb 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -577,7 +577,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { } }; - match infcx.eq_at( + match infcx.eq( // Only really exercised by generic_const_exprs &obligation.cause, obligation.param_env, @@ -731,7 +731,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { if let Ok(new_obligations) = infcx // Can define opaque types as this is only reachable with // `generic_const_exprs` - .eq_at( + .eq( &obligation.cause, obligation.param_env, DefineOpaqueTypes::Yes, @@ -750,7 +750,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { if let Ok(new_obligations) = infcx // Can define opaque types as this is only reachable with // `generic_const_exprs` - .eq_at( + .eq( &obligation.cause, obligation.param_env, DefineOpaqueTypes::Yes, @@ -796,7 +796,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { match (evaluate(c1), evaluate(c2)) { (Ok(c1), Ok(c2)) => { - match self.selcx.infcx.eq_at( + match self.selcx.infcx.eq( // Can define opaque types as this is only reachable with // `generic_const_exprs` &obligation.cause, diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 0e8b5610365dc..33faeae22a232 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -235,7 +235,7 @@ fn project_and_unify_term<'cx, 'tcx>( obligations.extend(new); // Need to define opaque types to support nested opaque types like `impl Fn() -> impl Trait` - match infcx.eq_at( + match infcx.eq( &obligation.cause, obligation.param_env, DefineOpaqueTypes::Yes, @@ -638,7 +638,7 @@ pub fn compute_inherent_assoc_term_args<'a, 'b, 'tcx>( self_ty.skip_normalization() }; - match selcx.infcx.eq_at(&cause, param_env, DefineOpaqueTypes::Yes, impl_ty, self_ty) { + match selcx.infcx.eq(&cause, param_env, DefineOpaqueTypes::Yes, impl_ty, self_ty) { Ok(mut ok) => obligations.append(&mut ok.obligations), Err(_) => { tcx.dcx().span_bug( @@ -2021,7 +2021,7 @@ fn confirm_param_env_candidate<'cx, 'tcx>( debug!(?cache_projection, ?obligation_projection); - match infcx.eq_at( + match infcx.eq( cause, param_env, DefineOpaqueTypes::Yes, diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index c880847f1050e..e1308177bb259 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -189,7 +189,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligations.extend( self.infcx - .eq_at( + .eq( &obligation.cause, obligation.param_env, DefineOpaqueTypes::No, @@ -530,7 +530,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { nested.extend( self.infcx - .eq_at( + .eq( &obligation.cause, obligation.param_env, DefineOpaqueTypes::No, @@ -987,7 +987,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // needed to define opaque types for tests/ui/type-alias-impl-trait/assoc-projection-ice.rs self.infcx - .eq_at( + .eq( &obligation.cause, obligation.param_env, DefineOpaqueTypes::Yes, @@ -1099,7 +1099,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // only the **lifetime bound** is changed. let InferOk { mut obligations, .. } = self .infcx - .sup_at( + .sup( &obligation.cause, obligation.param_env, DefineOpaqueTypes::Yes, @@ -1171,7 +1171,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { (&ty::Array(a, _), &ty::Slice(b)) => { let InferOk { obligations, .. } = self .infcx - .eq_at(&obligation.cause, obligation.param_env, DefineOpaqueTypes::Yes, b, a) + .eq(&obligation.cause, obligation.param_env, DefineOpaqueTypes::Yes, b, a) .map_err(|_| SelectionError::Unimplemented)?; ImplSource::Builtin(BuiltinImplSource::Misc, obligations) @@ -1218,7 +1218,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let new_struct = Ty::new_adt(tcx, def, args); let InferOk { obligations, .. } = self .infcx - .eq_at( + .eq( &obligation.cause, obligation.param_env, DefineOpaqueTypes::Yes, diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index b497a17f3c915..0ab0cd3805a67 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -883,7 +883,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .infcx // Can define opaque types as this is only reachable with // `generic_const_exprs` - .eq_at( + .eq( &obligation.cause, obligation.param_env, DefineOpaqueTypes::Yes, @@ -901,7 +901,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .infcx // Can define opaque types as this is only reachable with // `generic_const_exprs` - .eq_at( + .eq( &obligation.cause, obligation.param_env, DefineOpaqueTypes::Yes, @@ -931,7 +931,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { match (evaluate(c1), evaluate(c2)) { (Ok(c1), Ok(c2)) => { - match self.infcx.eq_at( + match self.infcx.eq( // Can define opaque types as this is only reachable with // `generic_const_exprs` &obligation.cause, @@ -988,7 +988,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } }; - match self.infcx.eq_at( + match self.infcx.eq( // Only really exercised by generic_const_exprs &obligation.cause, obligation.param_env, @@ -1701,7 +1701,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ty::Unnormalized::new_wip(trait_bound), ); self.infcx - .eq_at( + .eq( &obligation.cause, obligation.param_env, DefineOpaqueTypes::No, @@ -1768,7 +1768,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let is_match = self .infcx - .eq_at( + .eq( &obligation.cause, obligation.param_env, DefineOpaqueTypes::No, @@ -2533,7 +2533,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { let InferOk { obligations, .. } = self .infcx - .eq_at( + .eq( &cause, obligation.param_env, DefineOpaqueTypes::No, @@ -2622,7 +2622,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { HigherRankedType, hr_source_principal, ); - self.infcx.eq_trace_at( + self.infcx.eq_trace( &obligation.cause, obligation.param_env, DefineOpaqueTypes::Yes, @@ -2661,7 +2661,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { HigherRankedType, hr_source_projection, ); - self.infcx.eq_trace_at( + self.infcx.eq_trace( &obligation.cause, obligation.param_env, DefineOpaqueTypes::Yes, @@ -2693,7 +2693,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { HigherRankedType, hr_source_projection, ); - self.infcx.eq_trace_at( + self.infcx.eq_trace( &obligation.cause, obligation.param_env, DefineOpaqueTypes::Yes, @@ -2756,7 +2756,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { poly_trait_ref, ); self.infcx - .eq_at( + .eq( &obligation.cause, obligation.param_env, DefineOpaqueTypes::No, diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index d3e78cfd23968..d0ed33fe280ee 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -48,7 +48,7 @@ pub(crate) fn synthesize_blanket_impls( // Require the type the impl is implemented on to match // our type, and ignore the impl if there was a mismatch. - let Ok(eq_result) = infcx.eq_at( + let Ok(eq_result) = infcx.eq( &traits::ObligationCause::dummy(), param_env, DefineOpaqueTypes::Yes, From b538be345a255da9d5a32d3e458da7a5c1cc736a Mon Sep 17 00:00:00 2001 From: Fallible <118682743+fallible-algebra@users.noreply.github.com> Date: Wed, 30 Sep 2026 15:11:42 +0100 Subject: [PATCH 9/9] Re-order normalize args --- compiler/rustc_hir_analysis/src/coherence/orphan.rs | 9 ++------- compiler/rustc_hir_typeck/src/coercion.rs | 4 ++-- compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs | 4 ++-- compiler/rustc_hir_typeck/src/method/mod.rs | 6 +++--- compiler/rustc_infer/src/infer/at.rs | 4 +--- .../src/error_reporting/traits/fulfillment_errors.rs | 4 ++-- .../src/error_reporting/traits/suggestions.rs | 8 ++++---- compiler/rustc_trait_selection/src/solve/normalize.rs | 4 ++-- compiler/rustc_trait_selection/src/traits/coherence.rs | 2 +- compiler/rustc_trait_selection/src/traits/engine.rs | 2 +- compiler/rustc_trait_selection/src/traits/normalize.rs | 8 ++++---- .../src/traits/structural_normalize.rs | 2 +- 12 files changed, 25 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 6d418e2d9f720..9f43e1b2656f9 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -371,13 +371,8 @@ fn orphan_check<'tcx>( for (arg, id_arg) in std::iter::zip(args, ty::GenericArgs::identity_for_item(tcx, impl_def_id)) { - let _ = infcx.eq( - &cause, - ty::ParamEnv::empty(), - DefineOpaqueTypes::No, - arg, - id_arg, - ); + let _ = + infcx.eq(&cause, ty::ParamEnv::empty(), DefineOpaqueTypes::No, arg, id_arg); } infcx.deeply_resolve_ignoring_regions(tys) }); diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 710f30c3483bf..2c4a3dbf66955 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1045,9 +1045,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { let a_sig = self.sig_for_fn_def_coercion(a, Some(b_hdr.safety()))?; let InferOk { value: a_sig, mut obligations } = NormalizeExt::normalize( &self.infcx, - Unnormalized::new_wip(a_sig), - self.param_env.clone(), &self.cause, + self.param_env.clone(), + Unnormalized::new_wip(a_sig), ); let a = Ty::new_fn_ptr(self.tcx, a_sig); diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 705411bc8c974..ef316652a5aa5 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -466,9 +466,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { T: TypeFoldable>, { self.register_infer_ok_obligations(self.infcx.normalize( - value, - self.param_env, &self.misc(span), + self.param_env, + value, )) } diff --git a/compiler/rustc_hir_typeck/src/method/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs index 65c0ee203494b..7059f8afb29ae 100644 --- a/compiler/rustc_hir_typeck/src/method/mod.rs +++ b/compiler/rustc_hir_typeck/src/method/mod.rs @@ -429,9 +429,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let InferOk { value: fn_sig, obligations: o } = NormalizeExt::normalize( &self.infcx, - Unnormalized::new_wip(fn_sig), - self.param_env, &obligation.cause, + self.param_env, + Unnormalized::new_wip(fn_sig), ); obligations.extend(o); @@ -451,7 +451,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { move |_, _| predicates_cause.clone(), |clause| { let InferOk { value: pred, obligations: o } = - NormalizeExt::normalize(&self.infcx, clause, self.param_env, &obligation.cause); + NormalizeExt::normalize(&self.infcx, &obligation.cause, self.param_env, clause); normalization_obligations.extend(o); assert!(!pred.has_escaping_bound_vars()); pred diff --git a/compiler/rustc_infer/src/infer/at.rs b/compiler/rustc_infer/src/infer/at.rs index b9f4a323d7125..30b9fe19b774b 100644 --- a/compiler/rustc_infer/src/infer/at.rs +++ b/compiler/rustc_infer/src/infer/at.rs @@ -228,9 +228,7 @@ impl<'tcx> InferCtxt<'tcx> { match variance { ty::Covariant => self.sub(cause, param_env, define_opaque_types, expected, actual), ty::Invariant => self.eq(cause, param_env, define_opaque_types, expected, actual), - ty::Contravariant => { - self.sup(cause, param_env, define_opaque_types, expected, actual) - } + ty::Contravariant => self.sup(cause, param_env, define_opaque_types, expected, actual), // We could make this make sense but it's not readily // exposed and I don't feel like dealing with it. Note diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index a0fcfb0e2c240..5a346351eae95 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -3049,9 +3049,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { pred.fold_with(&mut ParamToVarFolder { infcx: self, var_map: Default::default() }); let InferOk { value: cleaned_pred, .. } = self.infcx.normalize( - Unnormalized::new_wip(cleaned_pred), - param_env, &ObligationCause::dummy(), + param_env, + Unnormalized::new_wip(cleaned_pred), ); let obligation = diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index f658c6a135b1d..465b613a62bc6 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -1617,7 +1617,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { // implied by wf, but also because that would possibly result in // erroneous errors later on. let InferOk { value: output, obligations: _ } = - self.normalize(Unnormalized::new_wip(output), param_env, &ObligationCause::dummy()); + self.normalize(&ObligationCause::dummy(), param_env, Unnormalized::new_wip(output)); if output.is_ty_var() { None } else { Some((def_id_or_name, output, inputs)) } } @@ -5034,9 +5034,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { ) }); let InferOk { value: projection_ty, .. } = self.normalize( - Unnormalized::new_wip(projection_ty), - obligation.param_env, &obligation.cause, + obligation.param_env, + Unnormalized::new_wip(projection_ty), ); debug!( @@ -5526,7 +5526,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { // Extract `::Target` assoc type and check that it is `T` && let Some(deref_target_did) = tcx.lang_items().deref_target() && let projection = Ty::new_projection_from_args(tcx,ty::IsRigid::No, deref_target_did, tcx.mk_args(&[ty::GenericArg::from(found_ty)])) - && let InferOk { value: deref_target, obligations } = infcx.normalize(Unnormalized::new_wip(projection), param_env, &ObligationCause::dummy()) + && let InferOk { value: deref_target, obligations } = infcx.normalize(&ObligationCause::dummy(), param_env, Unnormalized::new_wip(projection)) && obligations.iter().all(|obligation| infcx.predicate_must_hold_modulo_regions(obligation)) && infcx.can_eq(param_env, deref_target, target_ty) { diff --git a/compiler/rustc_trait_selection/src/solve/normalize.rs b/compiler/rustc_trait_selection/src/solve/normalize.rs index ee25d4cbbed41..3455ea0211feb 100644 --- a/compiler/rustc_trait_selection/src/solve/normalize.rs +++ b/compiler/rustc_trait_selection/src/solve/normalize.rs @@ -19,9 +19,9 @@ use crate::traits::{BoundVarReplacer, ScrubbedTraitError}; /// see `normalize_with_universes`. pub fn normalize<'tcx, T>( infcx: &InferCtxt<'tcx>, - value: Unnormalized<'tcx, T>, - param_env: ty::ParamEnv<'tcx>, cause: &ObligationCause<'tcx>, + param_env: ty::ParamEnv<'tcx>, + value: Unnormalized<'tcx, T>, ) -> Normalized<'tcx, T> where T: TypeFoldable>, diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index b3756933c9dfa..b5059552f0bc3 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -226,7 +226,7 @@ fn fresh_impl_header_normalized<'tcx>( let header = fresh_impl_header(infcx, impl_def_id, is_of_trait); let InferOk { value: mut header, obligations } = - infcx.normalize(Unnormalized::new_wip(header), param_env, &ObligationCause::dummy()); + infcx.normalize(&ObligationCause::dummy(), param_env, Unnormalized::new_wip(header)); header.predicates.extend(obligations.into_iter().map(|o| o.predicate)); header diff --git a/compiler/rustc_trait_selection/src/traits/engine.rs b/compiler/rustc_trait_selection/src/traits/engine.rs index 77c6fdac985c8..6e70056373e30 100644 --- a/compiler/rustc_trait_selection/src/traits/engine.rs +++ b/compiler/rustc_trait_selection/src/traits/engine.rs @@ -215,7 +215,7 @@ where param_env: ty::ParamEnv<'tcx>, value: Unnormalized<'tcx, T>, ) -> T { - let infer_ok = self.infcx.normalize(value, param_env, cause); + let infer_ok = self.infcx.normalize(cause, param_env, value); self.register_infer_ok_obligations(infer_ok) } diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index 0d88dfe6a87d8..79bed35e87830 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -28,13 +28,13 @@ impl<'tcx> InferCtxt<'tcx> { /// projection may be fallible. fn normalize>>( &self, - value: Unnormalized<'tcx, T>, - param_env: ty::ParamEnv<'tcx>, cause: &ObligationCause<'tcx>, + param_env: ty::ParamEnv<'tcx>, + value: Unnormalized<'tcx, T>, ) -> InferOk<'tcx, T> { if self.next_trait_solver() { let Normalized { value, obligations } = - crate::solve::normalize(self, value, param_env, cause); + crate::solve::normalize(self, cause, param_env, value); InferOk { value, obligations } } else { let mut selcx = SelectionContext::new(self); @@ -79,7 +79,7 @@ impl<'tcx> InferCtxt<'tcx> { ); } let value = self - .normalize(value, param_env, cause) + .normalize(cause, param_env, value) .into_value_registering_obligations(&self, &mut *fulfill_cx); let errors = fulfill_cx.evaluate_obligations_error_on_ambiguity(&self); let value = self.deeply_resolve_ignoring_regions(value); diff --git a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs index 2e096a9a46d75..4d327bc62496f 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs @@ -78,7 +78,7 @@ impl<'tcx> InferCtxt<'tcx> { Ok(self.deeply_resolve_ignoring_regions(new_infer)) } else { Ok(self - .normalize(term, param_env, cause) + .normalize(cause, param_env, term) .into_value_registering_obligations(&self, fulfill_cx)) } }