@@ -83,9 +83,7 @@ pub fn check_call<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
83
83
UnresolvedTypeAction :: Error ,
84
84
LvaluePreference :: NoPreference ,
85
85
|adj_ty, idx| {
86
- let autoderefref = ty:: AutoDerefRef { autoderefs : idx, autoref : None } ;
87
- try_overloaded_call_step ( fcx, call_expr, callee_expr,
88
- adj_ty, autoderefref)
86
+ try_overloaded_call_step ( fcx, call_expr, callee_expr, adj_ty, idx)
89
87
} ) ;
90
88
91
89
match result {
@@ -119,13 +117,15 @@ fn try_overloaded_call_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
119
117
call_expr : & ' tcx ast:: Expr ,
120
118
callee_expr : & ' tcx ast:: Expr ,
121
119
adjusted_ty : Ty < ' tcx > ,
122
- autoderefref : ty :: AutoDerefRef < ' tcx > )
120
+ autoderefs : usize )
123
121
-> Option < CallStep < ' tcx > >
124
122
{
125
- debug ! ( "try_overloaded_call_step(call_expr={}, adjusted_ty={}, autoderefref ={})" ,
123
+ debug ! ( "try_overloaded_call_step(call_expr={}, adjusted_ty={}, autoderefs ={})" ,
126
124
call_expr. repr( fcx. tcx( ) ) ,
127
125
adjusted_ty. repr( fcx. tcx( ) ) ,
128
- autoderefref. repr( fcx. tcx( ) ) ) ;
126
+ autoderefs) ;
127
+
128
+ let autoderefref = ty:: AutoDerefRef { autoderefs : autoderefs, autoref : None } ;
129
129
130
130
// If the callee is a bare function or a closure, then we're all set.
131
131
match structurally_resolved_type ( fcx, callee_expr. span , adjusted_ty) . sty {
@@ -161,6 +161,18 @@ fn try_overloaded_call_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
161
161
}
162
162
}
163
163
164
+ // Hack: we know that there are traits implementing Fn for &F
165
+ // where F:Fn and so forth. In the particular case of types
166
+ // like `x: &mut FnMut()`, if there is a call `x()`, we would
167
+ // normally translate to `FnMut::call_mut(&mut x, ())`, but
168
+ // that winds up requiring `mut x: &mut FnMut()`. A little
169
+ // over the top. The simplest fix by far is to just ignore
170
+ // this case and deref again, so we wind up with
171
+ // `FnMut::call_mut(&mut *x, ())`.
172
+ ty:: ty_rptr( ..) if autoderefs == 0 => {
173
+ return None ;
174
+ }
175
+
164
176
_ => { }
165
177
}
166
178
0 commit comments