@@ -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 } ;
@@ -1456,6 +1459,24 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1456
1459
return ;
1457
1460
}
1458
1461
1462
+ let unused_macro = self . unused_macros . iter ( ) . find_map ( |( def_id, ( _, unused_ident) ) | {
1463
+ if unused_ident. name == ident. name {
1464
+ Some ( ( def_id. clone ( ) , unused_ident. clone ( ) ) )
1465
+ } else {
1466
+ None
1467
+ }
1468
+ } ) ;
1469
+
1470
+ if let Some ( ( def_id, unused_ident) ) = unused_macro {
1471
+ let scope = self . local_macro_def_scopes [ & def_id] ;
1472
+ let parent_nearest = parent_scope. module . nearest_parent_mod ( ) ;
1473
+ if Some ( parent_nearest) == scope. opt_def_id ( ) {
1474
+ err. subdiagnostic ( self . dcx ( ) , MacroDefinedLater { span : unused_ident. span } ) ;
1475
+ err. subdiagnostic ( self . dcx ( ) , MacroSuggMovePosition { span : ident. span , ident } ) ;
1476
+ return ;
1477
+ }
1478
+ }
1479
+
1459
1480
if self . macro_names . contains ( & ident. normalize_to_macros_2_0 ( ) ) {
1460
1481
err. subdiagnostic ( self . dcx ( ) , AddedMacroUse ) ;
1461
1482
return ;
0 commit comments