Skip to content

Commit f5fef3c

Browse files
committed
Auto merge of rust-lang#75345 - Aaron1011:fix/no-std-hygiene, r=petrochenkov
Remove normalization of `Span` debug output in proc-macro tests Fixes rust-lang#74800 The definition of `is_x86_feature_detected!` (and similar macros) depends on the platform - it is produced by a `cfg_if!` invocation on x86, and a plain `#[cfg]` on other platforms. Since it is part of the prelude, we will end up importing different hygiene information depending on the platform. This previously required us to avoid printing raw `SyntaxContext` ids in any tests that uses the standard library, since the captured output will be platform-dependent. Previously, we replaced all `SyntaxContext` ids with "#CTXT", and the raw `Span` lo/hi bytes with "LO..HI". This commit adds `#![no_std]` and `extern crate std` to all proc-macro tests that print spans. This suppresses the prelude import, while still using lang items from `std` (which gives us a buildable binary). With this apporach, we will only load hygiene information for things which we explicitly import. This lets us re-add `-Z unpretty=expanded,hygiene`, since its output can now be made stable across all platforms. Additionally, we use `-Z span-debug` in more places, which lets us avoid the "LO..HI" normalization hack.
2 parents 18f3be7 + db6b3c1 commit f5fef3c

18 files changed

+233
-163
lines changed

src/test/ui/proc-macro/doc-comment-preserved.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// check-pass
2+
// compile-flags: -Z span-debug
23
// aux-build:test-macros.rs
34

4-
// Anonymize unstable non-dummy spans while still showing dummy spans `0..0`.
5-
// normalize-stdout-test "bytes\([^0]\w*\.\.(\w+)\)" -> "bytes(LO..$1)"
6-
// normalize-stdout-test "bytes\((\w+)\.\.[^0]\w*\)" -> "bytes($1..HI)"
5+
#![no_std] // Don't load unnecessary hygiene information from std
6+
extern crate std;
77

88
#[macro_use]
99
extern crate test_macros;

