@@ -1576,12 +1576,21 @@ impl<'a> Resolver<'a> {
1576
1576
1577
1577
/// Searches the current set of local scopes for labels.
1578
1578
/// Stops after meeting a closure.
1579
- fn search_label ( & self , ident : ast:: Ident ) -> Option < Def > {
1579
+ fn search_label ( & self , mut ident : ast:: Ident ) -> Option < Def > {
1580
1580
for rib in self . label_ribs . iter ( ) . rev ( ) {
1581
1581
match rib. kind {
1582
1582
NormalRibKind => {
1583
1583
// Continue
1584
1584
}
1585
+ MacroDefinition ( mac) => {
1586
+ // If an invocation of this macro created `ident`, give up on `ident`
1587
+ // and switch to `ident`'s source from the macro definition.
1588
+ if let Some ( ( source_ident, source_macro) ) = mtwt:: source ( ident) {
1589
+ if mac == source_macro {
1590
+ ident = source_ident;
1591
+ }
1592
+ }
1593
+ }
1585
1594
_ => {
1586
1595
// Do not resolve labels across function boundary
1587
1596
return None ;
@@ -2088,7 +2097,7 @@ impl<'a> Resolver<'a> {
2088
2097
let orig_module = self . current_module ;
2089
2098
let anonymous_module = self . module_map . get ( & block. id ) . cloned ( ) ; // clones a reference
2090
2099
2091
- let mut num_value_ribs = 1 ;
2100
+ let mut num_macro_definition_ribs = 0 ;
2092
2101
if let Some ( anonymous_module) = anonymous_module {
2093
2102
debug ! ( "(resolving block) found anonymous module, moving down" ) ;
2094
2103
self . value_ribs . push ( Rib :: new ( ModuleRibKind ( anonymous_module) ) ) ;
@@ -2101,9 +2110,10 @@ impl<'a> Resolver<'a> {
2101
2110
// Descend into the block.
2102
2111
for stmt in & block. stmts {
2103
2112
if let Some ( marks) = self . macros_at_scope . remove ( & stmt. id ) {
2104
- num_value_ribs += marks. len ( ) as u32 ;
2113
+ num_macro_definition_ribs += marks. len ( ) as u32 ;
2105
2114
for mark in marks {
2106
2115
self . value_ribs . push ( Rib :: new ( MacroDefinition ( mark) ) ) ;
2116
+ self . label_ribs . push ( Rib :: new ( MacroDefinition ( mark) ) ) ;
2107
2117
}
2108
2118
}
2109
2119
@@ -2112,9 +2122,11 @@ impl<'a> Resolver<'a> {
2112
2122
2113
2123
// Move back up.
2114
2124
self . current_module = orig_module;
2115
- for _ in 0 .. num_value_ribs {
2125
+ for _ in 0 .. num_macro_definition_ribs {
2116
2126
self . value_ribs . pop ( ) ;
2127
+ self . label_ribs . pop ( ) ;
2117
2128
}
2129
+ self . value_ribs . pop ( ) ;
2118
2130
if let Some ( _) = anonymous_module {
2119
2131
self . type_ribs . pop ( ) ;
2120
2132
}
0 commit comments