@@ -1358,6 +1358,34 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1358
1358
Applicability :: MaybeIncorrect ,
1359
1359
) ;
1360
1360
} else {
1361
+ let is_mut = mut_ref_self_ty_satisfies_pred || ref_inner_ty_mut;
1362
+ let sugg_prefix = format ! ( "&{}" , if is_mut { "mut " } else { "" } ) ;
1363
+ let sugg_msg = & format ! (
1364
+ "consider{} borrowing here" ,
1365
+ if is_mut { " mutably" } else { "" }
1366
+ ) ;
1367
+
1368
+ // Issue #109436, we need to add parentheses properly for method calls
1369
+ // for example, `foo.into()` should be `(&foo).into()`
1370
+ if let Ok ( snippet) = self
1371
+ . tcx
1372
+ . sess
1373
+ . source_map ( )
1374
+ . span_to_snippet ( self . tcx . sess . source_map ( ) . next_point ( span) )
1375
+ {
1376
+ if snippet == "." {
1377
+ err. multipart_suggestion_verbose (
1378
+ sugg_msg,
1379
+ vec ! [
1380
+ ( span. shrink_to_lo( ) , format!( "({}" , sugg_prefix) ) ,
1381
+ ( span. shrink_to_hi( ) , ")" . to_string( ) ) ,
1382
+ ] ,
1383
+ Applicability :: MaybeIncorrect ,
1384
+ ) ;
1385
+ return true ;
1386
+ }
1387
+ }
1388
+
1361
1389
// Issue #104961, we need to add parentheses properly for compond expressions
1362
1390
// for example, `x.starts_with("hi".to_string() + "you")`
1363
1391
// should be `x.starts_with(&("hi".to_string() + "you"))`
@@ -1374,14 +1402,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1374
1402
_ => false ,
1375
1403
} ;
1376
1404
1377
- let is_mut = mut_ref_self_ty_satisfies_pred || ref_inner_ty_mut;
1378
1405
let span = if needs_parens { span } else { span. shrink_to_lo ( ) } ;
1379
- let sugg_prefix = format ! ( "&{}" , if is_mut { "mut " } else { "" } ) ;
1380
- let sugg_msg = & format ! (
1381
- "consider{} borrowing here" ,
1382
- if is_mut { " mutably" } else { "" }
1383
- ) ;
1384
-
1385
1406
let suggestions = if !needs_parens {
1386
1407
vec ! [ ( span. shrink_to_lo( ) , format!( "{}" , sugg_prefix) ) ]
1387
1408
} else {
0 commit comments