Skip to content

Commit f630419

Browse files
committed
Fix bug in macro expression spans
1 parent 30422de commit f630419

File tree

6 files changed

+24
-28
lines changed

6 files changed

+24
-28
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,9 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
7070

7171
// Keep going, outside-in.
7272
let fully_expanded = fld.fold_expr(expanded_expr);
73-
let span = fld.new_span(span);
7473
fld.cx.bt_pop();
7574

76-
fully_expanded.map(|e| ast::Expr {
77-
id: ast::DUMMY_NODE_ID,
78-
node: e.node,
79-
span: span,
80-
attrs: e.attrs,
81-
})
75+
fully_expanded
8276
}
8377

8478
ast::ExprKind::InPlace(placer, value_expr) => {

src/test/compile-fail/borrowck/borrowck-borrowed-uniq-rvalue-2.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// error-pattern: borrowed value does not live long enough
12+
1113
struct defer<'a> {
1214
x: &'a [&'a str],
1315
}
@@ -28,6 +30,5 @@ fn defer<'r>(x: &'r [&'r str]) -> defer<'r> {
2830

2931
fn main() {
3032
let x = defer(&vec!("Goodbye", "world!"));
31-
//~^ ERROR borrowed value does not live long enough
3233
x.x[0];
3334
}

src/test/compile-fail/issue-15167.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,26 @@
1111
// macro f should not be able to inject a reference to 'n'.
1212

1313
macro_rules! f { () => (n) }
14+
//~^ ERROR unresolved name `n`
15+
//~| ERROR unresolved name `n`
16+
//~| ERROR unresolved name `n`
17+
//~| ERROR unresolved name `n`
1418

1519
fn main() -> (){
1620
for n in 0..1 {
17-
println!("{}", f!()); //~ ERROR unresolved name `n`
21+
println!("{}", f!());
1822
}
1923

2024
if let Some(n) = None {
21-
println!("{}", f!()); //~ ERROR unresolved name `n`
25+
println!("{}", f!());
2226
}
2327

2428
if false {
2529
} else if let Some(n) = None {
26-
println!("{}", f!()); //~ ERROR unresolved name `n`
30+
println!("{}", f!());
2731
}
2832

2933
while let Some(n) = None {
30-
println!("{}", f!()); //~ ERROR unresolved name `n`
34+
println!("{}", f!());
3135
}
3236
}

src/test/compile-fail/macro-backtrace-invalid-internals.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ macro_rules! fake_method_expr {
3636

3737
macro_rules! fake_field_expr {
3838
() => {
39-
1.fake
39+
1.fake //~ ERROR no field with that name
4040
}
4141
}
4242

4343
macro_rules! fake_anon_field_expr {
4444
() => {
45-
(1).0
45+
(1).0 //~ ERROR type was not a tuple
4646
}
4747
}
4848

@@ -52,8 +52,6 @@ fn main() {
5252
fake_anon_field_stmt!(); //~ NOTE in this expansion of
5353

5454
let _ = fake_method_expr!(); //~ NOTE in this expansion of
55-
let _ = fake_field_expr!(); //~ ERROR no field with that name
56-
//~^ NOTE in this expansion of
57-
let _ = fake_anon_field_expr!(); //~ ERROR type was not a tuple
58-
//~^ NOTE in this expansion of
55+
let _ = fake_field_expr!(); //~ NOTE in this expansion of
56+
let _ = fake_anon_field_expr!(); //~ NOTE in this expansion of
5957
}

src/test/compile-fail/macro-backtrace-nested.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@
1212
// we replace the span of the expanded expression with that of the call site.
1313

1414
macro_rules! nested_expr {
15-
() => (fake)
15+
() => (fake) //~ ERROR unresolved name
16+
//~^ ERROR unresolved name
1617
}
1718

1819
macro_rules! call_nested_expr {
19-
() => (nested_expr!())
20+
() => (nested_expr!()) //~ NOTE in this expansion of nested_expr!
2021
}
2122

2223
macro_rules! call_nested_expr_sum {
23-
() => { 1 + nested_expr!(); } //~ ERROR unresolved name
24-
//~^ NOTE in this expansion of nested_expr!
24+
() => { 1 + nested_expr!(); } //~ NOTE in this expansion of nested_expr!
2525
}
2626

2727
fn main() {
28-
1 + call_nested_expr!(); //~ ERROR unresolved name
29-
//~^ NOTE in this expansion of call_nested_expr!
28+
1 + call_nested_expr!(); //~ NOTE in this expansion of call_nested_expr!
3029
call_nested_expr_sum!(); //~ NOTE in this expansion of
3130
}

src/test/compile-fail/macro-backtrace-println.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ macro_rules! myprint {
2121
}
2222

2323
macro_rules! myprintln {
24-
($fmt:expr) => (myprint!(concat!($fmt, "\n"))); //~ ERROR invalid reference to argument `0`
25-
//~^ NOTE in this expansion of myprint!
26-
//~^^ NOTE in this expansion of concat!
24+
($fmt:expr) => (myprint!(concat!($fmt, "\n"))); //~ NOTE in this expansion of myprint!
25+
//~^ NOTE in this expansion of concat!
2726
}
2827

2928
fn main() {
30-
myprintln!("{}"); //~ NOTE in this expansion of
29+
myprintln!("{}"); //~ ERROR invalid reference to argument `0`
30+
//~^ NOTE in this expansion of
3131
}

0 commit comments

Comments
 (0)