@@ -4736,6 +4736,34 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
47364736 }
47374737 }
47384738
4739+ fn binding_description ( & self , b : & NameBinding , ident : Ident , from_prelude : bool ) -> String {
4740+ if b. span . is_dummy ( ) {
4741+ let add_built_in = match b. def ( ) {
4742+ // These already contain the "built-in" prefix or look bad with it.
4743+ Def :: NonMacroAttr ( ..) | Def :: PrimTy ( ..) | Def :: ToolMod => false ,
4744+ _ => true ,
4745+ } ;
4746+ let ( built_in, from) = if from_prelude {
4747+ ( "" , " from prelude" )
4748+ } else if b. is_extern_crate ( ) && !b. is_import ( ) &&
4749+ self . session . opts . externs . get ( & ident. as_str ( ) ) . is_some ( ) {
4750+ ( "" , " passed with `--extern`" )
4751+ } else if add_built_in {
4752+ ( " built-in" , "" )
4753+ } else {
4754+ ( "" , "" )
4755+ } ;
4756+
4757+ let article = if built_in. is_empty ( ) { b. article ( ) } else { "a" } ;
4758+ format ! ( "{a}{built_in} {thing}{from}" ,
4759+ a = article, thing = b. descr( ) , built_in = built_in, from = from)
4760+ } else {
4761+ let introduced = if b. is_import ( ) { "imported" } else { "defined" } ;
4762+ format ! ( "the {thing} {introduced} here" ,
4763+ thing = b. descr( ) , introduced = introduced)
4764+ }
4765+ }
4766+
47394767 fn report_ambiguity_error ( & self , ambiguity_error : & AmbiguityError ) {
47404768 let AmbiguityError { kind, ident, b1, b2, misc1, misc2 } = * ambiguity_error;
47414769 let ( b1, b2, misc1, misc2, swapped) = if b2. span . is_dummy ( ) && !b1. span . is_dummy ( ) {
@@ -4751,31 +4779,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
47514779 err. span_label ( ident. span , "ambiguous name" ) ;
47524780
47534781 let mut could_refer_to = |b : & NameBinding , misc : AmbiguityErrorMisc , also : & str | {
4754- let what = if b. span . is_dummy ( ) {
4755- let add_built_in = match b. def ( ) {
4756- // These already contain the "built-in" prefix or look bad with it.
4757- Def :: NonMacroAttr ( ..) | Def :: PrimTy ( ..) | Def :: ToolMod => false ,
4758- _ => true ,
4759- } ;
4760- let ( built_in, from) = if misc == AmbiguityErrorMisc :: FromPrelude {
4761- ( "" , " from prelude" )
4762- } else if b. is_extern_crate ( ) && !b. is_import ( ) &&
4763- self . session . opts . externs . get ( & ident. as_str ( ) ) . is_some ( ) {
4764- ( "" , " passed with `--extern`" )
4765- } else if add_built_in {
4766- ( " built-in" , "" )
4767- } else {
4768- ( "" , "" )
4769- } ;
4770-
4771- let article = if built_in. is_empty ( ) { b. article ( ) } else { "a" } ;
4772- format ! ( "{a}{built_in} {thing}{from}" ,
4773- a = article, thing = b. descr( ) , built_in = built_in, from = from)
4774- } else {
4775- let participle = if b. is_import ( ) { "imported" } else { "defined" } ;
4776- format ! ( "the {thing} {introduced} here" ,
4777- thing = b. descr( ) , introduced = participle)
4778- } ;
4782+ let what = self . binding_description ( b, ident, misc == AmbiguityErrorMisc :: FromPrelude ) ;
47794783 let note_msg = format ! ( "`{ident}` could{also} refer to {what}" ,
47804784 ident = ident, also = also, what = what) ;
47814785
0 commit comments