@@ -194,13 +194,12 @@ enum SelectionCandidate<'tcx> {
194
194
ProjectionCandidate ,
195
195
196
196
/// Implementation of a `Fn`-family trait by one of the anonymous types
197
- /// generated for a `||` expression. The ty::ClosureKind informs the
198
- /// confirmation step what ClosureKind obligation to emit.
199
- ClosureCandidate ( /* closure */ DefId , ty:: ClosureSubsts < ' tcx > , ty:: ClosureKind ) ,
197
+ /// generated for a `||` expression.
198
+ ClosureCandidate ,
200
199
201
200
/// Implementation of a `Generator` trait by one of the anonymous types
202
201
/// generated for a generator.
203
- GeneratorCandidate ( /* function / closure */ DefId , ty :: ClosureSubsts < ' tcx > ) ,
202
+ GeneratorCandidate ,
204
203
205
204
/// Implementation of a `Fn`-family trait by one of the anonymous
206
205
/// types generated for a fn pointer type (e.g., `fn(int)->int`)
@@ -229,20 +228,12 @@ impl<'a, 'tcx> ty::Lift<'tcx> for SelectionCandidate<'a> {
229
228
ObjectCandidate => ObjectCandidate ,
230
229
BuiltinObjectCandidate => BuiltinObjectCandidate ,
231
230
BuiltinUnsizeCandidate => BuiltinUnsizeCandidate ,
231
+ ClosureCandidate => ClosureCandidate ,
232
+ GeneratorCandidate => GeneratorCandidate ,
232
233
233
234
ParamCandidate ( ref trait_ref) => {
234
235
return tcx. lift ( trait_ref) . map ( ParamCandidate ) ;
235
236
}
236
- GeneratorCandidate ( def_id, ref substs) => {
237
- return tcx. lift ( substs) . map ( |substs| {
238
- GeneratorCandidate ( def_id, substs)
239
- } ) ;
240
- }
241
- ClosureCandidate ( def_id, ref substs, kind) => {
242
- return tcx. lift ( substs) . map ( |substs| {
243
- ClosureCandidate ( def_id, substs, kind)
244
- } ) ;
245
- }
246
237
} )
247
238
}
248
239
}
@@ -1471,23 +1462,22 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1471
1462
// touch bound regions, they just capture the in-scope
1472
1463
// type/region parameters
1473
1464
let self_ty = * obligation. self_ty ( ) . skip_binder ( ) ;
1474
- let ( closure_def_id, substs) = match self_ty. sty {
1475
- ty:: TyGenerator ( id, substs, _) => ( id, substs) ,
1465
+ match self_ty. sty {
1466
+ ty:: TyGenerator ( ..) => {
1467
+ debug ! ( "assemble_generator_candidates: self_ty={:?} obligation={:?}" ,
1468
+ self_ty,
1469
+ obligation) ;
1470
+
1471
+ candidates. vec . push ( GeneratorCandidate ) ;
1472
+ Ok ( ( ) )
1473
+ }
1476
1474
ty:: TyInfer ( ty:: TyVar ( _) ) => {
1477
1475
debug ! ( "assemble_generator_candidates: ambiguous self-type" ) ;
1478
1476
candidates. ambiguous = true ;
1479
1477
return Ok ( ( ) ) ;
1480
1478
}
1481
1479
_ => { return Ok ( ( ) ) ; }
1482
- } ;
1483
-
1484
- debug ! ( "assemble_generator_candidates: self_ty={:?} obligation={:?}" ,
1485
- self_ty,
1486
- obligation) ;
1487
-
1488
- candidates. vec . push ( GeneratorCandidate ( closure_def_id, substs) ) ;
1489
-
1490
- Ok ( ( ) )
1480
+ }
1491
1481
}
1492
1482
1493
1483
/// Check for the artificial impl that the compiler will create for an obligation like `X :
@@ -1509,36 +1499,31 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1509
1499
// ok to skip binder because the substs on closure types never
1510
1500
// touch bound regions, they just capture the in-scope
1511
1501
// type/region parameters
1512
- let self_ty = * obligation. self_ty ( ) . skip_binder ( ) ;
1513
- let ( closure_def_id, substs) = match self_ty. sty {
1514
- ty:: TyClosure ( id, substs) => ( id, substs) ,
1502
+ match obligation. self_ty ( ) . skip_binder ( ) . sty {
1503
+ ty:: TyClosure ( closure_def_id, _) => {
1504
+ debug ! ( "assemble_unboxed_candidates: kind={:?} obligation={:?}" ,
1505
+ kind, obligation) ;
1506
+ match self . infcx . closure_kind ( closure_def_id) {
1507
+ Some ( closure_kind) => {
1508
+ debug ! ( "assemble_unboxed_candidates: closure_kind = {:?}" , closure_kind) ;
1509
+ if closure_kind. extends ( kind) {
1510
+ candidates. vec . push ( ClosureCandidate ) ;
1511
+ }
1512
+ }
1513
+ None => {
1514
+ debug ! ( "assemble_unboxed_candidates: closure_kind not yet known" ) ;
1515
+ candidates. vec . push ( ClosureCandidate ) ;
1516
+ }
1517
+ } ;
1518
+ Ok ( ( ) )
1519
+ }
1515
1520
ty:: TyInfer ( ty:: TyVar ( _) ) => {
1516
1521
debug ! ( "assemble_unboxed_closure_candidates: ambiguous self-type" ) ;
1517
1522
candidates. ambiguous = true ;
1518
1523
return Ok ( ( ) ) ;
1519
1524
}
1520
1525
_ => { return Ok ( ( ) ) ; }
1521
- } ;
1522
-
1523
- debug ! ( "assemble_unboxed_candidates: self_ty={:?} kind={:?} obligation={:?}" ,
1524
- self_ty,
1525
- kind,
1526
- obligation) ;
1527
-
1528
- match self . infcx . closure_kind ( closure_def_id) {
1529
- Some ( closure_kind) => {
1530
- debug ! ( "assemble_unboxed_candidates: closure_kind = {:?}" , closure_kind) ;
1531
- if closure_kind. extends ( kind) {
1532
- candidates. vec . push ( ClosureCandidate ( closure_def_id, substs, kind) ) ;
1533
- }
1534
- }
1535
- None => {
1536
- debug ! ( "assemble_unboxed_candidates: closure_kind not yet known" ) ;
1537
- candidates. vec . push ( ClosureCandidate ( closure_def_id, substs, kind) ) ;
1538
- }
1539
1526
}
1540
-
1541
- Ok ( ( ) )
1542
1527
}
1543
1528
1544
1529
/// Implement one of the `Fn()` family for a fn pointer.
@@ -1855,8 +1840,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1855
1840
when there are other valid candidates") ;
1856
1841
}
1857
1842
ImplCandidate ( ..) |
1858
- ClosureCandidate ( .. ) |
1859
- GeneratorCandidate ( .. ) |
1843
+ ClosureCandidate |
1844
+ GeneratorCandidate |
1860
1845
FnPointerCandidate |
1861
1846
BuiltinObjectCandidate |
1862
1847
BuiltinUnsizeCandidate |
@@ -2198,15 +2183,13 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2198
2183
Ok ( VtableImpl ( self . confirm_impl_candidate ( obligation, impl_def_id) ) )
2199
2184
}
2200
2185
2201
- ClosureCandidate ( closure_def_id, substs, kind) => {
2202
- let vtable_closure =
2203
- self . confirm_closure_candidate ( obligation, closure_def_id, substs, kind) ?;
2186
+ ClosureCandidate => {
2187
+ let vtable_closure = self . confirm_closure_candidate ( obligation) ?;
2204
2188
Ok ( VtableClosure ( vtable_closure) )
2205
2189
}
2206
2190
2207
- GeneratorCandidate ( closure_def_id, substs) => {
2208
- let vtable_generator =
2209
- self . confirm_generator_candidate ( obligation, closure_def_id, substs) ?;
2191
+ GeneratorCandidate => {
2192
+ let vtable_generator = self . confirm_generator_candidate ( obligation) ?;
2210
2193
Ok ( VtableGenerator ( vtable_generator) )
2211
2194
}
2212
2195
@@ -2543,21 +2526,34 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2543
2526
}
2544
2527
2545
2528
fn confirm_generator_candidate ( & mut self ,
2546
- obligation : & TraitObligation < ' tcx > ,
2547
- closure_def_id : DefId ,
2548
- substs : ty:: ClosureSubsts < ' tcx > )
2549
- -> Result < VtableGeneratorData < ' tcx , PredicateObligation < ' tcx > > ,
2529
+ obligation : & TraitObligation < ' tcx > )
2530
+ -> Result < VtableGeneratorData < ' tcx , PredicateObligation < ' tcx > > ,
2550
2531
SelectionError < ' tcx > >
2551
2532
{
2533
+ // ok to skip binder because the substs on generator types never
2534
+ // touch bound regions, they just capture the in-scope
2535
+ // type/region parameters
2536
+ let self_ty = self . infcx . shallow_resolve ( obligation. self_ty ( ) . skip_binder ( ) ) ;
2537
+ let ( closure_def_id, substs) = match self_ty. sty {
2538
+ ty:: TyGenerator ( id, substs, _) => ( id, substs) ,
2539
+ _ => bug ! ( "closure candidate for non-closure {:?}" , obligation)
2540
+ } ;
2541
+
2552
2542
debug ! ( "confirm_generator_candidate({:?},{:?},{:?})" ,
2553
2543
obligation,
2554
2544
closure_def_id,
2555
2545
substs) ;
2556
2546
2547
+ let trait_ref =
2548
+ self . generator_trait_ref_unnormalized ( obligation, closure_def_id, substs) ;
2557
2549
let Normalized {
2558
2550
value : trait_ref,
2559
2551
obligations
2560
- } = self . generator_trait_ref ( obligation, closure_def_id, substs) ;
2552
+ } = normalize_with_depth ( self ,
2553
+ obligation. param_env ,
2554
+ obligation. cause . clone ( ) ,
2555
+ obligation. recursion_depth +1 ,
2556
+ & trait_ref) ;
2561
2557
2562
2558
debug ! ( "confirm_generator_candidate(closure_def_id={:?}, trait_ref={:?}, obligations={:?})" ,
2563
2559
closure_def_id,
@@ -2577,22 +2573,36 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2577
2573
}
2578
2574
2579
2575
fn confirm_closure_candidate ( & mut self ,
2580
- obligation : & TraitObligation < ' tcx > ,
2581
- closure_def_id : DefId ,
2582
- substs : ty:: ClosureSubsts < ' tcx > ,
2583
- kind : ty:: ClosureKind )
2576
+ obligation : & TraitObligation < ' tcx > )
2584
2577
-> Result < VtableClosureData < ' tcx , PredicateObligation < ' tcx > > ,
2585
2578
SelectionError < ' tcx > >
2586
2579
{
2587
- debug ! ( "confirm_closure_candidate({:?},{:?},{:?})" ,
2588
- obligation,
2589
- closure_def_id,
2590
- substs) ;
2580
+ debug ! ( "confirm_closure_candidate({:?})" , obligation) ;
2581
+
2582
+ let kind = match self . tcx ( ) . lang_items . fn_trait_kind ( obligation. predicate . 0 . def_id ( ) ) {
2583
+ Some ( k) => k,
2584
+ None => bug ! ( "closure candidate for non-fn trait {:?}" , obligation)
2585
+ } ;
2586
+
2587
+ // ok to skip binder because the substs on closure types never
2588
+ // touch bound regions, they just capture the in-scope
2589
+ // type/region parameters
2590
+ let self_ty = self . infcx . shallow_resolve ( obligation. self_ty ( ) . skip_binder ( ) ) ;
2591
+ let ( closure_def_id, substs) = match self_ty. sty {
2592
+ ty:: TyClosure ( id, substs) => ( id, substs) ,
2593
+ _ => bug ! ( "closure candidate for non-closure {:?}" , obligation)
2594
+ } ;
2591
2595
2596
+ let trait_ref =
2597
+ self . closure_trait_ref_unnormalized ( obligation, closure_def_id, substs) ;
2592
2598
let Normalized {
2593
2599
value : trait_ref,
2594
2600
mut obligations
2595
- } = self . closure_trait_ref ( obligation, closure_def_id, substs) ;
2601
+ } = normalize_with_depth ( self ,
2602
+ obligation. param_env ,
2603
+ obligation. cause . clone ( ) ,
2604
+ obligation. recursion_depth +1 ,
2605
+ & trait_ref) ;
2596
2606
2597
2607
debug ! ( "confirm_closure_candidate(closure_def_id={:?}, trait_ref={:?}, obligations={:?})" ,
2598
2608
closure_def_id,
@@ -3059,24 +3069,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
3059
3069
ty:: Binder ( trait_ref)
3060
3070
}
3061
3071
3062
- fn closure_trait_ref ( & mut self ,
3063
- obligation : & TraitObligation < ' tcx > ,
3064
- closure_def_id : DefId ,
3065
- substs : ty:: ClosureSubsts < ' tcx > )
3066
- -> Normalized < ' tcx , ty:: PolyTraitRef < ' tcx > >
3067
- {
3068
- let trait_ref = self . closure_trait_ref_unnormalized (
3069
- obligation, closure_def_id, substs) ;
3070
-
3071
- // A closure signature can contain associated types which
3072
- // must be normalized.
3073
- normalize_with_depth ( self ,
3074
- obligation. param_env ,
3075
- obligation. cause . clone ( ) ,
3076
- obligation. recursion_depth +1 ,
3077
- & trait_ref)
3078
- }
3079
-
3080
3072
fn generator_trait_ref_unnormalized ( & mut self ,
3081
3073
obligation : & TraitObligation < ' tcx > ,
3082
3074
closure_def_id : DefId ,
@@ -3098,24 +3090,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
3098
3090
ty:: Binder ( trait_ref)
3099
3091
}
3100
3092
3101
- fn generator_trait_ref ( & mut self ,
3102
- obligation : & TraitObligation < ' tcx > ,
3103
- closure_def_id : DefId ,
3104
- substs : ty:: ClosureSubsts < ' tcx > )
3105
- -> Normalized < ' tcx , ty:: PolyTraitRef < ' tcx > >
3106
- {
3107
- let trait_ref = self . generator_trait_ref_unnormalized (
3108
- obligation, closure_def_id, substs) ;
3109
-
3110
- // A generator signature can contain associated types which
3111
- // must be normalized.
3112
- normalize_with_depth ( self ,
3113
- obligation. param_env ,
3114
- obligation. cause . clone ( ) ,
3115
- obligation. recursion_depth +1 ,
3116
- & trait_ref)
3117
- }
3118
-
3119
3093
/// Returns the obligations that are implied by instantiating an
3120
3094
/// impl or trait. The obligations are substituted and fully
3121
3095
/// normalized. This is used when confirming an impl or default
0 commit comments