@@ -4670,6 +4670,34 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
46704670 }
46714671 }
46724672
4673+ fn binding_description ( & self , b : & NameBinding , ident : Ident , from_prelude : bool ) -> String {
4674+ if b. span . is_dummy ( ) {
4675+ let add_built_in = match b. def ( ) {
4676+ // These already contain the "built-in" prefix or look bad with it.
4677+ Def :: NonMacroAttr ( ..) | Def :: PrimTy ( ..) | Def :: ToolMod => false ,
4678+ _ => true ,
4679+ } ;
4680+ let ( built_in, from) = if from_prelude {
4681+ ( "" , " from prelude" )
4682+ } else if b. is_extern_crate ( ) && !b. is_import ( ) &&
4683+ self . session . opts . externs . get ( & ident. as_str ( ) ) . is_some ( ) {
4684+ ( "" , " passed with `--extern`" )
4685+ } else if add_built_in {
4686+ ( " built-in" , "" )
4687+ } else {
4688+ ( "" , "" )
4689+ } ;
4690+
4691+ let article = if built_in. is_empty ( ) { b. article ( ) } else { "a" } ;
4692+ format ! ( "{a}{built_in} {thing}{from}" ,
4693+ a = article, thing = b. descr( ) , built_in = built_in, from = from)
4694+ } else {
4695+ let introduced = if b. is_import ( ) { "imported" } else { "defined" } ;
4696+ format ! ( "the {thing} {introduced} here" ,
4697+ thing = b. descr( ) , introduced = introduced)
4698+ }
4699+ }
4700+
46734701 fn report_ambiguity_error ( & self , ambiguity_error : & AmbiguityError ) {
46744702 let AmbiguityError { kind, ident, b1, b2, misc1, misc2 } = * ambiguity_error;
46754703 let ( b1, b2, misc1, misc2, swapped) = if b2. span . is_dummy ( ) && !b1. span . is_dummy ( ) {
@@ -4685,31 +4713,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
46854713 err. span_label ( ident. span , "ambiguous name" ) ;
46864714
46874715 let mut could_refer_to = |b : & NameBinding , misc : AmbiguityErrorMisc , also : & str | {
4688- let what = if b. span . is_dummy ( ) {
4689- let add_built_in = match b. def ( ) {
4690- // These already contain the "built-in" prefix or look bad with it.
4691- Def :: NonMacroAttr ( ..) | Def :: PrimTy ( ..) | Def :: ToolMod => false ,
4692- _ => true ,
4693- } ;
4694- let ( built_in, from) = if misc == AmbiguityErrorMisc :: FromPrelude {
4695- ( "" , " from prelude" )
4696- } else if b. is_extern_crate ( ) && !b. is_import ( ) &&
4697- self . session . opts . externs . get ( & ident. as_str ( ) ) . is_some ( ) {
4698- ( "" , " passed with `--extern`" )
4699- } else if add_built_in {
4700- ( " built-in" , "" )
4701- } else {
4702- ( "" , "" )
4703- } ;
4704-
4705- let article = if built_in. is_empty ( ) { b. article ( ) } else { "a" } ;
4706- format ! ( "{a}{built_in} {thing}{from}" ,
4707- a = article, thing = b. descr( ) , built_in = built_in, from = from)
4708- } else {
4709- let participle = if b. is_import ( ) { "imported" } else { "defined" } ;
4710- format ! ( "the {thing} {introduced} here" ,
4711- thing = b. descr( ) , introduced = participle)
4712- } ;
4716+ let what = self . binding_description ( b, ident, misc == AmbiguityErrorMisc :: FromPrelude ) ;
47134717 let note_msg = format ! ( "`{ident}` could{also} refer to {what}" ,
47144718 ident = ident, also = also, what = what) ;
47154719
0 commit comments