@@ -9,8 +9,8 @@ use rustc_infer::infer::{
9
9
} ;
10
10
use rustc_infer:: traits:: ObligationCause ;
11
11
use rustc_infer:: traits:: query:: {
12
- CanonicalTypeOpAscribeUserTypeGoal , CanonicalTypeOpNormalizeGoal ,
13
- CanonicalTypeOpProvePredicateGoal ,
12
+ CanonicalTypeOpAscribeUserTypeGoal , CanonicalTypeOpDeeplyNormalizeGoal ,
13
+ CanonicalTypeOpNormalizeGoal , CanonicalTypeOpProvePredicateGoal ,
14
14
} ;
15
15
use rustc_middle:: ty:: error:: TypeError ;
16
16
use rustc_middle:: ty:: {
@@ -109,6 +109,14 @@ impl<'tcx, T: Copy + fmt::Display + TypeFoldable<TyCtxt<'tcx>> + 'tcx> ToUnivers
109
109
}
110
110
}
111
111
112
+ impl < ' tcx , T : Copy + fmt:: Display + TypeFoldable < TyCtxt < ' tcx > > + ' tcx > ToUniverseInfo < ' tcx >
113
+ for CanonicalTypeOpDeeplyNormalizeGoal < ' tcx , T >
114
+ {
115
+ fn to_universe_info ( self , base_universe : ty:: UniverseIndex ) -> UniverseInfo < ' tcx > {
116
+ UniverseInfo :: TypeOp ( Rc :: new ( DeeplyNormalizeQuery { canonical_query : self , base_universe } ) )
117
+ }
118
+ }
119
+
112
120
impl < ' tcx > ToUniverseInfo < ' tcx > for CanonicalTypeOpAscribeUserTypeGoal < ' tcx > {
113
121
fn to_universe_info ( self , base_universe : ty:: UniverseIndex ) -> UniverseInfo < ' tcx > {
114
122
UniverseInfo :: TypeOp ( Rc :: new ( AscribeUserTypeQuery { canonical_query : self , base_universe } ) )
@@ -285,6 +293,53 @@ where
285
293
}
286
294
}
287
295
296
+ struct DeeplyNormalizeQuery < ' tcx , T > {
297
+ canonical_query : CanonicalTypeOpDeeplyNormalizeGoal < ' tcx , T > ,
298
+ base_universe : ty:: UniverseIndex ,
299
+ }
300
+
301
+ impl < ' tcx , T > TypeOpInfo < ' tcx > for DeeplyNormalizeQuery < ' tcx , T >
302
+ where
303
+ T : Copy + fmt:: Display + TypeFoldable < TyCtxt < ' tcx > > + ' tcx ,
304
+ {
305
+ fn fallback_error ( & self , tcx : TyCtxt < ' tcx > , span : Span ) -> Diag < ' tcx > {
306
+ tcx. dcx ( ) . create_err ( HigherRankedLifetimeError {
307
+ cause : Some ( HigherRankedErrorCause :: CouldNotNormalize {
308
+ value : self . canonical_query . canonical . value . value . value . to_string ( ) ,
309
+ } ) ,
310
+ span,
311
+ } )
312
+ }
313
+
314
+ fn base_universe ( & self ) -> ty:: UniverseIndex {
315
+ self . base_universe
316
+ }
317
+
318
+ fn nice_error < ' infcx > (
319
+ & self ,
320
+ mbcx : & mut MirBorrowckCtxt < ' _ , ' infcx , ' tcx > ,
321
+ cause : ObligationCause < ' tcx > ,
322
+ placeholder_region : ty:: Region < ' tcx > ,
323
+ error_region : Option < ty:: Region < ' tcx > > ,
324
+ ) -> Option < Diag < ' infcx > > {
325
+ let ( infcx, key, _) =
326
+ mbcx. infcx . tcx . infer_ctxt ( ) . build_with_canonical ( cause. span , & self . canonical_query ) ;
327
+ let ocx = ObligationCtxt :: new ( & infcx) ;
328
+
329
+ let ( param_env, value) = key. into_parts ( ) ;
330
+ let _ = ocx. deeply_normalize ( & cause, param_env, value. value ) ;
331
+
332
+ let diag = try_extract_error_from_fulfill_cx (
333
+ & ocx,
334
+ mbcx. mir_def_id ( ) ,
335
+ placeholder_region,
336
+ error_region,
337
+ ) ?
338
+ . with_dcx ( mbcx. dcx ( ) ) ;
339
+ Some ( diag)
340
+ }
341
+ }
342
+
288
343
struct AscribeUserTypeQuery < ' tcx > {
289
344
canonical_query : CanonicalTypeOpAscribeUserTypeGoal < ' tcx > ,
290
345
base_universe : ty:: UniverseIndex ,
0 commit comments