@@ -18,6 +18,7 @@ use self::BuiltinBoundConditions::*;
18
18
use self :: EvaluationResult :: * ;
19
19
20
20
use super :: { DerivedObligationCause } ;
21
+ use super :: { project} ;
21
22
use super :: { PredicateObligation , Obligation , TraitObligation , ObligationCause } ;
22
23
use super :: { ObligationCauseCode , BuiltinDerivedObligation } ;
23
24
use super :: { SelectionError , Unimplemented , Overflow , OutputTypeParameterMismatch } ;
@@ -29,7 +30,7 @@ use super::{util};
29
30
30
31
use middle:: fast_reject;
31
32
use middle:: mem_categorization:: Typer ;
32
- use middle:: subst:: { Subst , Substs , VecPerParamSpace } ;
33
+ use middle:: subst:: { Subst , Substs , TypeSpace , VecPerParamSpace } ;
33
34
use middle:: ty:: { mod, AsPredicate , RegionEscape , ToPolyTraitRef , Ty } ;
34
35
use middle:: infer;
35
36
use middle:: infer:: { InferCtxt , TypeFreshener } ;
@@ -44,7 +45,7 @@ use util::ppaux::Repr;
44
45
pub struct SelectionContext < ' cx , ' tcx : ' cx > {
45
46
infcx : & ' cx InferCtxt < ' cx , ' tcx > ,
46
47
param_env : & ' cx ty:: ParameterEnvironment < ' tcx > ,
47
- typer : & ' cx ( Typer < ' tcx > +' cx ) ,
48
+ closure_typer : & ' cx ( ty :: UnboxedClosureTyper < ' tcx > +' cx ) ,
48
49
49
50
/// Freshener used specifically for skolemizing entries on the
50
51
/// obligation stack. This ensures that all entries on the stack
@@ -177,25 +178,25 @@ enum EvaluationResult<'tcx> {
177
178
impl < ' cx , ' tcx > SelectionContext < ' cx , ' tcx > {
178
179
pub fn new ( infcx : & ' cx InferCtxt < ' cx , ' tcx > ,
179
180
param_env : & ' cx ty:: ParameterEnvironment < ' tcx > ,
180
- typer : & ' cx Typer < ' tcx > )
181
+ closure_typer : & ' cx ty :: UnboxedClosureTyper < ' tcx > )
181
182
-> SelectionContext < ' cx , ' tcx > {
182
183
SelectionContext {
183
184
infcx : infcx,
184
185
param_env : param_env,
185
- typer : typer ,
186
+ closure_typer : closure_typer ,
186
187
freshener : infcx. freshener ( ) ,
187
188
intercrate : false ,
188
189
}
189
190
}
190
191
191
192
pub fn intercrate ( infcx : & ' cx InferCtxt < ' cx , ' tcx > ,
192
193
param_env : & ' cx ty:: ParameterEnvironment < ' tcx > ,
193
- typer : & ' cx Typer < ' tcx > )
194
+ closure_typer : & ' cx ty :: UnboxedClosureTyper < ' tcx > )
194
195
-> SelectionContext < ' cx , ' tcx > {
195
196
SelectionContext {
196
197
infcx : infcx,
197
198
param_env : param_env,
198
- typer : typer ,
199
+ closure_typer : closure_typer ,
199
200
freshener : infcx. freshener ( ) ,
200
201
intercrate : true ,
201
202
}
@@ -918,15 +919,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
918
919
kind,
919
920
obligation. repr( self . tcx( ) ) ) ;
920
921
921
- let closure_kind = match self . typer . unboxed_closures ( ) . borrow ( ) . get ( & closure_def_id) {
922
- Some ( closure) => closure. kind ,
923
- None => {
924
- self . tcx ( ) . sess . span_bug (
925
- obligation. cause . span ,
926
- format ! ( "No entry for unboxed closure: {}" ,
927
- closure_def_id. repr( self . tcx( ) ) ) [ ] ) ;
928
- }
929
- } ;
922
+ let closure_kind = self . closure_typer . unboxed_closure_kind ( closure_def_id) ;
930
923
931
924
debug ! ( "closure_kind = {}" , closure_kind) ;
932
925
@@ -1398,32 +1391,21 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1398
1391
return Ok ( ParameterBuiltin ) ;
1399
1392
}
1400
1393
1401
- match self . tcx ( ) . freevars . borrow ( ) . get ( & def_id. node ) {
1402
- None => {
1403
- // No upvars.
1404
- Ok ( If ( Vec :: new ( ) ) )
1394
+ match self . closure_typer . unboxed_closure_upvars ( def_id, substs) {
1395
+ Some ( upvars) => {
1396
+ Ok ( If ( upvars. iter ( ) . map ( |c| c. ty ) . collect ( ) ) )
1405
1397
}
1406
-
1407
- Some ( freevars) => {
1408
- let tys: Vec < Ty > =
1409
- freevars
1410
- . iter ( )
1411
- . map ( |freevar| {
1412
- let freevar_def_id = freevar. def . def_id ( ) ;
1413
- self . typer . node_ty ( freevar_def_id. node ) . subst ( self . tcx ( ) , substs)
1414
- } )
1415
- . collect ( ) ;
1416
- Ok ( If ( tys) )
1398
+ None => {
1399
+ Ok ( AmbiguousBuiltin )
1417
1400
}
1418
1401
}
1419
1402
}
1420
1403
1421
1404
ty:: ty_struct( def_id, substs) => {
1422
1405
let types: Vec < Ty > =
1423
- ty:: struct_fields ( self . tcx ( ) , def_id, substs)
1424
- . iter ( )
1425
- . map ( |f| f. mt . ty )
1426
- . collect ( ) ;
1406
+ ty:: struct_fields ( self . tcx ( ) , def_id, substs) . iter ( )
1407
+ . map ( |f| f. mt . ty )
1408
+ . collect ( ) ;
1427
1409
nominal ( self , bound, def_id, types)
1428
1410
}
1429
1411
@@ -1798,27 +1780,22 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1798
1780
closure_def_id. repr( self . tcx( ) ) ,
1799
1781
substs. repr( self . tcx( ) ) ) ;
1800
1782
1801
- let closure_type = match self . typer . unboxed_closures ( ) . borrow ( ) . get ( & closure_def_id) {
1802
- Some ( closure) => closure. closure_type . clone ( ) ,
1803
- None => {
1804
- self . tcx ( ) . sess . span_bug (
1805
- obligation. cause . span ,
1806
- format ! ( "No entry for unboxed closure: {}" ,
1807
- closure_def_id. repr( self . tcx( ) ) ) [ ] ) ;
1808
- }
1809
- } ;
1783
+ let closure_type = self . closure_typer . unboxed_closure_type ( closure_def_id, substs) ;
1784
+
1785
+ debug ! ( "confirm_unboxed_closure_candidate: closure_def_id={} closure_type={}" ,
1786
+ closure_def_id. repr( self . tcx( ) ) ,
1787
+ closure_type. repr( self . tcx( ) ) ) ;
1810
1788
1811
1789
let closure_sig = & closure_type. sig ;
1812
1790
let arguments_tuple = closure_sig. 0 . inputs [ 0 ] ;
1813
- let substs =
1791
+ let trait_substs =
1814
1792
Substs :: new_trait (
1815
- vec ! [ arguments_tuple. subst( self . tcx( ) , substs) ,
1816
- closure_sig. 0 . output. unwrap( ) . subst( self . tcx( ) , substs) ] ,
1793
+ vec ! [ arguments_tuple, closure_sig. 0 . output. unwrap( ) ] ,
1817
1794
vec ! [ ] ,
1818
1795
obligation. self_ty ( ) ) ;
1819
1796
let trait_ref = ty:: Binder ( Rc :: new ( ty:: TraitRef {
1820
1797
def_id : obligation. predicate . def_id ( ) ,
1821
- substs : self . tcx ( ) . mk_substs ( substs ) ,
1798
+ substs : self . tcx ( ) . mk_substs ( trait_substs ) ,
1822
1799
} ) ) ;
1823
1800
1824
1801
debug ! ( "confirm_unboxed_closure_candidate(closure_def_id={}, trait_ref={})" ,
@@ -2100,7 +2077,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
2100
2077
}
2101
2078
}
2102
2079
2103
- fn impl_predicates ( & self ,
2080
+ fn impl_predicates ( & mut self ,
2104
2081
cause : ObligationCause < ' tcx > ,
2105
2082
recursion_depth : uint ,
2106
2083
impl_def_id : ast:: DefId ,
@@ -2111,8 +2088,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
2111
2088
{
2112
2089
let impl_generics = ty:: lookup_item_type ( self . tcx ( ) , impl_def_id) . generics ;
2113
2090
let bounds = impl_generics. to_bounds ( self . tcx ( ) , impl_substs) ;
2114
- let bounds = self . infcx ( ) . plug_leaks ( skol_map, snapshot, & bounds) ;
2115
- util:: predicates_for_generics ( self . tcx ( ) , cause, recursion_depth, & bounds)
2091
+ let normalized_bounds =
2092
+ project:: normalize_with_depth ( self , cause. clone ( ) , recursion_depth, & bounds) ;
2093
+ let normalized_bounds =
2094
+ self . infcx ( ) . plug_leaks ( skol_map, snapshot, & normalized_bounds) ;
2095
+ let mut impl_obligations =
2096
+ util:: predicates_for_generics ( self . tcx ( ) ,
2097
+ cause,
2098
+ recursion_depth,
2099
+ & normalized_bounds. value ) ;
2100
+ for obligation in normalized_bounds. obligations . into_iter ( ) {
2101
+ impl_obligations. push ( TypeSpace , obligation) ;
2102
+ }
2103
+ impl_obligations
2116
2104
}
2117
2105
2118
2106
fn fn_family_trait_kind ( & self ,
0 commit comments