@@ -8,8 +8,11 @@ use rustc_infer::infer::region_constraints::GenericKind;
8
8
use rustc_infer:: infer:: InferCtxt ;
9
9
use rustc_middle:: mir:: ConstraintCategory ;
10
10
use rustc_middle:: traits:: query:: OutlivesBound ;
11
+ use rustc_middle:: traits:: ObligationCause ;
11
12
use rustc_middle:: ty:: { self , RegionVid , Ty , TypeVisitableExt } ;
12
- use rustc_span:: { ErrorGuaranteed , Span , DUMMY_SP } ;
13
+ use rustc_span:: { ErrorGuaranteed , DUMMY_SP } ;
14
+ use rustc_trait_selection:: solve:: deeply_normalize_with_skipped_universes;
15
+ use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt ;
13
16
use rustc_trait_selection:: traits:: query:: type_op:: { self , TypeOp } ;
14
17
use std:: rc:: Rc ;
15
18
use type_op:: TypeOpOutput ;
@@ -52,15 +55,13 @@ pub(crate) struct CreateResult<'tcx> {
52
55
pub ( crate ) fn create < ' tcx > (
53
56
infcx : & InferCtxt < ' tcx > ,
54
57
param_env : ty:: ParamEnv < ' tcx > ,
55
- known_type_outlives_obligations : & ' tcx [ ty:: PolyTypeOutlivesPredicate < ' tcx > ] ,
56
58
implicit_region_bound : ty:: Region < ' tcx > ,
57
59
universal_regions : & Rc < UniversalRegions < ' tcx > > ,
58
60
constraints : & mut MirTypeckRegionConstraints < ' tcx > ,
59
61
) -> CreateResult < ' tcx > {
60
62
UniversalRegionRelationsBuilder {
61
63
infcx,
62
64
param_env,
63
- known_type_outlives_obligations,
64
65
implicit_region_bound,
65
66
constraints,
66
67
universal_regions : universal_regions. clone ( ) ,
@@ -178,7 +179,6 @@ impl UniversalRegionRelations<'_> {
178
179
struct UniversalRegionRelationsBuilder < ' this , ' tcx > {
179
180
infcx : & ' this InferCtxt < ' tcx > ,
180
181
param_env : ty:: ParamEnv < ' tcx > ,
181
- known_type_outlives_obligations : & ' tcx [ ty:: PolyTypeOutlivesPredicate < ' tcx > ] ,
182
182
universal_regions : Rc < UniversalRegions < ' tcx > > ,
183
183
implicit_region_bound : ty:: Region < ' tcx > ,
184
184
constraints : & ' this mut MirTypeckRegionConstraints < ' tcx > ,
@@ -222,6 +222,35 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
222
222
self . relate_universal_regions ( fr, fr_fn_body) ;
223
223
}
224
224
225
+ // Normalize the assumptions we use to borrowck the program.
226
+ let mut constraints = vec ! [ ] ;
227
+ let mut known_type_outlives_obligations = vec ! [ ] ;
228
+ for bound in param_env. caller_bounds ( ) {
229
+ let Some ( outlives) = bound. as_type_outlives_clause ( ) else { continue } ;
230
+ let ty:: OutlivesPredicate ( mut ty, region) = outlives. skip_binder ( ) ;
231
+
232
+ // In the new solver, normalize the type-outlives obligation assumptions.
233
+ if self . infcx . next_trait_solver ( ) {
234
+ match deeply_normalize_with_skipped_universes (
235
+ self . infcx . at ( & ObligationCause :: misc ( span, defining_ty_def_id) , self . param_env ) ,
236
+ ty,
237
+ vec ! [ None ; ty. outer_exclusive_binder( ) . as_usize( ) ] ,
238
+ ) {
239
+ Ok ( normalized_ty) => {
240
+ ty = normalized_ty;
241
+ }
242
+ Err ( e) => {
243
+ self . infcx . err_ctxt ( ) . report_fulfillment_errors ( e) ;
244
+ }
245
+ }
246
+ }
247
+
248
+ known_type_outlives_obligations
249
+ . push ( outlives. rebind ( ty:: OutlivesPredicate ( ty, region) ) ) ;
250
+ }
251
+ let known_type_outlives_obligations =
252
+ self . infcx . tcx . arena . alloc_slice ( & known_type_outlives_obligations) ;
253
+
225
254
let unnormalized_input_output_tys = self
226
255
. universal_regions
227
256
. unnormalized_input_tys
@@ -239,7 +268,6 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
239
268
// the `relations` is built.
240
269
let mut normalized_inputs_and_output =
241
270
Vec :: with_capacity ( self . universal_regions . unnormalized_input_tys . len ( ) + 1 ) ;
242
- let mut constraints = vec ! [ ] ;
243
271
for ty in unnormalized_input_output_tys {
244
272
debug ! ( "build: input_or_output={:?}" , ty) ;
245
273
// We add implied bounds from both the unnormalized and normalized ty.
@@ -304,7 +332,19 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
304
332
}
305
333
306
334
for c in constraints {
307
- self . push_region_constraints ( c, span) ;
335
+ constraint_conversion:: ConstraintConversion :: new (
336
+ self . infcx ,
337
+ & self . universal_regions ,
338
+ & self . region_bound_pairs ,
339
+ self . implicit_region_bound ,
340
+ param_env,
341
+ known_type_outlives_obligations,
342
+ Locations :: All ( span) ,
343
+ span,
344
+ ConstraintCategory :: Internal ,
345
+ self . constraints ,
346
+ )
347
+ . convert_all ( c) ;
308
348
}
309
349
310
350
CreateResult {
@@ -313,30 +353,12 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
313
353
outlives : self . outlives . freeze ( ) ,
314
354
inverse_outlives : self . inverse_outlives . freeze ( ) ,
315
355
} ) ,
316
- known_type_outlives_obligations : self . known_type_outlives_obligations ,
356
+ known_type_outlives_obligations,
317
357
region_bound_pairs : self . region_bound_pairs ,
318
358
normalized_inputs_and_output,
319
359
}
320
360
}
321
361
322
- #[ instrument( skip( self , data) , level = "debug" ) ]
323
- fn push_region_constraints ( & mut self , data : & QueryRegionConstraints < ' tcx > , span : Span ) {
324
- debug ! ( "constraints generated: {:#?}" , data) ;
325
-
326
- constraint_conversion:: ConstraintConversion :: new (
327
- self . infcx ,
328
- & self . universal_regions ,
329
- & self . region_bound_pairs ,
330
- self . implicit_region_bound ,
331
- self . known_type_outlives_obligations ,
332
- Locations :: All ( span) ,
333
- span,
334
- ConstraintCategory :: Internal ,
335
- self . constraints ,
336
- )
337
- . convert_all ( data) ;
338
- }
339
-
340
362
/// Update the type of a single local, which should represent
341
363
/// either the return type of the MIR or one of its arguments. At
342
364
/// the same time, compute and add any implied bounds that come
0 commit comments