]> git.proxmox.com Git - rustc.git/blob - src/test/ui-fulldeps/proc-macro/parent-source-spans.rs
New upstream version 1.27.1+dfsg1
[rustc.git] / src / test / ui-fulldeps / proc-macro / parent-source-spans.rs
1 // Copyright 2018 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 // aux-build:parent-source-spans.rs
12 // ignore-stage1
13
14 #![feature(proc_macro, decl_macro, proc_macro_non_items)]
15
16 extern crate parent_source_spans;
17
18 use parent_source_spans::parent_source_spans;
19
20 macro one($a:expr, $b:expr) {
21 two!($a, $b);
22 //~^ ERROR first parent: "hello"
23 //~| ERROR second parent: "world"
24 }
25
26 macro two($a:expr, $b:expr) {
27 three!($a, $b);
28 //~^ ERROR first final: "hello"
29 //~| ERROR second final: "world"
30 //~| ERROR first final: "yay"
31 //~| ERROR second final: "rust"
32 }
33
34 // forwarding tokens directly doesn't create a new source chain
35 macro three($($tokens:tt)*) {
36 four!($($tokens)*);
37 }
38
39 macro four($($tokens:tt)*) {
40 parent_source_spans!($($tokens)*);
41 }
42
43 fn main() {
44 one!("hello", "world");
45 //~^ ERROR first grandparent: "hello"
46 //~| ERROR second grandparent: "world"
47 //~| ERROR first source: "hello"
48 //~| ERROR second source: "world"
49
50 two!("yay", "rust");
51 //~^ ERROR first parent: "yay"
52 //~| ERROR second parent: "rust"
53 //~| ERROR first source: "yay"
54 //~| ERROR second source: "rust"
55
56 three!("hip", "hop");
57 //~^ ERROR first final: "hip"
58 //~| ERROR second final: "hop"
59 //~| ERROR first source: "hip"
60 //~| ERROR second source: "hop"
61 }