src/test/ui/proc-macro/doc-comment-preserved.stdout

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,44 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
1111
Punct {
1212
ch: '#',
1313
spacing: Alone,
14-
span: #0 bytes(LO..HI),
14+
span: $DIR/doc-comment-preserved.rs:13:1: 19:3 (#0),
1515
},
1616
Group {
1717
delimiter: Bracket,
1818
stream: TokenStream [
1919
Ident {
2020
ident: "doc",
21-
span: #0 bytes(LO..HI),
21+
span: $DIR/doc-comment-preserved.rs:13:1: 19:3 (#0),
2222
},
2323
Punct {
2424
ch: '=',
2525
spacing: Alone,
26-
span: #0 bytes(LO..HI),
26+
span: $DIR/doc-comment-preserved.rs:13:1: 19:3 (#0),
2727
},
2828
Literal {
2929
kind: Str,
3030
symbol: "\n*******\n* DOC *\n* DOC *\n* DOC *\n*******\n",
3131
suffix: None,
32-
span: #0 bytes(LO..HI),
32+
span: $DIR/doc-comment-preserved.rs:13:1: 19:3 (#0),
3333
},
3434
],
35-
span: #0 bytes(LO..HI),
35+
span: $DIR/doc-comment-preserved.rs:13:1: 19:3 (#0),
3636
},
3737
Ident {
3838
ident: "pub",
39-
span: #0 bytes(LO..HI),
39+
span: $DIR/doc-comment-preserved.rs:20:1: 20:4 (#0),
4040
},
4141
Ident {
4242
ident: "struct",
43-
span: #0 bytes(LO..HI),
43+
span: $DIR/doc-comment-preserved.rs:20:5: 20:11 (#0),
4444
},
4545
Ident {
4646
ident: "S",
47-
span: #0 bytes(LO..HI),
47+
span: $DIR/doc-comment-preserved.rs:20:12: 20:13 (#0),
4848
},
4949
Punct {
5050
ch: ';',
5151
spacing: Alone,
52-
span: #0 bytes(LO..HI),
52+
span: $DIR/doc-comment-preserved.rs:20:13: 20:14 (#0),
5353
},
5454
]

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// check-pass
22
// edition:2018
3+
// compile-flags: -Z span-debug
34
// aux-build:test-macros.rs
45

5-
// Anonymize unstable non-dummy spans while still showing dummy spans `0..0`.
6-
// normalize-stdout-test "bytes\([^0]\w*\.\.(\w+)\)" -> "bytes(LO..$1)"
7-
// normalize-stdout-test "bytes\((\w+)\.\.[^0]\w*\)" -> "bytes($1..HI)"
8-
// normalize-stdout-test "#\d+" -> "#CTXT"
6+
#![no_std] // Don't load unnecessary hygiene information from std
7+
extern crate std;
98

109
#[macro_use]
1110
extern crate test_macros;

src/test/ui/proc-macro/dollar-crate-issue-57089.stdout

+16-16
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,79 @@ PRINT-BANG INPUT (DISPLAY): struct M($crate :: S) ;
22
PRINT-BANG INPUT (DEBUG): TokenStream [
33
Ident {
44
ident: "struct",
5-
span: #CTXT bytes(LO..HI),
5+
span: $DIR/dollar-crate-issue-57089.rs:17:13: 17:19 (#3),
66
},
77
Ident {
88
ident: "M",
9-
span: #CTXT bytes(LO..HI),
9+
span: $DIR/dollar-crate-issue-57089.rs:17:20: 17:21 (#3),
1010
},
1111
Group {
1212
delimiter: Parenthesis,
1313
stream: TokenStream [
1414
Ident {
1515
ident: "$crate",
16-
span: #CTXT bytes(LO..HI),
16+
span: $DIR/dollar-crate-issue-57089.rs:17:22: 17:28 (#3),
1717
},
1818
Punct {
1919
ch: ':',
2020
spacing: Joint,
21-
span: #CTXT bytes(LO..HI),
21+
span: $DIR/dollar-crate-issue-57089.rs:17:28: 17:30 (#3),
2222
},
2323
Punct {
2424
ch: ':',
2525
spacing: Alone,
26-
span: #CTXT bytes(LO..HI),
26+
span: $DIR/dollar-crate-issue-57089.rs:17:28: 17:30 (#3),
2727
},
2828
Ident {
2929
ident: "S",
30-
span: #CTXT bytes(LO..HI),
30+
span: $DIR/dollar-crate-issue-57089.rs:17:30: 17:31 (#3),
3131
},
3232
],
33-
span: #CTXT bytes(LO..HI),
33+
span: $DIR/dollar-crate-issue-57089.rs:17:21: 17:32 (#3),
3434
},
3535
Punct {
3636
ch: ';',
3737
spacing: Alone,
38-
span: #CTXT bytes(LO..HI),
38+
span: $DIR/dollar-crate-issue-57089.rs:17:32: 17:33 (#3),
3939
},
4040
]
4141
PRINT-ATTR INPUT (DISPLAY): struct A($crate :: S) ;
4242
PRINT-ATTR INPUT (DEBUG): TokenStream [
4343
Ident {
4444
ident: "struct",
45-
span: #CTXT bytes(LO..HI),
45+
span: $DIR/dollar-crate-issue-57089.rs:21:9: 21:15 (#3),
4646
},
4747
Ident {
4848
ident: "A",
49-
span: #CTXT bytes(LO..HI),
49+
span: $DIR/dollar-crate-issue-57089.rs:21:16: 21:17 (#3),
5050
},
5151
Group {
5252
delimiter: Parenthesis,
5353
stream: TokenStream [
5454
Ident {
5555
ident: "$crate",
56-
span: #CTXT bytes(LO..HI),
56+
span: $DIR/dollar-crate-issue-57089.rs:21:18: 21:24 (#3),
5757
},
5858
Punct {
5959
ch: ':',
6060
spacing: Joint,
61-
span: #CTXT bytes(LO..HI),
61+
span: $DIR/dollar-crate-issue-57089.rs:21:24: 21:26 (#3),
6262
},
6363
Punct {
6464
ch: ':',
6565
spacing: Alone,
66-
span: #CTXT bytes(LO..HI),
66+
span: $DIR/dollar-crate-issue-57089.rs:21:24: 21:26 (#3),
6767
},
6868
Ident {
6969
ident: "S",
70-
span: #CTXT bytes(LO..HI),
70+
span: $DIR/dollar-crate-issue-57089.rs:21:26: 21:27 (#3),
7171
},
7272
],
73-
span: #CTXT bytes(LO..HI),
73+
span: $DIR/dollar-crate-issue-57089.rs:21:17: 21:28 (#3),
7474
},
7575
Punct {
7676
ch: ';',
7777
spacing: Alone,
78-
span: #CTXT bytes(LO..HI),
78+
span: $DIR/dollar-crate-issue-57089.rs:21:28: 21:29 (#3),
7979
},
8080
]

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// check-pass
22
// edition:2018
3+
// compile-flags: -Z span-debug
34
// aux-build:test-macros.rs
45
// aux-build:dollar-crate-external.rs
56

6-
// Anonymize unstable non-dummy spans while still showing dummy spans `0..0`.
7-
// normalize-stdout-test "bytes\([^0]\w*\.\.(\w+)\)" -> "bytes(LO..$1)"
8-
// normalize-stdout-test "bytes\((\w+)\.\.[^0]\w*\)" -> "bytes($1..HI)"
9-
// normalize-stdout-test "#\d+" -> "#CTXT"
7+
8+
#![no_std] // Don't load unnecessary hygiene information from std
9+
extern crate std;
1010

1111
#[macro_use]
1212
extern crate test_macros;

src/test/ui/proc-macro/dollar-crate-issue-62325.stdout

+22-22
Original file line numberDiff line numberDiff line change
@@ -2,109 +2,109 @@ PRINT-ATTR INPUT (DISPLAY): struct A(identity ! ($crate :: S)) ;
22
PRINT-ATTR INPUT (DEBUG): TokenStream [
33
Ident {
44
ident: "struct",
5-
span: #CTXT bytes(LO..HI),
5+
span: $DIR/dollar-crate-issue-62325.rs:19:5: 19:11 (#3),
66
},
77
Ident {
88
ident: "A",
9-
span: #CTXT bytes(LO..HI),
9+
span: $DIR/dollar-crate-issue-62325.rs:19:12: 19:13 (#3),
1010
},
1111
Group {
1212
delimiter: Parenthesis,
1313
stream: TokenStream [
1414
Ident {
1515
ident: "identity",
16-
span: #CTXT bytes(LO..HI),
16+
span: $DIR/dollar-crate-issue-62325.rs:19:14: 19:22 (#3),
1717
},
1818
Punct {
1919
ch: '!',
2020
spacing: Alone,
21-
span: #CTXT bytes(LO..HI),
21+
span: $DIR/dollar-crate-issue-62325.rs:19:22: 19:23 (#3),
2222
},
2323
Group {
2424
delimiter: Parenthesis,
2525
stream: TokenStream [
2626
Ident {
2727
ident: "$crate",
28-
span: #CTXT bytes(LO..HI),
28+
span: $DIR/dollar-crate-issue-62325.rs:19:24: 19:30 (#3),
2929
},
3030
Punct {
3131
ch: ':',
3232
spacing: Joint,
33-
span: #CTXT bytes(LO..HI),
33+
span: $DIR/dollar-crate-issue-62325.rs:19:30: 19:32 (#3),
3434
},
3535
Punct {
3636
ch: ':',
3737
spacing: Alone,
38-
span: #CTXT bytes(LO..HI),
38+
span: $DIR/dollar-crate-issue-62325.rs:19:30: 19:32 (#3),
3939
},
4040
Ident {
4141
ident: "S",
42-
span: #CTXT bytes(LO..HI),
42+
span: $DIR/dollar-crate-issue-62325.rs:19:32: 19:33 (#3),
4343
},
4444
],
45-
span: #CTXT bytes(LO..HI),
45+
span: $DIR/dollar-crate-issue-62325.rs:19:23: 19:34 (#3),
4646
},
4747
],
48-
span: #CTXT bytes(LO..HI),
48+
span: $DIR/dollar-crate-issue-62325.rs:19:13: 19:35 (#3),
4949
},
5050
Punct {
5151
ch: ';',
5252
spacing: Alone,
53-
span: #CTXT bytes(LO..HI),
53+
span: $DIR/dollar-crate-issue-62325.rs:19:35: 19:36 (#3),
5454
},
5555
]
5656
PRINT-ATTR INPUT (DISPLAY): struct B(identity ! ($crate :: S)) ;
5757
PRINT-ATTR INPUT (DEBUG): TokenStream [
5858
Ident {
5959
ident: "struct",
60-
span: #CTXT bytes(LO..HI),
60+
span: $DIR/auxiliary/dollar-crate-external.rs:21:5: 21:11 (#10),
6161
},
6262
Ident {
6363
ident: "B",
64-
span: #CTXT bytes(LO..HI),
64+
span: $DIR/auxiliary/dollar-crate-external.rs:21:12: 21:13 (#10),
6565
},
6666
Group {
6767
delimiter: Parenthesis,
6868
stream: TokenStream [
6969
Ident {
7070
ident: "identity",
71-
span: #CTXT bytes(LO..HI),
71+
span: $DIR/auxiliary/dollar-crate-external.rs:21:14: 21:22 (#10),
7272
},
7373
Punct {
7474
ch: '!',
7575
spacing: Alone,
76-
span: #CTXT bytes(LO..HI),
76+
span: $DIR/auxiliary/dollar-crate-external.rs:21:22: 21:23 (#10),
7777
},
7878
Group {
7979
delimiter: Parenthesis,
8080
stream: TokenStream [
8181
Ident {
8282
ident: "$crate",
83-
span: #CTXT bytes(LO..HI),
83+
span: $DIR/auxiliary/dollar-crate-external.rs:21:24: 21:30 (#10),
8484
},
8585
Punct {
8686
ch: ':',
8787
spacing: Joint,
88-
span: #CTXT bytes(LO..HI),
88+
span: $DIR/auxiliary/dollar-crate-external.rs:21:30: 21:32 (#10),
8989
},
9090
Punct {
9191
ch: ':',
9292
spacing: Alone,
93-
span: #CTXT bytes(LO..HI),
93+
span: $DIR/auxiliary/dollar-crate-external.rs:21:30: 21:32 (#10),
9494
},
9595
Ident {
9696
ident: "S",
97-
span: #CTXT bytes(LO..HI),
97+
span: $DIR/auxiliary/dollar-crate-external.rs:21:32: 21:33 (#10),
9898
},
9999
],
100-
span: #CTXT bytes(LO..HI),
100+
span: $DIR/auxiliary/dollar-crate-external.rs:21:23: 21:34 (#10),
101101
},
102102
],
103-
span: #CTXT bytes(LO..HI),
103+
span: $DIR/auxiliary/dollar-crate-external.rs:21:13: 21:35 (#10),
104104
},
105105
Punct {
106106
ch: ';',
107107
spacing: Alone,
108-
span: #CTXT bytes(LO..HI),
108+
span: $DIR/auxiliary/dollar-crate-external.rs:21:35: 21:36 (#10),
109109
},
110110
]

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// check-pass
22
// edition:2018
3+
// compile-flags: -Z span-debug
34
// aux-build:test-macros.rs
45
// aux-build:dollar-crate-external.rs
56

6-
// Anonymize unstable non-dummy spans while still showing dummy spans `0..0`.
7-
// normalize-stdout-test "bytes\([^0]\w*\.\.(\w+)\)" -> "bytes(LO..$1)"
8-
// normalize-stdout-test "bytes\((\w+)\.\.[^0]\w*\)" -> "bytes($1..HI)"
9-
// normalize-stdout-test "#\d+" -> "#CTXT"
7+
#![no_std] // Don't load unnecessary hygiene information from std
8+
extern crate std;
109

1110
#[macro_use]
1211
extern crate test_macros;

0 commit comments

Comments
 (0)