@@ -6,7 +6,7 @@ use rustc_errors::ErrorReported;
6
6
use rustc_infer:: traits:: { TraitEngine , TraitEngineExt as _} ;
7
7
use rustc_middle:: mir:: interpret:: ErrorHandled ;
8
8
use rustc_middle:: ty:: error:: ExpectedFound ;
9
- use rustc_middle:: ty:: { self , Const , ToPolyTraitRef , Ty , TypeFoldable } ;
9
+ use rustc_middle:: ty:: { self , Binder , Const , ToPredicate , Ty , TypeFoldable } ;
10
10
use std:: marker:: PhantomData ;
11
11
12
12
use super :: project;
@@ -317,9 +317,15 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
317
317
318
318
let infcx = self . selcx . infcx ( ) ;
319
319
320
- match obligation. predicate . kind ( ) {
321
- ty:: PredicateKind :: Trait ( ref data, _) => {
322
- let trait_obligation = obligation. with ( * data) ;
320
+ match obligation. predicate . kint ( infcx. tcx ) {
321
+ ty:: PredicateKint :: ForAll ( binder) => {
322
+ let ( pred, _) = infcx. replace_bound_vars_with_placeholders ( binder) ;
323
+ ProcessResult :: Changed ( mk_pending ( vec ! [
324
+ obligation. with( pred. to_predicate( infcx. tcx) ) ,
325
+ ] ) )
326
+ }
327
+ ty:: PredicateKint :: Trait ( ref data, _) => {
328
+ let trait_obligation = obligation. with ( Binder :: dummy ( * data) ) ;
323
329
324
330
if obligation. predicate . is_global ( ) {
325
331
// no type variables present, can use evaluation for better caching.
@@ -352,7 +358,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
352
358
// trait selection is because we don't have enough
353
359
// information about the types in the trait.
354
360
pending_obligation. stalled_on =
355
- trait_ref_infer_vars ( self . selcx , data. to_poly_trait_ref ( ) ) ;
361
+ trait_ref_infer_vars ( self . selcx , data. trait_ref ) ;
356
362
357
363
debug ! (
358
364
"process_predicate: pending obligation {:?} now stalled on {:?}" ,
@@ -373,80 +379,48 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
373
379
}
374
380
}
375
381
376
- & ty:: PredicateKind :: RegionOutlives ( binder ) => {
377
- match infcx. region_outlives_predicate ( & obligation. cause , binder ) {
382
+ & ty:: PredicateKint :: RegionOutlives ( data ) => {
383
+ match infcx. region_outlives_predicate ( & obligation. cause , Binder :: dummy ( data ) ) {
378
384
Ok ( ( ) ) => ProcessResult :: Changed ( vec ! [ ] ) ,
379
385
Err ( _) => ProcessResult :: Error ( CodeSelectionError ( Unimplemented ) ) ,
380
386
}
381
387
}
382
388
383
- ty:: PredicateKind :: TypeOutlives ( ref binder) => {
384
- // Check if there are higher-ranked vars.
385
- match binder. no_bound_vars ( ) {
386
- // If there are, inspect the underlying type further.
387
- None => {
388
- // Convert from `Binder<OutlivesPredicate<Ty, Region>>` to `Binder<Ty>`.
389
- let binder = binder. map_bound_ref ( |pred| pred. 0 ) ;
390
-
391
- // Check if the type has any bound vars.
392
- match binder. no_bound_vars ( ) {
393
- // If so, this obligation is an error (for now). Eventually we should be
394
- // able to support additional cases here, like `for<'a> &'a str: 'a`.
395
- // NOTE: this is duplicate-implemented between here and fulfillment.
396
- None => ProcessResult :: Error ( CodeSelectionError ( Unimplemented ) ) ,
397
- // Otherwise, we have something of the form
398
- // `for<'a> T: 'a where 'a not in T`, which we can treat as
399
- // `T: 'static`.
400
- Some ( t_a) => {
401
- let r_static = self . selcx . tcx ( ) . lifetimes . re_static ;
402
- if self . register_region_obligations {
403
- self . selcx . infcx ( ) . register_region_obligation_with_cause (
404
- t_a,
405
- r_static,
406
- & obligation. cause ,
407
- ) ;
408
- }
409
- ProcessResult :: Changed ( vec ! [ ] )
410
- }
411
- }
412
- }
413
- // If there aren't, register the obligation.
414
- Some ( ty:: OutlivesPredicate ( t_a, r_b) ) => {
415
- if self . register_region_obligations {
416
- self . selcx . infcx ( ) . register_region_obligation_with_cause (
417
- t_a,
418
- r_b,
419
- & obligation. cause ,
420
- ) ;
421
- }
422
- ProcessResult :: Changed ( vec ! [ ] )
423
- }
389
+ ty:: PredicateKint :: TypeOutlives ( ty:: OutlivesPredicate ( t_a, r_b) ) => {
390
+ if self . register_region_obligations {
391
+ self . selcx . infcx ( ) . register_region_obligation_with_cause (
392
+ t_a,
393
+ r_b,
394
+ & obligation. cause ,
395
+ ) ;
424
396
}
397
+ ProcessResult :: Changed ( vec ! [ ] )
425
398
}
426
399
427
- ty:: PredicateKind :: Projection ( ref data) => {
428
- let project_obligation = obligation. with ( * data) ;
400
+ ty:: PredicateKint :: Projection ( ref data) => {
401
+ let project_obligation = obligation. with ( Binder :: dummy ( * data) ) ;
429
402
match project:: poly_project_and_unify_type ( self . selcx , & project_obligation) {
430
403
Ok ( None ) => {
431
- let tcx = self . selcx . tcx ( ) ;
432
- pending_obligation. stalled_on =
433
- trait_ref_infer_vars ( self . selcx , data. to_poly_trait_ref ( tcx) ) ;
404
+ pending_obligation. stalled_on = trait_ref_infer_vars (
405
+ self . selcx ,
406
+ data. projection_ty . trait_ref ( infcx. tcx ) ,
407
+ ) ;
434
408
ProcessResult :: Unchanged
435
409
}
436
410
Ok ( Some ( os) ) => ProcessResult :: Changed ( mk_pending ( os) ) ,
437
411
Err ( e) => ProcessResult :: Error ( CodeProjectionError ( e) ) ,
438
412
}
439
413
}
440
414
441
- & ty:: PredicateKind :: ObjectSafe ( trait_def_id) => {
415
+ & ty:: PredicateKint :: ObjectSafe ( trait_def_id) => {
442
416
if !self . selcx . tcx ( ) . is_object_safe ( trait_def_id) {
443
417
ProcessResult :: Error ( CodeSelectionError ( Unimplemented ) )
444
418
} else {
445
419
ProcessResult :: Changed ( vec ! [ ] )
446
420
}
447
421
}
448
422
449
- & ty:: PredicateKind :: ClosureKind ( _, closure_substs, kind) => {
423
+ & ty:: PredicateKint :: ClosureKind ( _, closure_substs, kind) => {
450
424
match self . selcx . infcx ( ) . closure_kind ( closure_substs) {
451
425
Some ( closure_kind) => {
452
426
if closure_kind. extends ( kind) {
@@ -459,7 +433,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
459
433
}
460
434
}
461
435
462
- & ty:: PredicateKind :: WellFormed ( arg) => {
436
+ & ty:: PredicateKint :: WellFormed ( arg) => {
463
437
match wf:: obligations (
464
438
self . selcx . infcx ( ) ,
465
439
obligation. param_env ,
@@ -476,27 +450,24 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
476
450
}
477
451
}
478
452
479
- & ty:: PredicateKind :: Subtype ( subtype) => {
453
+ & ty:: PredicateKint :: Subtype ( subtype) => {
480
454
match self . selcx . infcx ( ) . subtype_predicate (
481
455
& obligation. cause ,
482
456
obligation. param_env ,
483
- subtype,
457
+ Binder :: dummy ( subtype) ,
484
458
) {
485
459
None => {
486
460
// None means that both are unresolved.
487
461
pending_obligation. stalled_on = vec ! [
488
- TyOrConstInferVar :: maybe_from_ty( subtype. skip_binder ( ) . a) . unwrap( ) ,
489
- TyOrConstInferVar :: maybe_from_ty( subtype. skip_binder ( ) . b) . unwrap( ) ,
462
+ TyOrConstInferVar :: maybe_from_ty( subtype. a) . unwrap( ) ,
463
+ TyOrConstInferVar :: maybe_from_ty( subtype. b) . unwrap( ) ,
490
464
] ;
491
465
ProcessResult :: Unchanged
492
466
}
493
467
Some ( Ok ( ok) ) => ProcessResult :: Changed ( mk_pending ( ok. obligations ) ) ,
494
468
Some ( Err ( err) ) => {
495
- let expected_found = ExpectedFound :: new (
496
- subtype. skip_binder ( ) . a_is_expected ,
497
- subtype. skip_binder ( ) . a ,
498
- subtype. skip_binder ( ) . b ,
499
- ) ;
469
+ let expected_found =
470
+ ExpectedFound :: new ( subtype. a_is_expected , subtype. a , subtype. b ) ;
500
471
ProcessResult :: Error ( FulfillmentErrorCode :: CodeSubtypeError (
501
472
expected_found,
502
473
err,
@@ -505,7 +476,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
505
476
}
506
477
}
507
478
508
- & ty:: PredicateKind :: ConstEvaluatable ( def_id, substs) => {
479
+ & ty:: PredicateKint :: ConstEvaluatable ( def_id, substs) => {
509
480
match self . selcx . infcx ( ) . const_eval_resolve (
510
481
obligation. param_env ,
511
482
def_id,
@@ -518,7 +489,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
518
489
}
519
490
}
520
491
521
- ty:: PredicateKind :: ConstEquate ( c1, c2) => {
492
+ ty:: PredicateKint :: ConstEquate ( c1, c2) => {
522
493
debug ! ( "equating consts: c1={:?} c2={:?}" , c1, c2) ;
523
494
524
495
let stalled_on = & mut pending_obligation. stalled_on ;
@@ -601,12 +572,11 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
601
572
/// Returns the set of inference variables contained in a trait ref.
602
573
fn trait_ref_infer_vars < ' a , ' tcx > (
603
574
selcx : & mut SelectionContext < ' a , ' tcx > ,
604
- trait_ref : ty:: PolyTraitRef < ' tcx > ,
575
+ trait_ref : ty:: TraitRef < ' tcx > ,
605
576
) -> Vec < TyOrConstInferVar < ' tcx > > {
606
577
selcx
607
578
. infcx ( )
608
579
. resolve_vars_if_possible ( & trait_ref)
609
- . skip_binder ( ) // ok b/c this check doesn't care about regions
610
580
. substs
611
581
. iter ( )
612
582
// FIXME(eddyb) try using `skip_current_subtree` to skip everything that
0 commit comments