From c578e12016ffbe58e6e0ca841ae927aede34c2ac Mon Sep 17 00:00:00 2001 From: David Wood Date: Thu, 3 Jul 2025 09:29:08 +0000 Subject: [PATCH] trait_sel: normalise obligations from builtin impls Obligations produced by builtin impls need to be normalised so as not to later be compared to normalised candidates. For example, when introducing const sizedness then during the compilation of `std`, there will be a `thread::Inner as const MetaSized` obligation, the builtin impl will create a `::AtomicInner as const MetaSized` obligation, which if unnormalised, will end up in `evaluate_host_effect_from_item_bounds` and then `match_candidate` being compared with a normalised candidate and failing. --- .../src/traits/effects.rs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/effects.rs b/compiler/rustc_trait_selection/src/traits/effects.rs index a294981b92dc3..130c459fb792e 100644 --- a/compiler/rustc_trait_selection/src/traits/effects.rs +++ b/compiler/rustc_trait_selection/src/traits/effects.rs @@ -301,10 +301,28 @@ fn evaluate_host_effect_from_builtin_impls<'tcx>( selcx: &mut SelectionContext<'_, 'tcx>, obligation: &HostEffectObligation<'tcx>, ) -> Result>, EvaluationFailure> { - match selcx.tcx().as_lang_item(obligation.predicate.def_id()) { + let mut obligations = match selcx.tcx().as_lang_item(obligation.predicate.def_id()) { Some(LangItem::Destruct) => evaluate_host_effect_for_destruct_goal(selcx, obligation), _ => Err(EvaluationFailure::NoSolution), - } + }?; + + let mut obligations_from_normalization = thin_vec![]; + obligations = obligations + .drain(..) + .map(|mut obligation| { + obligation.recursion_depth += 1; + normalize_with_depth_to( + selcx, + obligation.param_env, + obligation.cause.clone(), + obligation.recursion_depth, + obligation, + &mut obligations_from_normalization, + ) + }) + .collect(); + obligations.extend(obligations_from_normalization.drain(..)); + Ok(obligations) } // NOTE: Keep this in sync with `const_conditions_for_destruct` in the new solver.