@@ -1427,6 +1427,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1427
1427
let tcx = self . tcx ;
1428
1428
let def_kind = similar_candidate. kind . as_def_kind ( ) ;
1429
1429
let an = self . tcx . def_kind_descr_article ( def_kind, similar_candidate. def_id ) ;
1430
+ let msg = format ! (
1431
+ "there is {an} {} `{}` with a similar name" ,
1432
+ self . tcx. def_kind_descr( def_kind, similar_candidate. def_id) ,
1433
+ similar_candidate. name,
1434
+ ) ;
1430
1435
// Methods are defined within the context of a struct and their first parameter
1431
1436
// is always `self`, which represents the instance of the struct the method is
1432
1437
// being called on Associated functions don’t take self as a parameter and they are
@@ -1443,7 +1448,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1443
1448
// call expression the user wrote.
1444
1449
err. span_suggestion_verbose (
1445
1450
span,
1446
- format ! ( "there is {an} method with a similar name" ) ,
1451
+ msg ,
1447
1452
similar_candidate. name ,
1448
1453
Applicability :: MaybeIncorrect ,
1449
1454
) ;
@@ -1453,8 +1458,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1453
1458
err. span_help (
1454
1459
tcx. def_span ( similar_candidate. def_id ) ,
1455
1460
format ! (
1456
- "there is {an} method `{}` with a similar name{}" ,
1457
- similar_candidate. name,
1461
+ "{msg}{}" ,
1458
1462
if let None = args { "" } else { ", but with different arguments" } ,
1459
1463
) ,
1460
1464
) ;
@@ -1466,47 +1470,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1466
1470
// function we found.
1467
1471
err. span_suggestion_verbose (
1468
1472
span,
1469
- format ! (
1470
- "there is {an} {} with a similar name" ,
1471
- self . tcx. def_kind_descr( def_kind, similar_candidate. def_id)
1472
- ) ,
1473
+ msg,
1473
1474
similar_candidate. name ,
1474
1475
Applicability :: MaybeIncorrect ,
1475
1476
) ;
1476
1477
} else {
1477
- err. span_help (
1478
- tcx. def_span ( similar_candidate. def_id ) ,
1479
- format ! (
1480
- "there is {an} {} `{}` with a similar name" ,
1481
- self . tcx. def_kind_descr( def_kind, similar_candidate. def_id) ,
1482
- similar_candidate. name,
1483
- ) ,
1484
- ) ;
1478
+ err. span_help ( tcx. def_span ( similar_candidate. def_id ) , msg) ;
1485
1479
}
1486
1480
} else if let Mode :: Path = mode
1487
1481
&& args. unwrap_or ( & [ ] ) . is_empty ( )
1488
1482
{
1489
1483
// We have an associated item syntax and we found something that isn't an fn.
1490
1484
err. span_suggestion_verbose (
1491
1485
span,
1492
- format ! (
1493
- "there is {an} {} with a similar name" ,
1494
- self . tcx. def_kind_descr( def_kind, similar_candidate. def_id)
1495
- ) ,
1486
+ msg,
1496
1487
similar_candidate. name ,
1497
1488
Applicability :: MaybeIncorrect ,
1498
1489
) ;
1499
1490
} else {
1500
1491
// The expression is a function or method call, but the item we found is an
1501
1492
// associated const or type.
1502
- err. span_help (
1503
- tcx. def_span ( similar_candidate. def_id ) ,
1504
- format ! (
1505
- "there is {an} {} `{}` with a similar name" ,
1506
- self . tcx. def_kind_descr( def_kind, similar_candidate. def_id) ,
1507
- similar_candidate. name,
1508
- ) ,
1509
- ) ;
1493
+ err. span_help ( tcx. def_span ( similar_candidate. def_id ) , msg) ;
1510
1494
}
1511
1495
}
1512
1496
0 commit comments