@@ -1885,9 +1885,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1885
1885
self . inh . item_substs . borrow ( )
1886
1886
}
1887
1887
1888
- pub fn opt_node_ty_substs ( & self ,
1889
- id : ast:: NodeId ,
1890
- f: |& ty:: ItemSubsts < ' tcx > |) {
1888
+ pub fn opt_node_ty_substs < F > ( & self ,
1889
+ id : ast:: NodeId ,
1890
+ f : F ) where
1891
+ F : FnOnce ( & ty:: ItemSubsts < ' tcx > ) ,
1892
+ {
1891
1893
match self . inh . item_substs . borrow ( ) . get ( & id) {
1892
1894
Some ( s) => { f ( s) }
1893
1895
None => { }
@@ -2027,12 +2029,14 @@ impl Copy for LvaluePreference {}
2027
2029
///
2028
2030
/// Note: this method does not modify the adjustments table. The caller is responsible for
2029
2031
/// inserting an AutoAdjustment record into the `fcx` using one of the suitable methods.
2030
- pub fn autoderef < ' a , ' tcx , T > ( fcx : & FnCtxt < ' a , ' tcx > , sp : Span ,
2031
- base_ty : Ty < ' tcx > ,
2032
- expr_id : Option < ast:: NodeId > ,
2033
- mut lvalue_pref : LvaluePreference ,
2034
- should_stop : |Ty < ' tcx > , uint| -> Option < T > )
2035
- -> ( Ty < ' tcx > , uint, Option < T > ) {
2032
+ pub fn autoderef < ' a , ' tcx , T , F > ( fcx : & FnCtxt < ' a , ' tcx > , sp : Span ,
2033
+ base_ty : Ty < ' tcx > ,
2034
+ expr_id : Option < ast:: NodeId > ,
2035
+ mut lvalue_pref : LvaluePreference ,
2036
+ mut should_stop : F )
2037
+ -> ( Ty < ' tcx > , uint , Option < T > ) where
2038
+ F : FnMut ( Ty < ' tcx > , uint ) -> Option < T > ,
2039
+ {
2036
2040
let mut t = base_ty;
2037
2041
for autoderefs in range ( 0 , fcx. tcx ( ) . sess . recursion_limit . get ( ) ) {
2038
2042
let resolved_t = structurally_resolved_type ( fcx, sp, t) ;
@@ -2194,12 +2198,13 @@ fn make_overloaded_lvalue_return_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
2194
2198
}
2195
2199
}
2196
2200
2197
- fn autoderef_for_index < ' a , ' tcx , T > ( fcx: & FnCtxt < ' a , ' tcx > ,
2198
- base_expr: & ast:: Expr ,
2199
- base_ty: Ty < ' tcx > ,
2200
- lvalue_pref: LvaluePreference ,
2201
- step: |Ty < ' tcx > , ty:: AutoDerefRef < ' tcx > | -> Option < T > )
2202
- -> Option < T >
2201
+ fn autoderef_for_index < ' a , ' tcx , T , F > ( fcx : & FnCtxt < ' a , ' tcx > ,
2202
+ base_expr : & ast:: Expr ,
2203
+ base_ty : Ty < ' tcx > ,
2204
+ lvalue_pref : LvaluePreference ,
2205
+ mut step : F )
2206
+ -> Option < T > where
2207
+ F : FnMut ( Ty < ' tcx > , ty:: AutoDerefRef < ' tcx > ) -> Option < T > ,
2203
2208
{
2204
2209
// FIXME(#18741) -- this is almost but not quite the same as the
2205
2210
// autoderef that normal method probing does. They could likely be
@@ -2938,11 +2943,12 @@ enum TupleArgumentsFlag {
2938
2943
/// Note that inspecting a type's structure *directly* may expose the fact
2939
2944
/// that there are actually multiple representations for `ty_err`, so avoid
2940
2945
/// that when err needs to be handled differently.
2941
- fn check_expr_with_unifier < ' a , ' tcx > ( fcx : & FnCtxt < ' a , ' tcx > ,
2942
- expr : & ast:: Expr ,
2943
- expected : Expectation < ' tcx > ,
2944
- lvalue_pref : LvaluePreference ,
2945
- unifier: ||)
2946
+ fn check_expr_with_unifier < ' a , ' tcx , F > ( fcx : & FnCtxt < ' a , ' tcx > ,
2947
+ expr : & ast:: Expr ,
2948
+ expected : Expectation < ' tcx > ,
2949
+ lvalue_pref : LvaluePreference ,
2950
+ unifier : F ) where
2951
+ F : FnOnce ( ) ,
2946
2952
{
2947
2953
debug ! ( ">> typechecking: expr={} expected={}" ,
2948
2954
expr. repr( fcx. tcx( ) ) , expected. repr( fcx. tcx( ) ) ) ;
@@ -3117,14 +3123,16 @@ fn check_expr_with_unifier<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
3117
3123
fcx. write_ty ( id, if_ty) ;
3118
3124
}
3119
3125
3120
- fn lookup_op_method < ' a , ' tcx > ( fcx : & ' a FnCtxt < ' a , ' tcx > ,
3121
- op_ex : & ast:: Expr ,
3122
- lhs_ty : Ty < ' tcx > ,
3123
- opname : ast:: Name ,
3124
- trait_did : Option < ast:: DefId > ,
3125
- lhs : & ' a ast:: Expr ,
3126
- rhs : Option < & P < ast:: Expr > > ,
3127
- unbound_method: ||) -> Ty < ' tcx > {
3126
+ fn lookup_op_method < ' a , ' tcx , F > ( fcx : & ' a FnCtxt < ' a , ' tcx > ,
3127
+ op_ex : & ast:: Expr ,
3128
+ lhs_ty : Ty < ' tcx > ,
3129
+ opname : ast:: Name ,
3130
+ trait_did : Option < ast:: DefId > ,
3131
+ lhs : & ' a ast:: Expr ,
3132
+ rhs : Option < & P < ast:: Expr > > ,
3133
+ unbound_method : F ) -> Ty < ' tcx > where
3134
+ F : FnOnce ( ) ,
3135
+ {
3128
3136
let method = match trait_did {
3129
3137
Some ( trait_did) => {
3130
3138
// We do eager coercions to make using operators
@@ -4376,19 +4384,17 @@ impl<'tcx> Expectation<'tcx> {
4376
4384
}
4377
4385
}
4378
4386
4379
- fn map < ' a > ( self , fcx : & FnCtxt < ' a , ' tcx > ,
4380
- unpack : | & ty:: sty < ' tcx > | -> Expectation < ' tcx > )
4381
- -> Expectation < ' tcx > {
4387
+ fn map < ' a , F > ( self , fcx : & FnCtxt < ' a , ' tcx > , unpack : F ) -> Expectation < ' tcx > where
4388
+ F : FnOnce ( & ty:: sty < ' tcx > ) -> Expectation < ' tcx >
4389
+ {
4382
4390
match self . resolve ( fcx) {
4383
4391
NoExpectation => NoExpectation ,
4384
4392
ExpectCastableToType ( t) | ExpectHasType ( t) => unpack ( & t. sty ) ,
4385
4393
}
4386
4394
}
4387
4395
4388
- fn map_to_option < ' a , O > ( self ,
4389
- fcx : & FnCtxt < ' a , ' tcx > ,
4390
- unpack: |& ty:: sty < ' tcx > | -> Option < O > )
4391
- -> Option < O >
4396
+ fn map_to_option < ' a , O , F > ( self , fcx : & FnCtxt < ' a , ' tcx > , unpack : F ) -> Option < O > where
4397
+ F : FnOnce ( & ty:: sty < ' tcx > ) -> Option < O > ,
4392
4398
{
4393
4399
match self . resolve ( fcx) {
4394
4400
NoExpectation => None ,
0 commit comments