@@ -14,8 +14,7 @@ use rustc::session::config::nightly_options;
14
14
use rustc:: ty:: subst:: { InternalSubsts , Subst , SubstsRef } ;
15
15
use rustc:: ty:: GenericParamDefKind ;
16
16
use rustc:: ty:: {
17
- self , ParamEnvAnd , ToPolyTraitRef , ToPredicate , TraitRef , Ty , TyCtxt , TypeFoldable ,
18
- WithConstness ,
17
+ self , ParamEnvAnd , ToPolyTraitRef , ToPredicate , Ty , TyCtxt , TypeFoldable , WithConstness ,
19
18
} ;
20
19
use rustc_data_structures:: fx:: FxHashSet ;
21
20
use rustc_data_structures:: sync:: Lrc ;
@@ -78,7 +77,7 @@ struct ProbeContext<'a, 'tcx> {
78
77
79
78
/// Collects near misses when trait bounds for type parameters are unsatisfied and is only used
80
79
/// for error reporting
81
- unsatisfied_predicates : Vec < TraitRef < ' tcx > > ,
80
+ unsatisfied_predicates : Vec < ty :: Predicate < ' tcx > > ,
82
81
83
82
is_suggestion : IsSuggestion ,
84
83
}
@@ -1224,7 +1223,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1224
1223
& self ,
1225
1224
self_ty : Ty < ' tcx > ,
1226
1225
probes : ProbesIter ,
1227
- possibly_unsatisfied_predicates : & mut Vec < TraitRef < ' tcx > > ,
1226
+ possibly_unsatisfied_predicates : & mut Vec < ty :: Predicate < ' tcx > > ,
1228
1227
unstable_candidates : Option < & mut Vec < ( & ' b Candidate < ' tcx > , Symbol ) > > ,
1229
1228
) -> Option < PickResult < ' tcx > >
1230
1229
where
@@ -1343,7 +1342,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1343
1342
& self ,
1344
1343
self_ty : Ty < ' tcx > ,
1345
1344
probe : & Candidate < ' tcx > ,
1346
- possibly_unsatisfied_predicates : & mut Vec < TraitRef < ' tcx > > ,
1345
+ possibly_unsatisfied_predicates : & mut Vec < ty :: Predicate < ' tcx > > ,
1347
1346
) -> ProbeResult {
1348
1347
debug ! ( "consider_probe: self_ty={:?} probe={:?}" , self_ty, probe) ;
1349
1348
@@ -1398,47 +1397,40 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1398
1397
let predicate = trait_ref. without_const ( ) . to_predicate ( ) ;
1399
1398
let obligation = traits:: Obligation :: new ( cause, self . param_env , predicate) ;
1400
1399
if !self . predicate_may_hold ( & obligation) {
1401
- if self . probe ( |_| self . select_trait_candidate ( trait_ref) . is_err ( ) ) {
1400
+ if self . probe ( |_| {
1401
+ match self . select_trait_candidate ( trait_ref) {
1402
+ Err ( _) => return true ,
1403
+ Ok ( Some ( vtable) )
1404
+ if !vtable. borrow_nested_obligations ( ) . is_empty ( ) =>
1405
+ {
1406
+ for obligation in vtable. borrow_nested_obligations ( ) {
1407
+ // Determine exactly which obligation wasn't met, so
1408
+ // that we can give more context in the error.
1409
+ if !self . predicate_may_hold ( & obligation) {
1410
+ result = ProbeResult :: NoMatch ;
1411
+ let o = self . resolve_vars_if_possible ( obligation) ;
1412
+ possibly_unsatisfied_predicates. push ( o. predicate ) ;
1413
+ }
1414
+ }
1415
+ }
1416
+ _ => {
1417
+ // Some nested subobligation of this predicate
1418
+ // failed.
1419
+ //
1420
+ // FIXME: try to find the exact nested subobligation
1421
+ // and point at it rather than reporting the entire
1422
+ // trait-ref?
1423
+ result = ProbeResult :: NoMatch ;
1424
+ let predicate = self . resolve_vars_if_possible ( & predicate) ;
1425
+ possibly_unsatisfied_predicates. push ( predicate) ;
1426
+ }
1427
+ }
1428
+ false
1429
+ } ) {
1402
1430
// This candidate's primary obligation doesn't even
1403
1431
// select - don't bother registering anything in
1404
1432
// `potentially_unsatisfied_predicates`.
1405
1433
return ProbeResult :: NoMatch ;
1406
- } else {
1407
- self . probe ( |_| {
1408
- match self . select_trait_candidate ( trait_ref) {
1409
- Ok ( Some ( traits:: VtableImpl ( traits:: VtableImplData {
1410
- nested,
1411
- ..
1412
- } ) ) ) if !nested. is_empty ( ) => {
1413
- for obligation in nested {
1414
- // Determine exactly which obligation wasn't met, so
1415
- // that we can give more context in the error.
1416
- if !self . predicate_may_hold ( & obligation) {
1417
- result = ProbeResult :: NoMatch ;
1418
- if let Some ( poly_trait_ref) =
1419
- obligation. predicate . to_opt_poly_trait_ref ( )
1420
- {
1421
- let trait_ref = poly_trait_ref. clone ( ) ;
1422
- let trait_ref = trait_ref. skip_binder ( ) ;
1423
- possibly_unsatisfied_predicates
1424
- . push ( * trait_ref) ;
1425
- }
1426
- }
1427
- }
1428
- }
1429
- _ => {
1430
- // Some nested subobligation of this predicate
1431
- // failed.
1432
- //
1433
- // FIXME: try to find the exact nested subobligation
1434
- // and point at it rather than reporting the entire
1435
- // trait-ref?
1436
- result = ProbeResult :: NoMatch ;
1437
- let trait_ref = self . resolve_vars_if_possible ( & trait_ref) ;
1438
- possibly_unsatisfied_predicates. push ( trait_ref) ;
1439
- }
1440
- }
1441
- } ) ;
1442
1434
}
1443
1435
}
1444
1436
vec ! [ ]
@@ -1455,9 +1447,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1455
1447
let o = self . resolve_vars_if_possible ( & o) ;
1456
1448
if !self . predicate_may_hold ( & o) {
1457
1449
result = ProbeResult :: NoMatch ;
1458
- if let & ty:: Predicate :: Trait ( ref pred, _) = & o. predicate {
1459
- possibly_unsatisfied_predicates. push ( pred. skip_binder ( ) . trait_ref ) ;
1460
- }
1450
+ possibly_unsatisfied_predicates. push ( o. predicate ) ;
1461
1451
}
1462
1452
}
1463
1453
0 commit comments