@@ -220,21 +220,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
220220 let method = self . register_infer_ok_obligations ( ok) ;
221221 let mut autoref = None ;
222222 if borrow {
223- if let ty:: Ref ( region, _, mutbl) = method. sig . inputs ( ) [ 0 ] . kind {
224- let mutbl = match mutbl {
225- hir:: Mutability :: Not => AutoBorrowMutability :: Not ,
226- hir:: Mutability :: Mut => AutoBorrowMutability :: Mut {
227- // For initial two-phase borrow
228- // deployment, conservatively omit
229- // overloaded function call ops.
230- allow_two_phase_borrow : AllowTwoPhase :: No ,
231- } ,
232- } ;
233- autoref = Some ( Adjustment {
234- kind : Adjust :: Borrow ( AutoBorrow :: Ref ( region, mutbl) ) ,
235- target : method. sig . inputs ( ) [ 0 ] ,
236- } ) ;
237- }
223+ // Check for &self vs &mut self in the method signature. Since this is either
224+ // the Fn or FnMut trait, it should be one of those.
225+ let ( region, mutbl) = if let ty:: Ref ( r, _, mutbl) = method. sig . inputs ( ) [ 0 ] . kind
226+ {
227+ ( r, mutbl)
228+ } else {
229+ span_bug ! ( call_expr. span, "input to call/call_mut is not a ref?" ) ;
230+ } ;
231+
232+ let mutbl = match mutbl {
233+ hir:: Mutability :: Not => AutoBorrowMutability :: Not ,
234+ hir:: Mutability :: Mut => AutoBorrowMutability :: Mut {
235+ // For initial two-phase borrow
236+ // deployment, conservatively omit
237+ // overloaded function call ops.
238+ allow_two_phase_borrow : AllowTwoPhase :: No ,
239+ } ,
240+ } ;
241+ autoref = Some ( Adjustment {
242+ kind : Adjust :: Borrow ( AutoBorrow :: Ref ( region, mutbl) ) ,
243+ target : method. sig . inputs ( ) [ 0 ] ,
244+ } ) ;
238245 }
239246 return Some ( ( autoref, method) ) ;
240247 }
0 commit comments