@@ -226,7 +226,7 @@ impl DerefDelegate<'_, 'tcx> {
226
226
format ! ( "{}{}" , self . suggestion_start, end_snip)
227
227
}
228
228
229
- fn func_takes_arg_by_ref ( & self , parent_expr : & ' tcx hir:: Expr < ' _ > , cmt_hir_id : HirId ) -> bool {
229
+ fn func_takes_arg_by_double_ref ( & self , parent_expr : & ' tcx hir:: Expr < ' _ > , cmt_hir_id : HirId ) -> bool {
230
230
let ( call_args, inputs) = match parent_expr. kind {
231
231
ExprKind :: MethodCall ( _, _, call_args, _) => {
232
232
if let Some ( method_did) = self . cx . typeck_results ( ) . type_dependent_def_id ( parent_expr. hir_id ) {
@@ -277,16 +277,18 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
277
277
let arg_ty_kind = self . cx . typeck_results ( ) . expr_ty ( expr) . kind ( ) ;
278
278
279
279
if matches ! ( arg_ty_kind, ty:: Ref ( _, _, Mutability :: Not ) ) {
280
- // suggest ampersand if call function is taking args by ref
281
- let takes_arg_by_ref = self . func_takes_arg_by_ref ( parent_expr, cmt. hir_id ) ;
280
+ // suggest ampersand if call function is taking args by double reference
281
+ let takes_arg_by_double_ref = self . func_takes_arg_by_double_ref ( parent_expr, cmt. hir_id ) ;
282
282
283
283
// do not suggest ampersand if the ident is the method caller
284
- let ident_sugg =
285
- if !call_args. is_empty ( ) && call_args[ 0 ] . hir_id == cmt. hir_id && !takes_arg_by_ref {
286
- format ! ( "{}{}" , start_snip, ident_str)
287
- } else {
288
- format ! ( "{}&{}" , start_snip, ident_str)
289
- } ;
284
+ let ident_sugg = if !call_args. is_empty ( )
285
+ && call_args[ 0 ] . hir_id == cmt. hir_id
286
+ && !takes_arg_by_double_ref
287
+ {
288
+ format ! ( "{}{}" , start_snip, ident_str)
289
+ } else {
290
+ format ! ( "{}&{}" , start_snip, ident_str)
291
+ } ;
290
292
self . suggestion_start . push_str ( & ident_sugg) ;
291
293
self . next_pos = span. hi ( ) ;
292
294
return ;
0 commit comments