@@ -110,7 +110,7 @@ enum Candidate {
110
110
BuiltinCandidate ( ty:: BuiltinBound ) ,
111
111
ParamCandidate ( VtableParamData ) ,
112
112
ImplCandidate ( ast:: DefId ) ,
113
- UnboxedClosureCandidate ( /* closure */ ast:: DefId ) ,
113
+ UnboxedClosureCandidate ( /* closure */ ast:: DefId , Substs ) ,
114
114
ErrorCandidate ,
115
115
}
116
116
@@ -995,8 +995,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
995
995
} ;
996
996
997
997
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 ( ) ) ,
1000
1000
ty:: ty_infer( ty:: TyVar ( _) ) => {
1001
1001
candidates. ambiguous = true ;
1002
1002
return Ok ( ( ) ) ;
@@ -1019,7 +1019,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1019
1019
} ;
1020
1020
1021
1021
if closure_kind == kind {
1022
- candidates. vec . push ( UnboxedClosureCandidate ( closure_def_id) ) ;
1022
+ candidates. vec . push ( UnboxedClosureCandidate ( closure_def_id, substs . clone ( ) ) ) ;
1023
1023
}
1024
1024
1025
1025
Ok ( ( ) )
@@ -1383,7 +1383,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1383
1383
Ok ( If ( tys. clone ( ) ) )
1384
1384
}
1385
1385
1386
- ty:: ty_unboxed_closure( def_id, _) => {
1386
+ ty:: ty_unboxed_closure( def_id, _, ref substs ) => {
1387
1387
// FIXME -- This case is tricky. In the case of by-ref
1388
1388
// closures particularly, we need the results of
1389
1389
// inference to decide how to reflect the type of each
@@ -1407,7 +1407,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1407
1407
. map ( |freevar| {
1408
1408
let freevar_def_id = freevar. def . def_id ( ) ;
1409
1409
self . typer . node_ty ( freevar_def_id. node )
1410
- . unwrap_or ( ty:: mk_err ( ) )
1410
+ . unwrap_or ( ty:: mk_err ( ) ) . subst ( self . tcx ( ) , substs )
1411
1411
} )
1412
1412
. collect ( ) ;
1413
1413
Ok ( If ( tys) )
@@ -1548,8 +1548,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1548
1548
Ok ( VtableImpl ( vtable_impl) )
1549
1549
}
1550
1550
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 ) ) ;
1553
1553
Ok ( VtableUnboxedClosure ( closure_def_id) )
1554
1554
}
1555
1555
}
@@ -1646,12 +1646,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1646
1646
1647
1647
fn confirm_unboxed_closure_candidate ( & mut self ,
1648
1648
obligation : & Obligation ,
1649
- closure_def_id : ast:: DefId )
1649
+ closure_def_id : ast:: DefId ,
1650
+ substs : & Substs )
1650
1651
-> Result < ( ) , SelectionError >
1651
1652
{
1652
- debug ! ( "confirm_unboxed_closure_candidate({},{})" ,
1653
+ debug ! ( "confirm_unboxed_closure_candidate({},{},{} )" ,
1653
1654
obligation. repr( self . tcx( ) ) ,
1654
- closure_def_id. repr( self . tcx( ) ) ) ;
1655
+ closure_def_id. repr( self . tcx( ) ) ,
1656
+ substs. repr( self . tcx( ) ) ) ;
1655
1657
1656
1658
let closure_type = match self . typer . unboxed_closures ( ) . borrow ( ) . find ( & closure_def_id) {
1657
1659
Some ( closure) => closure. closure_type . clone ( ) ,
@@ -1678,7 +1680,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1678
1680
let trait_ref = Rc :: new ( ty:: TraitRef {
1679
1681
def_id : obligation. trait_ref . def_id ,
1680
1682
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) ] ,
1682
1685
vec ! [ ] ,
1683
1686
obligation. self_ty ( ) )
1684
1687
} ) ;
@@ -1959,7 +1962,9 @@ impl Repr for Candidate {
1959
1962
match * self {
1960
1963
ErrorCandidate => format ! ( "ErrorCandidate" ) ,
1961
1964
BuiltinCandidate ( b) => format ! ( "BuiltinCandidate({})" , b) ,
1962
- UnboxedClosureCandidate ( c) => format ! ( "MatchedUnboxedClosureCandidate({})" , c) ,
1965
+ UnboxedClosureCandidate ( c, ref s) => {
1966
+ format ! ( "MatchedUnboxedClosureCandidate({},{})" , c, s. repr( tcx) )
1967
+ }
1963
1968
ParamCandidate ( ref a) => format ! ( "ParamCandidate({})" , a. repr( tcx) ) ,
1964
1969
ImplCandidate ( a) => format ! ( "ImplCandidate({})" , a. repr( tcx) ) ,
1965
1970
}
0 commit comments