Skip to content

Commit db0c346

Browse files
authored
Rollup merge of rust-lang#72795 - petrochenkov:identgroup, r=nikomatsakis
Add a test for `$:ident` in proc macro input cc rust-lang#72545 (comment)
2 parents 8a68fc6 + 81e06da commit db0c346

File tree

5 files changed

+99
-33
lines changed

5 files changed

+99
-33
lines changed

src/test/ui/proc-macro/auxiliary/test-macros.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,6 @@ pub fn print_attr(_: TokenStream, input: TokenStream) -> TokenStream {
108108

109109
#[proc_macro_derive(Print, attributes(print_helper))]
110110
pub fn print_derive(input: TokenStream) -> TokenStream {
111-
print_helper(input, "DERIVE")
111+
print_helper(input, "DERIVE");
112+
TokenStream::new()
112113
}

src/test/ui/proc-macro/dollar-crate.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// check-pass
12
// edition:2018
23
// aux-build:test-macros.rs
34
// aux-build:dollar-crate-external.rs
@@ -23,7 +24,7 @@ mod local {
2324
struct A($crate::S);
2425

2526
#[derive(Print)]
26-
struct D($crate::S); //~ ERROR the name `D` is defined multiple times
27+
struct D($crate::S);
2728
};
2829
}
2930

@@ -33,7 +34,7 @@ mod local {
3334
mod external {
3435
use crate::dollar_crate_external;
3536

36-
dollar_crate_external::external!(); //~ ERROR the name `D` is defined multiple times
37+
dollar_crate_external::external!();
3738
}
3839

3940
fn main() {}

src/test/ui/proc-macro/dollar-crate.stderr

-30
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Check what token streams proc macros see when interpolated tokens are passed to them as input.
2+
3+
// check-pass
4+
// aux-build:test-macros.rs
5+
6+
#[macro_use]
7+
extern crate test_macros;
8+
9+
macro_rules! pass_ident {
10+
($i:ident) => {
11+
fn f() {
12+
print_bang!($i);
13+
}
14+
15+
#[print_attr]
16+
const $i: u8 = 0;
17+
18+
#[derive(Print)]
19+
struct $i {}
20+
};
21+
}
22+
23+
pass_ident!(A);
24+
25+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
PRINT-BANG INPUT (DISPLAY): A
2+
PRINT-BANG RE-COLLECTED (DISPLAY): A
3+
PRINT-BANG INPUT (DEBUG): TokenStream [
4+
Group {
5+
delimiter: None,
6+
stream: TokenStream [
7+
Ident {
8+
ident: "A",
9+
span: #0 bytes(402..403),
10+
},
11+
],
12+
span: #3 bytes(269..271),
13+
},
14+
]
15+
PRINT-ATTR INPUT (DISPLAY): const A: u8 = 0;
16+
PRINT-ATTR RE-COLLECTED (DISPLAY): const A : u8 = 0 ;
17+
PRINT-ATTR INPUT (DEBUG): TokenStream [
18+
Ident {
19+
ident: "const",
20+
span: #0 bytes(0..0),
21+
},
22+
Ident {
23+
ident: "A",
24+
span: #0 bytes(0..0),
25+
},
26+
Punct {
27+
ch: ':',
28+
spacing: Alone,
29+
span: #0 bytes(0..0),
30+
},
31+
Ident {
32+
ident: "u8",
33+
span: #0 bytes(0..0),
34+
},
35+
Punct {
36+
ch: '=',
37+
spacing: Alone,
38+
span: #0 bytes(0..0),
39+
},
40+
Literal {
41+
kind: Integer,
42+
symbol: "0",
43+
suffix: None,
44+
span: #0 bytes(0..0),
45+
},
46+
Punct {
47+
ch: ';',
48+
spacing: Alone,
49+
span: #0 bytes(0..0),
50+
},
51+
]
52+
PRINT-DERIVE INPUT (DISPLAY): struct A {
53+
}
54+
PRINT-DERIVE RE-COLLECTED (DISPLAY): struct A { }
55+
PRINT-DERIVE INPUT (DEBUG): TokenStream [
56+
Ident {
57+
ident: "struct",
58+
span: #0 bytes(0..0),
59+
},
60+
Ident {
61+
ident: "A",
62+
span: #0 bytes(0..0),
63+
},
64+
Group {
65+
delimiter: Brace,
66+
stream: TokenStream [],
67+
span: #0 bytes(0..0),
68+
},
69+
]

0 commit comments

Comments
 (0)