Skip to content

Commit c83e31e

Browse files
committed
Include the MacroDefinition rib in the label ribs.
1 parent 56c4ddf commit c83e31e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/librustc_resolve/lib.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -1576,12 +1576,21 @@ impl<'a> Resolver<'a> {
15761576

15771577
/// Searches the current set of local scopes for labels.
15781578
/// 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> {
15801580
for rib in self.label_ribs.iter().rev() {
15811581
match rib.kind {
15821582
NormalRibKind => {
15831583
// Continue
15841584
}
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+
}
15851594
_ => {
15861595
// Do not resolve labels across function boundary
15871596
return None;
@@ -2088,7 +2097,7 @@ impl<'a> Resolver<'a> {
20882097
let orig_module = self.current_module;
20892098
let anonymous_module = self.module_map.get(&block.id).cloned(); // clones a reference
20902099

2091-
let mut num_value_ribs = 1;
2100+
let mut num_macro_definition_ribs = 0;
20922101
if let Some(anonymous_module) = anonymous_module {
20932102
debug!("(resolving block) found anonymous module, moving down");
20942103
self.value_ribs.push(Rib::new(ModuleRibKind(anonymous_module)));
@@ -2101,9 +2110,10 @@ impl<'a> Resolver<'a> {
21012110
// Descend into the block.
21022111
for stmt in &block.stmts {
21032112
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;
21052114
for mark in marks {
21062115
self.value_ribs.push(Rib::new(MacroDefinition(mark)));
2116+
self.label_ribs.push(Rib::new(MacroDefinition(mark)));
21072117
}
21082118
}
21092119

@@ -2112,9 +2122,11 @@ impl<'a> Resolver<'a> {
21122122

21132123
// Move back up.
21142124
self.current_module = orig_module;
2115-
for _ in 0 .. num_value_ribs {
2125+
for _ in 0 .. num_macro_definition_ribs {
21162126
self.value_ribs.pop();
2127+
self.label_ribs.pop();
21172128
}
2129+
self.value_ribs.pop();
21182130
if let Some(_) = anonymous_module {
21192131
self.type_ribs.pop();
21202132
}

0 commit comments

Comments
 (0)