@@ -30,7 +30,10 @@ use rustc_span::{BytePos, Span, SyntaxContext};
30
30
use thin_vec:: { thin_vec, ThinVec } ;
31
31
32
32
use crate :: errors:: { AddedMacroUse , ChangeImportBinding , ChangeImportBindingSuggestion } ;
33
- use crate :: errors:: { ConsiderAddingADerive , ExplicitUnsafeTraits , MaybeMissingMacroRulesName } ;
33
+ use crate :: errors:: {
34
+ ConsiderAddingADerive , ExplicitUnsafeTraits , MacroDefinedLater , MacroSuggMovePosition ,
35
+ MaybeMissingMacroRulesName ,
36
+ } ;
34
37
use crate :: imports:: { Import , ImportKind } ;
35
38
use crate :: late:: { PatternSource , Rib } ;
36
39
use crate :: { errors as errs, BindingKey } ;
@@ -1442,6 +1445,24 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1442
1445
return ;
1443
1446
}
1444
1447
1448
+ let unused_macro = self . unused_macros . iter ( ) . find_map ( |( def_id, ( _, unused_ident) ) | {
1449
+ if unused_ident. name == ident. name {
1450
+ Some ( ( def_id. clone ( ) , unused_ident. clone ( ) ) )
1451
+ } else {
1452
+ None
1453
+ }
1454
+ } ) ;
1455
+
1456
+ if let Some ( ( def_id, unused_ident) ) = unused_macro {
1457
+ let scope = self . local_macro_def_scopes [ & def_id] ;
1458
+ let parent_nearest = parent_scope. module . nearest_parent_mod ( ) ;
1459
+ if Some ( parent_nearest) == scope. opt_def_id ( ) {
1460
+ err. subdiagnostic ( self . dcx ( ) , MacroDefinedLater { span : unused_ident. span } ) ;
1461
+ err. subdiagnostic ( self . dcx ( ) , MacroSuggMovePosition { span : ident. span , ident } ) ;
1462
+ return ;
1463
+ }
1464
+ }
1465
+
1445
1466
if self . macro_names . contains ( & ident. normalize_to_macros_2_0 ( ) ) {
1446
1467
err. subdiagnostic ( self . dcx ( ) , AddedMacroUse ) ;
1447
1468
return ;
0 commit comments