@@ -27,10 +27,8 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
27
27
use rustc_span:: { BytePos , Span , SyntaxContext } ;
28
28
use thin_vec:: { thin_vec, ThinVec } ;
29
29
30
- use crate :: errors:: {
31
- AddedMacroUse , ChangeImportBinding , ChangeImportBindingSuggestion , ConsiderAddingADerive ,
32
- ExplicitUnsafeTraits ,
33
- } ;
30
+ use crate :: errors:: { AddedMacroUse , ChangeImportBinding , ChangeImportBindingSuggestion } ;
31
+ use crate :: errors:: { ConsiderAddingADerive , ExplicitUnsafeTraits , MaybeMissingMacroRulesName } ;
34
32
use crate :: imports:: { Import , ImportKind } ;
35
33
use crate :: late:: { PatternSource , Rib } ;
36
34
use crate :: path_names_to_string;
@@ -1421,14 +1419,42 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1421
1419
"" ,
1422
1420
) ;
1423
1421
1422
+ if macro_kind == MacroKind :: Bang
1423
+ && ident. name == sym:: macro_rules
1424
+ && let source_map = self . tcx . sess . source_map ( )
1425
+ && let Ok ( next_source) = source_map. span_to_next_source ( ident. span )
1426
+ && let Some ( brace_offset) = {
1427
+ // find the first `{`
1428
+ let chars = next_source. chars ( ) . collect :: < Vec < _ > > ( ) ;
1429
+ if chars. len ( ) < 2 || chars[ 0 ] != '!' {
1430
+ None
1431
+ } else {
1432
+ let mut idx = 1 ;
1433
+ while idx < chars. len ( ) && chars[ idx] . is_ascii_whitespace ( ) {
1434
+ idx += 1 ;
1435
+ }
1436
+ ( idx < chars. len ( ) && chars[ idx] == '{' ) . then_some ( idx)
1437
+ }
1438
+ }
1439
+ {
1440
+ let bang_pos = ident. span . hi ( ) . 0 ;
1441
+ let lo = bang_pos + 1 ; // the pos after `!`
1442
+ let hi = bang_pos + brace_offset as u32 ; // the pos of '{'
1443
+ let span = ident. span . with_hi ( BytePos ( hi) ) . with_lo ( BytePos ( lo) ) ;
1444
+ err. subdiagnostic ( MaybeMissingMacroRulesName { span } ) ;
1445
+ return ;
1446
+ }
1447
+
1424
1448
if macro_kind == MacroKind :: Derive && ( ident. name == sym:: Send || ident. name == sym:: Sync ) {
1425
1449
err. subdiagnostic ( ExplicitUnsafeTraits { span : ident. span , ident } ) ;
1426
1450
return ;
1427
1451
}
1452
+
1428
1453
if self . macro_names . contains ( & ident. normalize_to_macros_2_0 ( ) ) {
1429
1454
err. subdiagnostic ( AddedMacroUse ) ;
1430
1455
return ;
1431
1456
}
1457
+
1432
1458
if ident. name == kw:: Default
1433
1459
&& let ModuleKind :: Def ( DefKind :: Enum , def_id, _) = parent_scope. module . kind
1434
1460
{
0 commit comments