@@ -190,12 +190,12 @@ impl<'a> Resolver<'a> {
190
190
ModuleKind :: Block => "block" ,
191
191
} ;
192
192
193
- let old_noun = match old_binding. is_import ( ) {
193
+ let old_noun = match old_binding. is_import_user_facing ( ) {
194
194
true => "import" ,
195
195
false => "definition" ,
196
196
} ;
197
197
198
- let new_participle = match new_binding. is_import ( ) {
198
+ let new_participle = match new_binding. is_import_user_facing ( ) {
199
199
true => "imported" ,
200
200
false => "defined" ,
201
201
} ;
@@ -226,7 +226,7 @@ impl<'a> Resolver<'a> {
226
226
true => struct_span_err ! ( self . session, span, E0254 , "{}" , msg) ,
227
227
false => struct_span_err ! ( self . session, span, E0260 , "{}" , msg) ,
228
228
} ,
229
- _ => match ( old_binding. is_import ( ) , new_binding. is_import ( ) ) {
229
+ _ => match ( old_binding. is_import_user_facing ( ) , new_binding. is_import_user_facing ( ) ) {
230
230
( false , false ) => struct_span_err ! ( self . session, span, E0428 , "{}" , msg) ,
231
231
( true , true ) => struct_span_err ! ( self . session, span, E0252 , "{}" , msg) ,
232
232
_ => struct_span_err ! ( self . session, span, E0255 , "{}" , msg) ,
@@ -248,14 +248,18 @@ impl<'a> Resolver<'a> {
248
248
249
249
// See https://github.com/rust-lang/rust/issues/32354
250
250
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
+ } ;
251
255
let import = match ( & new_binding. kind , & old_binding. kind ) {
252
256
// If there are two imports where one or both have attributes then prefer removing the
253
257
// import without attributes.
254
258
( Import { import : new, .. } , Import { import : old, .. } )
255
259
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 )
259
263
} =>
260
264
{
261
265
if old. has_attributes {
@@ -265,10 +269,10 @@ impl<'a> Resolver<'a> {
265
269
}
266
270
}
267
271
// 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 ) => {
269
273
Some ( ( import, new_binding. span , other. is_import ( ) ) )
270
274
}
271
- ( other, Import { import, .. } ) if !old_binding . span . is_dummy ( ) => {
275
+ ( other, Import { import, .. } ) if can_suggest ( old_binding , import ) => {
272
276
Some ( ( import, old_binding. span , other. is_import ( ) ) )
273
277
}
274
278
_ => None ,
@@ -1683,7 +1687,7 @@ impl<'a> Resolver<'a> {
1683
1687
let a = if built_in. is_empty ( ) { res. article ( ) } else { "a" } ;
1684
1688
format ! ( "{a}{built_in} {thing}{from}" , thing = res. descr( ) )
1685
1689
} else {
1686
- let introduced = if b. is_import ( ) { "imported" } else { "defined" } ;
1690
+ let introduced = if b. is_import_user_facing ( ) { "imported" } else { "defined" } ;
1687
1691
format ! ( "the {thing} {introduced} here" , thing = res. descr( ) )
1688
1692
}
1689
1693
}
@@ -1742,10 +1746,10 @@ impl<'a> Resolver<'a> {
1742
1746
/// If the binding refers to a tuple struct constructor with fields,
1743
1747
/// returns the span of its fields.
1744
1748
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
1749
1753
{
1750
1754
let def_id = self . parent ( ctor_def_id) ;
1751
1755
let fields = self . field_names . get ( & def_id) ?;
@@ -1789,7 +1793,9 @@ impl<'a> Resolver<'a> {
1789
1793
next_ident = source;
1790
1794
Some ( binding)
1791
1795
}
1792
- ImportKind :: Glob { .. } | ImportKind :: MacroUse => Some ( binding) ,
1796
+ ImportKind :: Glob { .. } | ImportKind :: MacroUse | ImportKind :: MacroExport => {
1797
+ Some ( binding)
1798
+ }
1793
1799
ImportKind :: ExternCrate { .. } => None ,
1794
1800
} ,
1795
1801
_ => None ,
0 commit comments