@@ -242,9 +242,6 @@ pub(crate) enum RibKind<'ra> {
242242 /// We passed through a module item.
243243 Module ( Module < ' ra > ) ,
244244
245- /// We passed through a `macro_rules!` statement
246- MacroDefinition ( DefId ) ,
247-
248245 /// All bindings in this rib are generic parameters that can't be used
249246 /// from the default of a generic parameter because they're not declared
250247 /// before said generic parameter. Also see the `visit_generics` override.
@@ -275,7 +272,6 @@ impl RibKind<'_> {
275272 | RibKind :: FnOrCoroutine
276273 | RibKind :: ConstantItem ( ..)
277274 | RibKind :: Module ( _)
278- | RibKind :: MacroDefinition ( _)
279275 | RibKind :: InlineAsmSym => false ,
280276 RibKind :: ConstParamTy
281277 | RibKind :: AssocItem
@@ -287,7 +283,7 @@ impl RibKind<'_> {
287283 /// This rib forbids referring to labels defined in upwards ribs.
288284 fn is_label_barrier ( self ) -> bool {
289285 match self {
290- RibKind :: Normal | RibKind :: MacroDefinition ( .. ) => false ,
286+ RibKind :: Normal | RibKind :: Block { .. } => false ,
291287 RibKind :: FnOrCoroutine | RibKind :: ConstantItem ( ..) => true ,
292288 kind => bug ! ( "unexpected rib kind: {kind:?}" ) ,
293289 }
@@ -2487,12 +2483,18 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
24872483 for i in ( 0 ..self . label_ribs . len ( ) ) . rev ( ) {
24882484 let rib = & self . label_ribs [ i] ;
24892485
2490- if let RibKind :: MacroDefinition ( def) = rib. kind
2491- // If an invocation of this macro created `ident`, give up on `ident`
2492- // and switch to `ident`'s source from the macro definition.
2493- && def == self . r . macro_def ( label. span . ctxt ( ) )
2486+ if let RibKind :: Block { id, .. } = rib. kind
2487+ && let Some ( items) = self . r . lookahead_items_in_block . get ( & id)
24942488 {
2495- label. span . remove_mark ( ) ;
2489+ for ( _, item) in items. iter ( ) . rev ( ) {
2490+ if let LookaheadItemInBlock :: MacroDef { def_id, .. } = item
2491+ && * def_id == self . r . macro_def ( label. span . ctxt ( ) )
2492+ {
2493+ // If an invocation of this macro created `ident`, give up on `ident`
2494+ // and switch to `ident`'s source from the macro definition.
2495+ label. span . remove_mark ( ) ;
2496+ }
2497+ }
24962498 }
24972499
24982500 let ident = label. normalize_to_macro_rules ( ) ;
@@ -4761,36 +4763,27 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
47614763 let orig_module = self . parent_scope . module ;
47624764 let anonymous_module = self . r . block_map . get ( & block. id ) . copied ( ) ;
47634765
4764- let mut num_macro_definition_ribs = 0 ;
47654766 if let Some ( anonymous_module) = anonymous_module {
47664767 debug ! ( "(resolving block) found anonymous module, moving down" ) ;
47674768 let rib_kind = RibKind :: Block { module : Some ( anonymous_module) , id : block. id } ;
47684769 self . ribs [ ValueNS ] . push ( Rib :: new ( rib_kind) ) ;
47694770 self . ribs [ TypeNS ] . push ( Rib :: new ( rib_kind) ) ;
4771+ self . label_ribs . push ( Rib :: new ( rib_kind) ) ;
47704772 self . parent_scope . module = anonymous_module;
47714773 } else {
4772- self . ribs [ ValueNS ] . push ( Rib :: new ( RibKind :: Block { module : None , id : block. id } ) ) ;
4774+ let rib_kind = RibKind :: Block { module : None , id : block. id } ;
4775+ self . ribs [ ValueNS ] . push ( Rib :: new ( rib_kind) ) ;
4776+ self . label_ribs . push ( Rib :: new ( rib_kind) ) ;
47734777 }
47744778
47754779 // Descend into the block.
47764780 for stmt in & block. stmts {
4777- if let StmtKind :: Item ( ref item) = stmt. kind
4778- && let ItemKind :: MacroDef ( ..) = item. kind
4779- {
4780- num_macro_definition_ribs += 1 ;
4781- let res = self . r . local_def_id ( item. id ) . to_def_id ( ) ;
4782- self . label_ribs . push ( Rib :: new ( RibKind :: MacroDefinition ( res) ) ) ;
4783- }
4784-
47854781 self . visit_stmt ( stmt) ;
47864782 }
47874783
47884784 // Move back up.
47894785 self . parent_scope . module = orig_module;
4790- for _ in 0 ..num_macro_definition_ribs {
4791- // pop `MacroDefinition`
4792- self . label_ribs . pop ( ) ;
4793- }
4786+ self . label_ribs . pop ( ) ;
47944787 self . last_block_rib = self . ribs [ ValueNS ] . pop ( ) ;
47954788 if anonymous_module. is_some ( ) {
47964789 self . ribs [ TypeNS ] . pop ( ) ;
0 commit comments