@@ -28,6 +28,7 @@ use crate::infer::outlives::env::OutlivesEnvironment;
28
28
use crate :: infer:: { InferCtxt , TyCtxtInferExt } ;
29
29
use crate :: traits:: error_reporting:: InferCtxtExt as _;
30
30
use crate :: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
31
+ use rustc_data_structures:: functor:: IdFunctor ;
31
32
use rustc_errors:: ErrorGuaranteed ;
32
33
use rustc_hir as hir;
33
34
use rustc_hir:: def_id:: DefId ;
@@ -219,6 +220,7 @@ fn do_normalize_predicates<'tcx>(
219
220
cause : ObligationCause < ' tcx > ,
220
221
elaborated_env : ty:: ParamEnv < ' tcx > ,
221
222
predicates : Vec < ty:: Predicate < ' tcx > > ,
223
+ outlives : bool ,
222
224
) -> Result < Vec < ty:: Predicate < ' tcx > > , ErrorGuaranteed > {
223
225
let span = cause. span ;
224
226
// FIXME. We should really... do something with these region
@@ -235,7 +237,15 @@ fn do_normalize_predicates<'tcx>(
235
237
// them here too, and we will remove this function when
236
238
// we move over to lazy normalization *anyway*.
237
239
tcx. infer_ctxt ( ) . ignoring_regions ( ) . enter ( |infcx| {
238
- let predicates = match fully_normalize ( & infcx, cause, elaborated_env, predicates) {
240
+ let predicates = match predicates. try_map_id ( |predicate| {
241
+ if outlives
242
+ != matches ! ( predicate. kind( ) . skip_binder( ) , ty:: PredicateKind :: TypeOutlives ( ..) )
243
+ {
244
+ Ok ( predicate)
245
+ } else {
246
+ fully_normalize ( & infcx, cause. clone ( ) , elaborated_env, predicate)
247
+ }
248
+ } ) {
239
249
Ok ( predicates) => predicates,
240
250
Err ( errors) => {
241
251
let reported = infcx. report_fulfillment_errors ( & errors, None , false ) ;
@@ -262,7 +272,15 @@ fn do_normalize_predicates<'tcx>(
262
272
) ;
263
273
}
264
274
265
- match infcx. fully_resolve ( predicates) {
275
+ match predicates. try_map_id ( |predicate| {
276
+ if outlives
277
+ != matches ! ( predicate. kind( ) . skip_binder( ) , ty:: PredicateKind :: TypeOutlives ( ..) )
278
+ {
279
+ Ok ( predicate)
280
+ } else {
281
+ infcx. fully_resolve ( predicate)
282
+ }
283
+ } ) {
266
284
Ok ( predicates) => Ok ( predicates) ,
267
285
Err ( fixup_err) => {
268
286
// If we encounter a fixup error, it means that some type
@@ -306,7 +324,7 @@ pub fn normalize_param_env_or_error<'tcx>(
306
324
// parameter environments once for every fn as it goes,
307
325
// and errors will get reported then; so outside of type inference we
308
326
// can be sure that no errors should occur.
309
- let mut predicates: Vec < _ > =
327
+ let predicates: Vec < _ > =
310
328
util:: elaborate_predicates ( tcx, unnormalized_env. caller_bounds ( ) . into_iter ( ) )
311
329
. map ( |obligation| obligation. predicate )
312
330
. collect ( ) ;
@@ -337,53 +355,39 @@ pub fn normalize_param_env_or_error<'tcx>(
337
355
//
338
356
// This works fairly well because trait matching does not actually care about param-env
339
357
// TypeOutlives predicates - these are normally used by regionck.
340
- let outlives_predicates: Vec < _ > = predicates
341
- . drain_filter ( |predicate| {
342
- matches ! ( predicate. kind( ) . skip_binder( ) , ty:: PredicateKind :: TypeOutlives ( ..) )
343
- } )
344
- . collect ( ) ;
345
358
346
- debug ! (
347
- "normalize_param_env_or_error: predicates=(non-outlives={:?}, outlives={:?})" ,
348
- predicates, outlives_predicates
349
- ) ;
350
- let Ok ( non_outlives_predicates) = do_normalize_predicates (
359
+ let Ok ( predicates) = do_normalize_predicates (
351
360
tcx,
352
361
cause. clone ( ) ,
353
362
elaborated_env,
354
363
predicates,
364
+ false ,
355
365
) else {
356
366
// An unnormalized env is better than nothing.
357
367
debug ! ( "normalize_param_env_or_error: errored resolving non-outlives predicates" ) ;
358
368
return elaborated_env;
359
369
} ;
360
370
361
- debug ! ( "normalize_param_env_or_error: non-outlives predicates={:?}" , non_outlives_predicates) ;
362
-
363
371
// Not sure whether it is better to include the unnormalized TypeOutlives predicates
364
372
// here. I believe they should not matter, because we are ignoring TypeOutlives param-env
365
373
// predicates here anyway. Keeping them here anyway because it seems safer.
366
- let outlives_env: Vec < _ > =
367
- non_outlives_predicates. iter ( ) . chain ( & outlives_predicates) . cloned ( ) . collect ( ) ;
368
374
let outlives_env = ty:: ParamEnv :: new (
369
- tcx. intern_predicates ( & outlives_env ) ,
375
+ tcx. intern_predicates ( & predicates ) ,
370
376
unnormalized_env. reveal ( ) ,
371
377
unnormalized_env. constness ( ) ,
372
378
) ;
373
- let Ok ( outlives_predicates ) = do_normalize_predicates (
379
+ let Ok ( predicates ) = do_normalize_predicates (
374
380
tcx,
375
381
cause,
376
382
outlives_env,
377
- outlives_predicates,
383
+ predicates,
384
+ true
378
385
) else {
379
386
// An unnormalized env is better than nothing.
380
387
debug ! ( "normalize_param_env_or_error: errored resolving outlives predicates" ) ;
381
388
return elaborated_env;
382
389
} ;
383
- debug ! ( "normalize_param_env_or_error: outlives predicates={:?}" , outlives_predicates) ;
384
390
385
- let mut predicates = non_outlives_predicates;
386
- predicates. extend ( outlives_predicates) ;
387
391
debug ! ( "normalize_param_env_or_error: final predicates={:?}" , predicates) ;
388
392
ty:: ParamEnv :: new (
389
393
tcx. intern_predicates ( & predicates) ,
0 commit comments