Skip to content

Commit 5a8f102

Browse files
committed
Add compile-file/macro-backtrace-{invalid-internals,nested,println} tests
1 parent a893c64 commit 5a8f102

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2015 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+
// Macros in statement vs expression position handle backtraces differently.
12+
13+
macro_rules! fake_method_stmt { //~ NOTE in expansion of
14+
() => {
15+
1.fake() //~ ERROR does not implement any method
16+
}
17+
}
18+
19+
macro_rules! fake_field_stmt { //~ NOTE in expansion of
20+
() => {
21+
1.fake //~ ERROR no field with that name
22+
}
23+
}
24+
25+
macro_rules! fake_anon_field_stmt { //~ NOTE in expansion of
26+
() => {
27+
(1).0 //~ ERROR type was not a tuple
28+
}
29+
}
30+
31+
macro_rules! fake_method_expr { //~ NOTE in expansion of
32+
() => {
33+
1.fake() //~ ERROR does not implement any method
34+
}
35+
}
36+
37+
macro_rules! fake_field_expr {
38+
() => {
39+
1.fake
40+
}
41+
}
42+
43+
macro_rules! fake_anon_field_expr {
44+
() => {
45+
(1).0
46+
}
47+
}
48+
49+
fn main() {
50+
fake_method_stmt!(); //~ NOTE expansion site
51+
fake_field_stmt!(); //~ NOTE expansion site
52+
fake_anon_field_stmt!(); //~ NOTE expansion site
53+
54+
let _ = fake_method_expr!(); //~ NOTE expansion site
55+
let _ = fake_field_expr!(); //~ ERROR no field with that name
56+
let _ = fake_anon_field_expr!(); //~ ERROR type was not a tuple
57+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2015 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+
// In expression position, but not statement position, when we expand a macro,
12+
// we replace the span of the expanded expression with that of the call site.
13+
14+
macro_rules! nested_expr {
15+
() => (fake)
16+
}
17+
18+
macro_rules! call_nested_expr {
19+
() => (nested_expr!())
20+
}
21+
22+
macro_rules! call_nested_expr_sum { //~ NOTE in expansion of
23+
() => { 1 + nested_expr!(); } //~ ERROR unresolved name
24+
}
25+
26+
fn main() {
27+
1 + call_nested_expr!(); //~ ERROR unresolved name
28+
call_nested_expr_sum!(); //~ NOTE expansion site
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2015 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+
// The `format_args!` syntax extension issues errors before code expansion
12+
// has completed, but we still need a backtrace.
13+
14+
// This test includes stripped-down versions of `print!` and `println!`,
15+
// because we can't otherwise verify the lines of the backtrace.
16+
17+
fn print(_args: std::fmt::Arguments) {}
18+
19+
macro_rules! myprint { //~ NOTE in expansion of
20+
($($arg:tt)*) => (print(format_args!($($arg)*)));
21+
}
22+
23+
macro_rules! myprintln { //~ NOTE in expansion of
24+
($fmt:expr) => (myprint!(concat!($fmt, "\n"))); //~ ERROR invalid reference to argument `0`
25+
}
26+
27+
fn main() {
28+
myprintln!("{}"); //~ NOTE expansion site
29+
}

0 commit comments

Comments
 (0)