@@ -18,6 +18,7 @@ use self::BuiltinBoundConditions::*;
1818use self :: EvaluationResult :: * ;
1919
2020use super :: { DerivedObligationCause } ;
21+ use super :: { project} ;
2122use super :: { PredicateObligation , Obligation , TraitObligation , ObligationCause } ;
2223use super :: { ObligationCauseCode , BuiltinDerivedObligation } ;
2324use super :: { SelectionError , Unimplemented , Overflow , OutputTypeParameterMismatch } ;
@@ -29,7 +30,7 @@ use super::{util};
2930
3031use middle:: fast_reject;
3132use middle:: mem_categorization:: Typer ;
32- use middle:: subst:: { Subst , Substs , VecPerParamSpace } ;
33+ use middle:: subst:: { Subst , Substs , TypeSpace , VecPerParamSpace } ;
3334use middle:: ty:: { mod, AsPredicate , RegionEscape , ToPolyTraitRef , Ty } ;
3435use middle:: infer;
3536use middle:: infer:: { InferCtxt , TypeFreshener } ;
@@ -44,7 +45,7 @@ use util::ppaux::Repr;
4445pub struct SelectionContext < ' cx , ' tcx : ' cx > {
4546 infcx : & ' cx InferCtxt < ' cx , ' tcx > ,
4647 param_env : & ' cx ty:: ParameterEnvironment < ' tcx > ,
47- typer : & ' cx ( Typer < ' tcx > +' cx ) ,
48+ closure_typer : & ' cx ( ty :: UnboxedClosureTyper < ' tcx > +' cx ) ,
4849
4950 /// Freshener used specifically for skolemizing entries on the
5051 /// obligation stack. This ensures that all entries on the stack
@@ -177,25 +178,25 @@ enum EvaluationResult<'tcx> {
177178impl < ' cx , ' tcx > SelectionContext < ' cx , ' tcx > {
178179 pub fn new ( infcx : & ' cx InferCtxt < ' cx , ' tcx > ,
179180 param_env : & ' cx ty:: ParameterEnvironment < ' tcx > ,
180- typer : & ' cx Typer < ' tcx > )
181+ closure_typer : & ' cx ty :: UnboxedClosureTyper < ' tcx > )
181182 -> SelectionContext < ' cx , ' tcx > {
182183 SelectionContext {
183184 infcx : infcx,
184185 param_env : param_env,
185- typer : typer ,
186+ closure_typer : closure_typer ,
186187 freshener : infcx. freshener ( ) ,
187188 intercrate : false ,
188189 }
189190 }
190191
191192 pub fn intercrate ( infcx : & ' cx InferCtxt < ' cx , ' tcx > ,
192193 param_env : & ' cx ty:: ParameterEnvironment < ' tcx > ,
193- typer : & ' cx Typer < ' tcx > )
194+ closure_typer : & ' cx ty :: UnboxedClosureTyper < ' tcx > )
194195 -> SelectionContext < ' cx , ' tcx > {
195196 SelectionContext {
196197 infcx : infcx,
197198 param_env : param_env,
198- typer : typer ,
199+ closure_typer : closure_typer ,
199200 freshener : infcx. freshener ( ) ,
200201 intercrate : true ,
201202 }
@@ -918,15 +919,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
918919 kind,
919920 obligation. repr( self . tcx( ) ) ) ;
920921
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) ;
930923
931924 debug ! ( "closure_kind = {}" , closure_kind) ;
932925
@@ -1398,32 +1391,21 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13981391 return Ok ( ParameterBuiltin ) ;
13991392 }
14001393
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 ( ) ) )
14051397 }
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 )
14171400 }
14181401 }
14191402 }
14201403
14211404 ty:: ty_struct( def_id, substs) => {
14221405 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 ( ) ;
14271409 nominal ( self , bound, def_id, types)
14281410 }
14291411
@@ -1798,27 +1780,22 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17981780 closure_def_id. repr( self . tcx( ) ) ,
17991781 substs. repr( self . tcx( ) ) ) ;
18001782
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( ) ) ) ;
18101788
18111789 let closure_sig = & closure_type. sig ;
18121790 let arguments_tuple = closure_sig. 0 . inputs [ 0 ] ;
1813- let substs =
1791+ let trait_substs =
18141792 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( ) ] ,
18171794 vec ! [ ] ,
18181795 obligation. self_ty ( ) ) ;
18191796 let trait_ref = ty:: Binder ( Rc :: new ( ty:: TraitRef {
18201797 def_id : obligation. predicate . def_id ( ) ,
1821- substs : self . tcx ( ) . mk_substs ( substs ) ,
1798+ substs : self . tcx ( ) . mk_substs ( trait_substs ) ,
18221799 } ) ) ;
18231800
18241801 debug ! ( "confirm_unboxed_closure_candidate(closure_def_id={}, trait_ref={})" ,
@@ -2100,7 +2077,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
21002077 }
21012078 }
21022079
2103- fn impl_predicates ( & self ,
2080+ fn impl_predicates ( & mut self ,
21042081 cause : ObligationCause < ' tcx > ,
21052082 recursion_depth : uint ,
21062083 impl_def_id : ast:: DefId ,
@@ -2111,8 +2088,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
21112088 {
21122089 let impl_generics = ty:: lookup_item_type ( self . tcx ( ) , impl_def_id) . generics ;
21132090 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
21162104 }
21172105
21182106 fn fn_family_trait_kind ( & self ,
0 commit comments