]> git.lizzy.rs Git - rust.git/blob - src/test/ui/proc-macro/parent-source-spans.rs
2e12c34b99b1b1df65ce32604f19ed85d82c3232
[rust.git] / src / test / ui / proc-macro / parent-source-spans.rs
1 // aux-build:parent-source-spans.rs
2
3
4 #![feature(decl_macro, proc_macro_hygiene)]
5
6 extern crate parent_source_spans;
7
8 use parent_source_spans::parent_source_spans;
9
10 macro one($a:expr, $b:expr) {
11     two!($a, $b);
12     //~^ ERROR first parent: "hello"
13     //~| ERROR second parent: "world"
14 }
15
16 macro two($a:expr, $b:expr) {
17     three!($a, $b);
18     //~^ ERROR first final: "hello"
19     //~| ERROR second final: "world"
20     //~| ERROR first final: "yay"
21     //~| ERROR second final: "rust"
22 }
23
24 // forwarding tokens directly doesn't create a new source chain
25 macro three($($tokens:tt)*) {
26     four!($($tokens)*);
27 }
28
29 macro four($($tokens:tt)*) {
30     parent_source_spans!($($tokens)*);
31 }
32
33 fn main() {
34     one!("hello", "world");
35     //~^ ERROR first grandparent: "hello"
36     //~| ERROR second grandparent: "world"
37     //~| ERROR first source: "hello"
38     //~| ERROR second source: "world"
39
40     two!("yay", "rust");
41     //~^ ERROR first parent: "yay"
42     //~| ERROR second parent: "rust"
43     //~| ERROR first source: "yay"
44     //~| ERROR second source: "rust"
45
46     three!("hip", "hop");
47     //~^ ERROR first final: "hip"
48     //~| ERROR second final: "hop"
49     //~| ERROR first source: "hip"
50     //~| ERROR second source: "hop"
51 }