@@ -12,8 +12,8 @@ use infer::{RegionObligation, InferCtxt};
12
12
use mir:: interpret:: GlobalId ;
13
13
use ty:: { self , Ty , TypeFoldable , ToPolyTraitRef , ToPredicate } ;
14
14
use ty:: error:: ExpectedFound ;
15
- use rustc_data_structures:: obligation_forest:: { ObligationForest , Error } ;
16
- use rustc_data_structures:: obligation_forest:: { ForestObligation , ObligationProcessor } ;
15
+ use rustc_data_structures:: obligation_forest:: { Error , ForestObligation , ObligationForest } ;
16
+ use rustc_data_structures:: obligation_forest:: { ObligationProcessor , ProcessResult } ;
17
17
use std:: marker:: PhantomData ;
18
18
use hir:: def_id:: DefId ;
19
19
use middle:: const_val:: { ConstEvalErr , ErrKind } ;
@@ -263,16 +263,16 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
263
263
type Error = FulfillmentErrorCode < ' tcx > ;
264
264
265
265
/// Processes a predicate obligation and returns either:
266
- /// - `Ok(Some(v) )` if the predicate is true, presuming that `v` are also true
267
- /// - `Ok(None) ` if we don't have enough info to be sure
268
- /// - `Err ` if the predicate does not hold
266
+ /// - `Changed(v )` if the predicate is true, presuming that `v` are also true
267
+ /// - `Unchanged ` if we don't have enough info to be sure
268
+ /// - `Error(e) ` if the predicate does not hold
269
269
///
270
270
/// This is always inlined, despite its size, because it has a single
271
271
/// callsite and it is called *very* frequently.
272
272
#[ inline( always) ]
273
273
fn process_obligation ( & mut self ,
274
274
pending_obligation : & mut Self :: Obligation )
275
- -> Result < Option < Vec < Self :: Obligation > > , Self :: Error >
275
+ -> ProcessResult < Self :: Obligation , Self :: Error >
276
276
{
277
277
// if we were stalled on some unresolved variables, first check
278
278
// whether any of them have been resolved; if not, don't bother
@@ -286,7 +286,7 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
286
286
self . selcx. infcx( )
287
287
. resolve_type_vars_if_possible( & pending_obligation. obligation) ,
288
288
pending_obligation. stalled_on) ;
289
- return Ok ( None ) ;
289
+ return ProcessResult :: Unchanged ;
290
290
}
291
291
pending_obligation. stalled_on = vec ! [ ] ;
292
292
}
@@ -308,15 +308,15 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
308
308
if self . selcx . infcx ( ) . predicate_must_hold ( & obligation) {
309
309
debug ! ( "selecting trait `{:?}` at depth {} evaluated to holds" ,
310
310
data, obligation. recursion_depth) ;
311
- return Ok ( Some ( vec ! [ ] ) )
311
+ return ProcessResult :: Changed ( vec ! [ ] )
312
312
}
313
313
}
314
314
315
315
match self . selcx . select ( & trait_obligation) {
316
316
Ok ( Some ( vtable) ) => {
317
317
debug ! ( "selecting trait `{:?}` at depth {} yielded Ok(Some)" ,
318
318
data, obligation. recursion_depth) ;
319
- Ok ( Some ( mk_pending ( vtable. nested_obligations ( ) ) ) )
319
+ ProcessResult :: Changed ( mk_pending ( vtable. nested_obligations ( ) ) )
320
320
}
321
321
Ok ( None ) => {
322
322
debug ! ( "selecting trait `{:?}` at depth {} yielded Ok(None)" ,
@@ -342,21 +342,21 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
342
342
self . selcx. infcx( ) . resolve_type_vars_if_possible( obligation) ,
343
343
pending_obligation. stalled_on) ;
344
344
345
- Ok ( None )
345
+ ProcessResult :: Unchanged
346
346
}
347
347
Err ( selection_err) => {
348
348
info ! ( "selecting trait `{:?}` at depth {} yielded Err" ,
349
349
data, obligation. recursion_depth) ;
350
350
351
- Err ( CodeSelectionError ( selection_err) )
351
+ ProcessResult :: Error ( CodeSelectionError ( selection_err) )
352
352
}
353
353
}
354
354
}
355
355
356
356
ty:: Predicate :: RegionOutlives ( ref binder) => {
357
357
match self . selcx . infcx ( ) . region_outlives_predicate ( & obligation. cause , binder) {
358
- Ok ( ( ) ) => Ok ( Some ( Vec :: new ( ) ) ) ,
359
- Err ( _) => Err ( CodeSelectionError ( Unimplemented ) ) ,
358
+ Ok ( ( ) ) => ProcessResult :: Changed ( vec ! [ ] ) ,
359
+ Err ( _) => ProcessResult :: Error ( CodeSelectionError ( Unimplemented ) ) ,
360
360
}
361
361
}
362
362
@@ -373,7 +373,7 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
373
373
// If so, this obligation is an error (for now). Eventually we should be
374
374
// able to support additional cases here, like `for<'a> &'a str: 'a`.
375
375
None => {
376
- Err ( CodeSelectionError ( Unimplemented ) )
376
+ ProcessResult :: Error ( CodeSelectionError ( Unimplemented ) )
377
377
}
378
378
// Otherwise, we have something of the form
379
379
// `for<'a> T: 'a where 'a not in T`, which we can treat as
@@ -389,7 +389,7 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
389
389
cause : obligation. cause . clone ( ) ,
390
390
} ) ;
391
391
}
392
- Ok ( Some ( vec ! [ ] ) )
392
+ ProcessResult :: Changed ( vec ! [ ] )
393
393
}
394
394
}
395
395
}
@@ -404,7 +404,7 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
404
404
cause : obligation. cause . clone ( )
405
405
} ) ;
406
406
}
407
- Ok ( Some ( vec ! [ ] ) )
407
+ ProcessResult :: Changed ( vec ! [ ] )
408
408
}
409
409
}
410
410
}
@@ -416,32 +416,32 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
416
416
let tcx = self . selcx . tcx ( ) ;
417
417
pending_obligation. stalled_on =
418
418
trait_ref_type_vars ( self . selcx , data. to_poly_trait_ref ( tcx) ) ;
419
- Ok ( None )
419
+ ProcessResult :: Unchanged
420
420
}
421
- Ok ( Some ( os) ) => Ok ( Some ( mk_pending ( os) ) ) ,
422
- Err ( e) => Err ( CodeProjectionError ( e) )
421
+ Ok ( Some ( os) ) => ProcessResult :: Changed ( mk_pending ( os) ) ,
422
+ Err ( e) => ProcessResult :: Error ( CodeProjectionError ( e) )
423
423
}
424
424
}
425
425
426
426
ty:: Predicate :: ObjectSafe ( trait_def_id) => {
427
427
if !self . selcx . tcx ( ) . is_object_safe ( trait_def_id) {
428
- Err ( CodeSelectionError ( Unimplemented ) )
428
+ ProcessResult :: Error ( CodeSelectionError ( Unimplemented ) )
429
429
} else {
430
- Ok ( Some ( Vec :: new ( ) ) )
430
+ ProcessResult :: Changed ( vec ! [ ] )
431
431
}
432
432
}
433
433
434
434
ty:: Predicate :: ClosureKind ( closure_def_id, closure_substs, kind) => {
435
435
match self . selcx . infcx ( ) . closure_kind ( closure_def_id, closure_substs) {
436
436
Some ( closure_kind) => {
437
437
if closure_kind. extends ( kind) {
438
- Ok ( Some ( vec ! [ ] ) )
438
+ ProcessResult :: Changed ( vec ! [ ] )
439
439
} else {
440
- Err ( CodeSelectionError ( Unimplemented ) )
440
+ ProcessResult :: Error ( CodeSelectionError ( Unimplemented ) )
441
441
}
442
442
}
443
443
None => {
444
- Ok ( None )
444
+ ProcessResult :: Unchanged
445
445
}
446
446
}
447
447
}
@@ -453,9 +453,9 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
453
453
ty, obligation. cause . span ) {
454
454
None => {
455
455
pending_obligation. stalled_on = vec ! [ ty] ;
456
- Ok ( None )
456
+ ProcessResult :: Unchanged
457
457
}
458
- Some ( os) => Ok ( Some ( mk_pending ( os) ) )
458
+ Some ( os) => ProcessResult :: Changed ( mk_pending ( os) )
459
459
}
460
460
}
461
461
@@ -467,24 +467,25 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
467
467
// None means that both are unresolved.
468
468
pending_obligation. stalled_on = vec ! [ subtype. skip_binder( ) . a,
469
469
subtype. skip_binder( ) . b] ;
470
- Ok ( None )
470
+ ProcessResult :: Unchanged
471
471
}
472
472
Some ( Ok ( ok) ) => {
473
- Ok ( Some ( mk_pending ( ok. obligations ) ) )
473
+ ProcessResult :: Changed ( mk_pending ( ok. obligations ) )
474
474
}
475
475
Some ( Err ( err) ) => {
476
476
let expected_found = ExpectedFound :: new ( subtype. skip_binder ( ) . a_is_expected ,
477
477
subtype. skip_binder ( ) . a ,
478
478
subtype. skip_binder ( ) . b ) ;
479
- Err ( FulfillmentErrorCode :: CodeSubtypeError ( expected_found, err) )
479
+ ProcessResult :: Error (
480
+ FulfillmentErrorCode :: CodeSubtypeError ( expected_found, err) )
480
481
}
481
482
}
482
483
}
483
484
484
485
ty:: Predicate :: ConstEvaluatable ( def_id, substs) => {
485
486
match self . selcx . tcx ( ) . lift_to_global ( & obligation. param_env ) {
486
487
None => {
487
- Ok ( None )
488
+ ProcessResult :: Unchanged
488
489
}
489
490
Some ( param_env) => {
490
491
match self . selcx . tcx ( ) . lift_to_global ( & substs) {
@@ -502,19 +503,22 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
502
503
} ;
503
504
match self . selcx . tcx ( ) . at ( obligation. cause . span )
504
505
. const_eval ( param_env. and ( cid) ) {
505
- Ok ( _) => Ok ( Some ( vec ! [ ] ) ) ,
506
- Err ( err) => Err ( CodeSelectionError ( ConstEvalFailure ( err) ) )
506
+ Ok ( _) => ProcessResult :: Changed ( vec ! [ ] ) ,
507
+ Err ( err) => ProcessResult :: Error (
508
+ CodeSelectionError ( ConstEvalFailure ( err) ) )
507
509
}
508
510
} else {
509
- Err ( CodeSelectionError ( ConstEvalFailure ( ConstEvalErr {
510
- span : obligation. cause . span ,
511
- kind : ErrKind :: CouldNotResolve . into ( ) ,
512
- } ) ) )
511
+ ProcessResult :: Error (
512
+ CodeSelectionError ( ConstEvalFailure ( ConstEvalErr {
513
+ span : obligation. cause . span ,
514
+ kind : ErrKind :: CouldNotResolve . into ( ) ,
515
+ } ) )
516
+ )
513
517
}
514
518
} ,
515
519
None => {
516
520
pending_obligation. stalled_on = substs. types ( ) . collect ( ) ;
517
- Ok ( None )
521
+ ProcessResult :: Unchanged
518
522
}
519
523
}
520
524
}
0 commit comments