1
Fork 0

Expand nested items within a backtrace.

Fixes a regression from #4913 which causes items to be exanded with spans lacking expn_info from the context's current backtrace.
This commit is contained in:
Nick Cameron 2014-03-03 10:12:40 -08:00
parent 0a5138c752
commit 4a891fe80d
2 changed files with 15 additions and 6 deletions

View file

@ -248,7 +248,7 @@ macro_rules! with_exts_frame (
// When we enter a module, record it, for the sake of `module!` // When we enter a module, record it, for the sake of `module!`
pub fn expand_item(it: @ast::Item, fld: &mut MacroExpander) pub fn expand_item(it: @ast::Item, fld: &mut MacroExpander)
-> SmallVector<@ast::Item> { -> SmallVector<@ast::Item> {
let mut decorator_items = SmallVector::zero(); let mut decorator_items: SmallVector<@ast::Item> = SmallVector::zero();
for attr in it.attrs.rev_iter() { for attr in it.attrs.rev_iter() {
let mname = attr.name(); let mname = attr.name();
@ -262,20 +262,21 @@ pub fn expand_item(it: @ast::Item, fld: &mut MacroExpander)
span: None span: None
} }
}); });
// we'd ideally decorator_items.push_all(expand_item(item, fld)), // we'd ideally decorator_items.push_all(expand_item(item, fld)),
// but that double-mut-borrows fld // but that double-mut-borrows fld
let mut items: SmallVector<@ast::Item> = SmallVector::zero();
dec_fn(fld.cx, attr.span, attr.node.value, it, dec_fn(fld.cx, attr.span, attr.node.value, it,
|item| decorator_items.push(item)); |item| items.push(item));
decorator_items.extend(&mut items.move_iter()
.flat_map(|item| expand_item(item, fld).move_iter()));
fld.cx.bt_pop(); fld.cx.bt_pop();
} }
_ => {} _ => {}
} }
} }
let decorator_items = decorator_items.move_iter()
.flat_map(|item| expand_item(item, fld).move_iter())
.collect();
let mut new_items = match it.node { let mut new_items = match it.node {
ast::ItemMac(..) => expand_item_mac(it, fld), ast::ItemMac(..) => expand_item_mac(it, fld),
ast::ItemMod(_) | ast::ItemForeignMod(_) => { ast::ItemMod(_) | ast::ItemForeignMod(_) => {

View file

@ -39,6 +39,14 @@ impl<T> FromIterator<T> for SmallVector<T> {
} }
} }
impl<T> Extendable<T> for SmallVector<T> {
fn extend<I: Iterator<T>>(&mut self, iter: &mut I) {
for val in *iter {
self.push(val);
}
}
}
impl<T> SmallVector<T> { impl<T> SmallVector<T> {
pub fn zero() -> SmallVector<T> { pub fn zero() -> SmallVector<T> {
Zero Zero