@@ -1325,6 +1325,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1325
1325
let tcx = self . tcx ;
1326
1326
let def_kind = similar_candidate. kind . as_def_kind ( ) ;
1327
1327
let an = self . tcx . def_kind_descr_article ( def_kind, similar_candidate. def_id ) ;
1328
+ let msg = format ! (
1329
+ "there is {an} {} `{}` with a similar name" ,
1330
+ self . tcx. def_kind_descr( def_kind, similar_candidate. def_id) ,
1331
+ similar_candidate. name,
1332
+ ) ;
1328
1333
// Methods are defined within the context of a struct and their first parameter
1329
1334
// is always `self`, which represents the instance of the struct the method is
1330
1335
// being called on Associated functions don’t take self as a parameter and they are
@@ -1341,7 +1346,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1341
1346
// call expression the user wrote.
1342
1347
err. span_suggestion_verbose (
1343
1348
span,
1344
- format ! ( "there is {an} method with a similar name" ) ,
1349
+ msg ,
1345
1350
similar_candidate. name ,
1346
1351
Applicability :: MaybeIncorrect ,
1347
1352
) ;
@@ -1351,8 +1356,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1351
1356
err. span_help (
1352
1357
tcx. def_span ( similar_candidate. def_id ) ,
1353
1358
format ! (
1354
- "there is {an} method `{}` with a similar name{}" ,
1355
- similar_candidate. name,
1359
+ "{msg}{}" ,
1356
1360
if let None = args { "" } else { ", but with different arguments" } ,
1357
1361
) ,
1358
1362
) ;
@@ -1364,47 +1368,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1364
1368
// function we found.
1365
1369
err. span_suggestion_verbose (
1366
1370
span,
1367
- format ! (
1368
- "there is {an} {} with a similar name" ,
1369
- self . tcx. def_kind_descr( def_kind, similar_candidate. def_id)
1370
- ) ,
1371
+ msg,
1371
1372
similar_candidate. name ,
1372
1373
Applicability :: MaybeIncorrect ,
1373
1374
) ;
1374
1375
} else {
1375
- err. span_help (
1376
- tcx. def_span ( similar_candidate. def_id ) ,
1377
- format ! (
1378
- "there is {an} {} `{}` with a similar name" ,
1379
- self . tcx. def_kind_descr( def_kind, similar_candidate. def_id) ,
1380
- similar_candidate. name,
1381
- ) ,
1382
- ) ;
1376
+ err. span_help ( tcx. def_span ( similar_candidate. def_id ) , msg) ;
1383
1377
}
1384
1378
} else if let Mode :: Path = mode
1385
1379
&& args. unwrap_or ( & [ ] ) . is_empty ( )
1386
1380
{
1387
1381
// We have an associated item syntax and we found something that isn't an fn.
1388
1382
err. span_suggestion_verbose (
1389
1383
span,
1390
- format ! (
1391
- "there is {an} {} with a similar name" ,
1392
- self . tcx. def_kind_descr( def_kind, similar_candidate. def_id)
1393
- ) ,
1384
+ msg,
1394
1385
similar_candidate. name ,
1395
1386
Applicability :: MaybeIncorrect ,
1396
1387
) ;
1397
1388
} else {
1398
1389
// The expression is a function or method call, but the item we found is an
1399
1390
// associated const or type.
1400
- err. span_help (
1401
- tcx. def_span ( similar_candidate. def_id ) ,
1402
- format ! (
1403
- "there is {an} {} `{}` with a similar name" ,
1404
- self . tcx. def_kind_descr( def_kind, similar_candidate. def_id) ,
1405
- similar_candidate. name,
1406
- ) ,
1407
- ) ;
1391
+ err. span_help ( tcx. def_span ( similar_candidate. def_id ) , msg) ;
1408
1392
}
1409
1393
}
1410
1394
0 commit comments