@@ -190,12 +190,12 @@ impl<'a> Resolver<'a> {
190190 ModuleKind :: Block => "block" ,
191191 } ;
192192
193- let old_noun = match old_binding. is_import ( ) {
193+ let old_noun = match old_binding. is_import_user_facing ( ) {
194194 true => "import" ,
195195 false => "definition" ,
196196 } ;
197197
198- let new_participle = match new_binding. is_import ( ) {
198+ let new_participle = match new_binding. is_import_user_facing ( ) {
199199 true => "imported" ,
200200 false => "defined" ,
201201 } ;
@@ -226,7 +226,7 @@ impl<'a> Resolver<'a> {
226226 true => struct_span_err ! ( self . session, span, E0254 , "{}" , msg) ,
227227 false => struct_span_err ! ( self . session, span, E0260 , "{}" , msg) ,
228228 } ,
229- _ => match ( old_binding. is_import ( ) , new_binding. is_import ( ) ) {
229+ _ => match ( old_binding. is_import_user_facing ( ) , new_binding. is_import_user_facing ( ) ) {
230230 ( false , false ) => struct_span_err ! ( self . session, span, E0428 , "{}" , msg) ,
231231 ( true , true ) => struct_span_err ! ( self . session, span, E0252 , "{}" , msg) ,
232232 _ => struct_span_err ! ( self . session, span, E0255 , "{}" , msg) ,
@@ -248,14 +248,18 @@ impl<'a> Resolver<'a> {
248248
249249 // See https://github.com/rust-lang/rust/issues/32354
250250 use NameBindingKind :: Import ;
251+ let can_suggest = |binding : & NameBinding < ' _ > , import : & self :: Import < ' _ > | {
252+ !binding. span . is_dummy ( )
253+ && !matches ! ( import. kind, ImportKind :: MacroUse | ImportKind :: MacroExport )
254+ } ;
251255 let import = match ( & new_binding. kind , & old_binding. kind ) {
252256 // If there are two imports where one or both have attributes then prefer removing the
253257 // import without attributes.
254258 ( Import { import : new, .. } , Import { import : old, .. } )
255259 if {
256- !new_binding . span . is_dummy ( )
257- && !old_binding . span . is_dummy ( )
258- && ( new . has_attributes || old . has_attributes )
260+ ( new . has_attributes || old . has_attributes )
261+ && can_suggest ( old_binding , old )
262+ && can_suggest ( new_binding , new )
259263 } =>
260264 {
261265 if old. has_attributes {
@@ -265,10 +269,10 @@ impl<'a> Resolver<'a> {
265269 }
266270 }
267271 // Otherwise prioritize the new binding.
268- ( Import { import, .. } , other) if !new_binding . span . is_dummy ( ) => {
272+ ( Import { import, .. } , other) if can_suggest ( new_binding , import ) => {
269273 Some ( ( import, new_binding. span , other. is_import ( ) ) )
270274 }
271- ( other, Import { import, .. } ) if !old_binding . span . is_dummy ( ) => {
275+ ( other, Import { import, .. } ) if can_suggest ( old_binding , import ) => {
272276 Some ( ( import, old_binding. span , other. is_import ( ) ) )
273277 }
274278 _ => None ,
@@ -1683,7 +1687,7 @@ impl<'a> Resolver<'a> {
16831687 let a = if built_in. is_empty ( ) { res. article ( ) } else { "a" } ;
16841688 format ! ( "{a}{built_in} {thing}{from}" , thing = res. descr( ) )
16851689 } else {
1686- let introduced = if b. is_import ( ) { "imported" } else { "defined" } ;
1690+ let introduced = if b. is_import_user_facing ( ) { "imported" } else { "defined" } ;
16871691 format ! ( "the {thing} {introduced} here" , thing = res. descr( ) )
16881692 }
16891693 }
@@ -1742,10 +1746,10 @@ impl<'a> Resolver<'a> {
17421746 /// If the binding refers to a tuple struct constructor with fields,
17431747 /// returns the span of its fields.
17441748 fn ctor_fields_span ( & self , binding : & NameBinding < ' _ > ) -> Option < Span > {
1745- if let NameBindingKind :: Res (
1746- Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , CtorKind :: Fn ) , ctor_def_id ) ,
1747- _ ,
1748- ) = binding. kind
1749+ if let NameBindingKind :: Res ( Res :: Def (
1750+ DefKind :: Ctor ( CtorOf :: Struct , CtorKind :: Fn ) ,
1751+ ctor_def_id ,
1752+ ) ) = binding. kind
17491753 {
17501754 let def_id = self . parent ( ctor_def_id) ;
17511755 let fields = self . field_names . get ( & def_id) ?;
@@ -1789,7 +1793,9 @@ impl<'a> Resolver<'a> {
17891793 next_ident = source;
17901794 Some ( binding)
17911795 }
1792- ImportKind :: Glob { .. } | ImportKind :: MacroUse => Some ( binding) ,
1796+ ImportKind :: Glob { .. } | ImportKind :: MacroUse | ImportKind :: MacroExport => {
1797+ Some ( binding)
1798+ }
17931799 ImportKind :: ExternCrate { .. } => None ,
17941800 } ,
17951801 _ => None ,
0 commit comments