Skip to content

Commit 5b42f79

Browse files
author
Keegan McAllister
committed
Pop the expansion context after expanding a method macro
We were leaving these on the stack, causing spurious backtraces. I've confirmed that this test fails without the fix.
1 parent f85e4f7 commit 5b42f79

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/libsyntax/ext/expand.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,10 @@ fn expand_method(m: P<ast::Method>, fld: &mut MacroExpander) -> SmallVector<P<as
897897
};
898898

899899
// expand again if necessary
900-
new_methods.into_iter().flat_map(|m| fld.fold_method(m).into_iter()).collect()
900+
let new_methods = new_methods.move_iter()
901+
.flat_map(|m| fld.fold_method(m).into_iter()).collect();
902+
fld.cx.bt_pop();
903+
new_methods
901904
}
902905
})
903906
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// forbid-output: in expansion of
12+
13+
#![feature(macro_rules)]
14+
15+
macro_rules! make_method ( ($name:ident) => (
16+
fn $name(&self) { }
17+
))
18+
19+
struct S;
20+
21+
impl S {
22+
// We had a bug where these wouldn't clean up macro backtrace frames.
23+
make_method!(foo1)
24+
make_method!(foo2)
25+
make_method!(foo3)
26+
make_method!(foo4)
27+
make_method!(foo5)
28+
make_method!(foo6)
29+
make_method!(foo7)
30+
make_method!(foo8)
31+
32+
// Cause an error. It shouldn't have any macro backtrace frames.
33+
fn bar(&self) { }
34+
fn bar(&self) { } //~ ERROR duplicate definition
35+
}
36+
37+
fn main() { }

0 commit comments

Comments
 (0)