@@ -1427,6 +1427,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14271427 let tcx = self . tcx ;
14281428 let def_kind = similar_candidate. kind . as_def_kind ( ) ;
14291429 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+ ) ;
14301435 // Methods are defined within the context of a struct and their first parameter
14311436 // is always `self`, which represents the instance of the struct the method is
14321437 // 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> {
14431448 // call expression the user wrote.
14441449 err. span_suggestion_verbose (
14451450 span,
1446- format ! ( "there is {an} method with a similar name" ) ,
1451+ msg ,
14471452 similar_candidate. name ,
14481453 Applicability :: MaybeIncorrect ,
14491454 ) ;
@@ -1453,8 +1458,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14531458 err. span_help (
14541459 tcx. def_span ( similar_candidate. def_id ) ,
14551460 format ! (
1456- "there is {an} method `{}` with a similar name{}" ,
1457- similar_candidate. name,
1461+ "{msg}{}" ,
14581462 if let None = args { "" } else { ", but with different arguments" } ,
14591463 ) ,
14601464 ) ;
@@ -1466,47 +1470,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14661470 // function we found.
14671471 err. span_suggestion_verbose (
14681472 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,
14731474 similar_candidate. name ,
14741475 Applicability :: MaybeIncorrect ,
14751476 ) ;
14761477 } 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) ;
14851479 }
14861480 } else if let Mode :: Path = mode
14871481 && args. unwrap_or ( & [ ] ) . is_empty ( )
14881482 {
14891483 // We have an associated item syntax and we found something that isn't an fn.
14901484 err. span_suggestion_verbose (
14911485 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,
14961487 similar_candidate. name ,
14971488 Applicability :: MaybeIncorrect ,
14981489 ) ;
14991490 } else {
15001491 // The expression is a function or method call, but the item we found is an
15011492 // 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) ;
15101494 }
15111495 }
15121496
0 commit comments