@@ -4,10 +4,11 @@ use crate::traits::{needs_normalization, BoundVarReplacer, PlaceholderReplacer};
44use rustc_data_structures:: stack:: ensure_sufficient_stack;
55use rustc_infer:: infer:: at:: At ;
66use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
7+ use rustc_infer:: infer:: InferCtxt ;
78use rustc_infer:: traits:: TraitEngineExt ;
89use rustc_infer:: traits:: { FulfillmentError , Obligation , TraitEngine } ;
910use rustc_middle:: infer:: unify_key:: { ConstVariableOrigin , ConstVariableOriginKind } ;
10- use rustc_middle:: traits:: Reveal ;
11+ use rustc_middle:: traits:: { ObligationCause , Reveal } ;
1112use rustc_middle:: ty:: { self , AliasTy , Ty , TyCtxt , UniverseIndex } ;
1213use rustc_middle:: ty:: { FallibleTypeFolder , TypeSuperFoldable } ;
1314use rustc_middle:: ty:: { TypeFoldable , TypeVisitableExt } ;
@@ -41,6 +42,19 @@ pub(crate) fn deeply_normalize_with_skipped_universes<'tcx, T: TypeFoldable<TyCt
4142 value. try_fold_with ( & mut folder)
4243}
4344
45+ // Deeply normalize a value and return it
46+ pub ( crate ) fn deeply_normalize_for_diagnostics < ' tcx , T : TypeFoldable < TyCtxt < ' tcx > > > (
47+ infcx : & InferCtxt < ' tcx > ,
48+ param_env : ty:: ParamEnv < ' tcx > ,
49+ t : T ,
50+ ) -> T {
51+ infcx
52+ . commit_if_ok ( |_| {
53+ deeply_normalize ( infcx. at ( & ObligationCause :: dummy ( ) , param_env) , t. clone ( ) )
54+ } )
55+ . unwrap_or ( t)
56+ }
57+
4458struct NormalizationFolder < ' me , ' tcx > {
4559 at : At < ' me , ' tcx > ,
4660 fulfill_cx : FulfillmentCtxt < ' tcx > ,
0 commit comments