@@ -242,9 +242,6 @@ pub(crate) enum RibKind<'ra> {
242
242
/// We passed through a module item.
243
243
Module ( Module < ' ra > ) ,
244
244
245
- /// We passed through a `macro_rules!` statement
246
- MacroDefinition ( DefId ) ,
247
-
248
245
/// All bindings in this rib are generic parameters that can't be used
249
246
/// from the default of a generic parameter because they're not declared
250
247
/// before said generic parameter. Also see the `visit_generics` override.
@@ -275,7 +272,6 @@ impl RibKind<'_> {
275
272
| RibKind :: FnOrCoroutine
276
273
| RibKind :: ConstantItem ( ..)
277
274
| RibKind :: Module ( _)
278
- | RibKind :: MacroDefinition ( _)
279
275
| RibKind :: InlineAsmSym => false ,
280
276
RibKind :: ConstParamTy
281
277
| RibKind :: AssocItem
@@ -287,7 +283,7 @@ impl RibKind<'_> {
287
283
/// This rib forbids referring to labels defined in upwards ribs.
288
284
fn is_label_barrier ( self ) -> bool {
289
285
match self {
290
- RibKind :: Normal | RibKind :: MacroDefinition ( .. ) => false ,
286
+ RibKind :: Normal | RibKind :: Block { .. } => false ,
291
287
RibKind :: FnOrCoroutine | RibKind :: ConstantItem ( ..) => true ,
292
288
kind => bug ! ( "unexpected rib kind: {kind:?}" ) ,
293
289
}
@@ -2487,12 +2483,18 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
2487
2483
for i in ( 0 ..self . label_ribs . len ( ) ) . rev ( ) {
2488
2484
let rib = & self . label_ribs [ i] ;
2489
2485
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)
2494
2488
{
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
+ }
2496
2498
}
2497
2499
2498
2500
let ident = label. normalize_to_macro_rules ( ) ;
@@ -4761,36 +4763,27 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4761
4763
let orig_module = self . parent_scope . module ;
4762
4764
let anonymous_module = self . r . block_map . get ( & block. id ) . copied ( ) ;
4763
4765
4764
- let mut num_macro_definition_ribs = 0 ;
4765
4766
if let Some ( anonymous_module) = anonymous_module {
4766
4767
debug ! ( "(resolving block) found anonymous module, moving down" ) ;
4767
4768
let rib_kind = RibKind :: Block { module : Some ( anonymous_module) , id : block. id } ;
4768
4769
self . ribs [ ValueNS ] . push ( Rib :: new ( rib_kind) ) ;
4769
4770
self . ribs [ TypeNS ] . push ( Rib :: new ( rib_kind) ) ;
4771
+ self . label_ribs . push ( Rib :: new ( rib_kind) ) ;
4770
4772
self . parent_scope . module = anonymous_module;
4771
4773
} 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) ) ;
4773
4777
}
4774
4778
4775
4779
// Descend into the block.
4776
4780
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
-
4785
4781
self . visit_stmt ( stmt) ;
4786
4782
}
4787
4783
4788
4784
// Move back up.
4789
4785
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 ( ) ;
4794
4787
self . last_block_rib = self . ribs [ ValueNS ] . pop ( ) ;
4795
4788
if anonymous_module. is_some ( ) {
4796
4789
self . ribs [ TypeNS ] . pop ( ) ;
0 commit comments