@@ -103,7 +103,7 @@ impl IntoDiagArg for PatternSource {
103
103
/// Denotes whether the context for the set of already bound bindings is a `Product`
104
104
/// or `Or` context. This is used in e.g., `fresh_binding` and `resolve_pattern_inner`.
105
105
/// See those functions for more information.
106
- #[ derive( PartialEq ) ]
106
+ #[ derive( PartialEq , Debug ) ]
107
107
enum PatBoundCtx {
108
108
/// A product pattern context, e.g., `Variant(a, b)`.
109
109
Product ,
@@ -217,6 +217,8 @@ pub(crate) enum RibKind<'ra> {
217
217
/// We passed through a `macro_rules!` statement
218
218
MacroDefinition ( DefId ) ,
219
219
220
+ LookAheadMacroDefinition ( DefId ) ,
221
+
220
222
/// All bindings in this rib are generic parameters that can't be used
221
223
/// from the default of a generic parameter because they're not declared
222
224
/// before said generic parameter. Also see the `visit_generics` override.
@@ -247,6 +249,7 @@ impl RibKind<'_> {
247
249
| RibKind :: ConstantItem ( ..)
248
250
| RibKind :: Module ( _)
249
251
| RibKind :: MacroDefinition ( _)
252
+ | RibKind :: LookAheadMacroDefinition ( _)
250
253
| RibKind :: InlineAsmSym => false ,
251
254
RibKind :: ConstParamTy
252
255
| RibKind :: AssocItem
@@ -258,7 +261,9 @@ impl RibKind<'_> {
258
261
/// This rib forbids referring to labels defined in upwards ribs.
259
262
fn is_label_barrier ( self ) -> bool {
260
263
match self {
261
- RibKind :: Normal | RibKind :: MacroDefinition ( ..) => false ,
264
+ RibKind :: Normal
265
+ | RibKind :: MacroDefinition ( ..)
266
+ | RibKind :: LookAheadMacroDefinition ( ..) => false ,
262
267
263
268
RibKind :: AssocItem
264
269
| RibKind :: FnOrCoroutine
@@ -3793,17 +3798,21 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3793
3798
3794
3799
/// Apply the bindings from a pattern to the innermost rib of the current scope.
3795
3800
fn apply_pattern_bindings ( & mut self , mut pat_bindings : PatternBindings ) {
3796
- let rib_bindings = self . innermost_rib_bindings ( ValueNS ) ;
3797
3801
let Some ( ( _, pat_bindings) ) = pat_bindings. pop ( ) else {
3798
3802
bug ! ( "tried applying nonexistent bindings from pattern" ) ;
3799
3803
} ;
3800
-
3801
- if rib_bindings. is_empty ( ) {
3802
- // Often, such as for match arms, the bindings are introduced into a new rib.
3803
- // In this case, we can move the bindings over directly.
3804
- * rib_bindings = pat_bindings;
3805
- } else {
3806
- rib_bindings. extend ( pat_bindings) ;
3804
+ for rib in self . ribs [ ValueNS ] . iter_mut ( ) . rev ( ) {
3805
+ let stop = !matches ! ( rib. kind, RibKind :: LookAheadMacroDefinition ( _) ) ;
3806
+ if rib. bindings . is_empty ( ) {
3807
+ // Often, such as for match arms, the bindings are introduced into a new rib.
3808
+ // In this case, we can move the bindings over directly.
3809
+ rib. bindings = pat_bindings. clone ( ) ;
3810
+ } else {
3811
+ rib. bindings . extend ( pat_bindings. clone ( ) ) ;
3812
+ }
3813
+ if stop {
3814
+ break ;
3815
+ }
3807
3816
}
3808
3817
}
3809
3818
@@ -4680,11 +4689,19 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4680
4689
&& let ItemKind :: MacroDef ( ..) = item. kind
4681
4690
{
4682
4691
num_macro_definition_ribs += 1 ;
4692
+ let res = self . r . local_def_id ( item. id ) . to_def_id ( ) ;
4693
+ self . ribs [ ValueNS ] . push ( Rib :: new ( RibKind :: LookAheadMacroDefinition ( res) ) ) ;
4694
+ }
4695
+ }
4696
+
4697
+ for stmt in & block. stmts {
4698
+ if let StmtKind :: Item ( ref item) = stmt. kind
4699
+ && let ItemKind :: MacroDef ( ..) = item. kind
4700
+ {
4683
4701
let res = self . r . local_def_id ( item. id ) . to_def_id ( ) ;
4684
4702
self . ribs [ ValueNS ] . push ( Rib :: new ( RibKind :: MacroDefinition ( res) ) ) ;
4685
4703
self . label_ribs . push ( Rib :: new ( RibKind :: MacroDefinition ( res) ) ) ;
4686
4704
}
4687
-
4688
4705
self . visit_stmt ( stmt) ;
4689
4706
}
4690
4707
@@ -4694,6 +4711,10 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4694
4711
self . ribs [ ValueNS ] . pop ( ) ;
4695
4712
self . label_ribs . pop ( ) ;
4696
4713
}
4714
+ for _ in 0 ..num_macro_definition_ribs {
4715
+ // pop `RibKind::LookAheadMacroDefinition`
4716
+ self . ribs [ ValueNS ] . pop ( ) ;
4717
+ }
4697
4718
self . last_block_rib = self . ribs [ ValueNS ] . pop ( ) ;
4698
4719
if anonymous_module. is_some ( ) {
4699
4720
self . ribs [ TypeNS ] . pop ( ) ;
0 commit comments