@@ -110,7 +110,7 @@ enum Candidate {
110110 BuiltinCandidate ( ty:: BuiltinBound ) ,
111111 ParamCandidate ( VtableParamData ) ,
112112 ImplCandidate ( ast:: DefId ) ,
113- UnboxedClosureCandidate ( /* closure */ ast:: DefId ) ,
113+ UnboxedClosureCandidate ( /* closure */ ast:: DefId , Substs ) ,
114114 ErrorCandidate ,
115115}
116116
@@ -995,8 +995,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
995995 } ;
996996
997997 let self_ty = self . infcx . shallow_resolve ( obligation. self_ty ( ) ) ;
998- let closure_def_id = match ty:: get ( self_ty) . sty {
999- ty:: ty_unboxed_closure( id, _) => id ,
998+ let ( closure_def_id, substs ) = match ty:: get ( self_ty) . sty {
999+ ty:: ty_unboxed_closure( id, _, ref substs ) => ( id , substs . clone ( ) ) ,
10001000 ty:: ty_infer( ty:: TyVar ( _) ) => {
10011001 candidates. ambiguous = true ;
10021002 return Ok ( ( ) ) ;
@@ -1019,7 +1019,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10191019 } ;
10201020
10211021 if closure_kind == kind {
1022- candidates. vec . push ( UnboxedClosureCandidate ( closure_def_id) ) ;
1022+ candidates. vec . push ( UnboxedClosureCandidate ( closure_def_id, substs . clone ( ) ) ) ;
10231023 }
10241024
10251025 Ok ( ( ) )
@@ -1383,7 +1383,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13831383 Ok ( If ( tys. clone ( ) ) )
13841384 }
13851385
1386- ty:: ty_unboxed_closure( def_id, _) => {
1386+ ty:: ty_unboxed_closure( def_id, _, ref substs ) => {
13871387 // FIXME -- This case is tricky. In the case of by-ref
13881388 // closures particularly, we need the results of
13891389 // inference to decide how to reflect the type of each
@@ -1407,7 +1407,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14071407 . map ( |freevar| {
14081408 let freevar_def_id = freevar. def . def_id ( ) ;
14091409 self . typer . node_ty ( freevar_def_id. node )
1410- . unwrap_or ( ty:: mk_err ( ) )
1410+ . unwrap_or ( ty:: mk_err ( ) ) . subst ( self . tcx ( ) , substs )
14111411 } )
14121412 . collect ( ) ;
14131413 Ok ( If ( tys) )
@@ -1548,8 +1548,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15481548 Ok ( VtableImpl ( vtable_impl) )
15491549 }
15501550
1551- UnboxedClosureCandidate ( closure_def_id) => {
1552- try!( self . confirm_unboxed_closure_candidate ( obligation, closure_def_id) ) ;
1551+ UnboxedClosureCandidate ( closure_def_id, ref substs ) => {
1552+ try!( self . confirm_unboxed_closure_candidate ( obligation, closure_def_id, substs ) ) ;
15531553 Ok ( VtableUnboxedClosure ( closure_def_id) )
15541554 }
15551555 }
@@ -1646,12 +1646,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16461646
16471647 fn confirm_unboxed_closure_candidate ( & mut self ,
16481648 obligation : & Obligation ,
1649- closure_def_id : ast:: DefId )
1649+ closure_def_id : ast:: DefId ,
1650+ substs : & Substs )
16501651 -> Result < ( ) , SelectionError >
16511652 {
1652- debug ! ( "confirm_unboxed_closure_candidate({},{})" ,
1653+ debug ! ( "confirm_unboxed_closure_candidate({},{},{} )" ,
16531654 obligation. repr( self . tcx( ) ) ,
1654- closure_def_id. repr( self . tcx( ) ) ) ;
1655+ closure_def_id. repr( self . tcx( ) ) ,
1656+ substs. repr( self . tcx( ) ) ) ;
16551657
16561658 let closure_type = match self . typer . unboxed_closures ( ) . borrow ( ) . find ( & closure_def_id) {
16571659 Some ( closure) => closure. closure_type . clone ( ) ,
@@ -1678,7 +1680,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16781680 let trait_ref = Rc :: new ( ty:: TraitRef {
16791681 def_id : obligation. trait_ref . def_id ,
16801682 substs : Substs :: new_trait (
1681- vec ! [ arguments_tuple, new_signature. output] ,
1683+ vec ! [ arguments_tuple. subst( self . tcx( ) , substs) ,
1684+ new_signature. output. subst( self . tcx( ) , substs) ] ,
16821685 vec ! [ ] ,
16831686 obligation. self_ty ( ) )
16841687 } ) ;
@@ -1959,7 +1962,9 @@ impl Repr for Candidate {
19591962 match * self {
19601963 ErrorCandidate => format ! ( "ErrorCandidate" ) ,
19611964 BuiltinCandidate ( b) => format ! ( "BuiltinCandidate({})" , b) ,
1962- UnboxedClosureCandidate ( c) => format ! ( "MatchedUnboxedClosureCandidate({})" , c) ,
1965+ UnboxedClosureCandidate ( c, ref s) => {
1966+ format ! ( "MatchedUnboxedClosureCandidate({},{})" , c, s. repr( tcx) )
1967+ }
19631968 ParamCandidate ( ref a) => format ! ( "ParamCandidate({})" , a. repr( tcx) ) ,
19641969 ImplCandidate ( a) => format ! ( "ImplCandidate({})" , a. repr( tcx) ) ,
19651970 }
0 commit comments