Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand nested items within a backtrace. #12671

Merged
merged 1 commit into from
Mar 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ macro_rules! with_exts_frame (
// When we enter a module, record it, for the sake of `module!`
pub fn expand_item(it: @ast::Item, fld: &mut MacroExpander)
-> 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() {
let mname = attr.name();

Expand All @@ -262,20 +262,21 @@ pub fn expand_item(it: @ast::Item, fld: &mut MacroExpander)
span: None
}
});

// we'd ideally decorator_items.push_all(expand_item(item, 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,
|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();
}
_ => {}
}
}

let decorator_items = decorator_items.move_iter()
.flat_map(|item| expand_item(item, fld).move_iter())
.collect();

let mut new_items = match it.node {
ast::ItemMac(..) => expand_item_mac(it, fld),
ast::ItemMod(_) | ast::ItemForeignMod(_) => {
Expand Down
8 changes: 8 additions & 0 deletions src/libsyntax/util/small_vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
pub fn zero() -> SmallVector<T> {
Zero
Expand Down