@@ -1325,6 +1325,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13251325 let tcx = self . tcx ;
13261326 let def_kind = similar_candidate. kind . as_def_kind ( ) ;
13271327 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+ ) ;
13281333 // Methods are defined within the context of a struct and their first parameter
13291334 // is always `self`, which represents the instance of the struct the method is
13301335 // 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> {
13411346 // call expression the user wrote.
13421347 err. span_suggestion_verbose (
13431348 span,
1344- format ! ( "there is {an} method with a similar name" ) ,
1349+ msg ,
13451350 similar_candidate. name ,
13461351 Applicability :: MaybeIncorrect ,
13471352 ) ;
@@ -1351,8 +1356,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13511356 err. span_help (
13521357 tcx. def_span ( similar_candidate. def_id ) ,
13531358 format ! (
1354- "there is {an} method `{}` with a similar name{}" ,
1355- similar_candidate. name,
1359+ "{msg}{}" ,
13561360 if let None = args { "" } else { ", but with different arguments" } ,
13571361 ) ,
13581362 ) ;
@@ -1364,47 +1368,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13641368 // function we found.
13651369 err. span_suggestion_verbose (
13661370 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,
13711372 similar_candidate. name ,
13721373 Applicability :: MaybeIncorrect ,
13731374 ) ;
13741375 } 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) ;
13831377 }
13841378 } else if let Mode :: Path = mode
13851379 && args. unwrap_or ( & [ ] ) . is_empty ( )
13861380 {
13871381 // We have an associated item syntax and we found something that isn't an fn.
13881382 err. span_suggestion_verbose (
13891383 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,
13941385 similar_candidate. name ,
13951386 Applicability :: MaybeIncorrect ,
13961387 ) ;
13971388 } else {
13981389 // The expression is a function or method call, but the item we found is an
13991390 // 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) ;
14081392 }
14091393 }
14101394
0 commit comments