Skip to content

Commit

Permalink
Remove normalization of Span debug output in proc-macro tests
Browse files Browse the repository at this point in the history
Fixes #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.
  • Loading branch information
Aaron1011 committed Aug 9, 2020
1 parent 543f03d commit db6b3c1
Show file tree
Hide file tree
Showing 18 changed files with 233 additions and 163 deletions.
6 changes: 3 additions & 3 deletions src/test/ui/proc-macro/doc-comment-preserved.rs
@@ -1,9 +1,9 @@
// check-pass
// compile-flags: -Z span-debug
// aux-build:test-macros.rs

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

#[macro_use]
extern crate test_macros;
Expand Down
18 changes: 9 additions & 9 deletions src/test/ui/proc-macro/doc-comment-preserved.stdout
Expand Up @@ -11,44 +11,44 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
spacing: Alone,
span: #0 bytes(LO..HI),
span: $DIR/doc-comment-preserved.rs:13:1: 19:3 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "doc",
span: #0 bytes(LO..HI),
span: $DIR/doc-comment-preserved.rs:13:1: 19:3 (#0),
},
Punct {
ch: '=',
spacing: Alone,
span: #0 bytes(LO..HI),
span: $DIR/doc-comment-preserved.rs:13:1: 19:3 (#0),
},
Literal {
kind: Str,
symbol: "\n*******\n* DOC *\n* DOC *\n* DOC *\n*******\n",
suffix: None,
span: #0 bytes(LO..HI),
span: $DIR/doc-comment-preserved.rs:13:1: 19:3 (#0),
},
],
span: #0 bytes(LO..HI),
span: $DIR/doc-comment-preserved.rs:13:1: 19:3 (#0),
},
Ident {
ident: "pub",
span: #0 bytes(LO..HI),
span: $DIR/doc-comment-preserved.rs:20:1: 20:4 (#0),
},
Ident {
ident: "struct",
span: #0 bytes(LO..HI),
span: $DIR/doc-comment-preserved.rs:20:5: 20:11 (#0),
},
Ident {
ident: "S",
span: #0 bytes(LO..HI),
span: $DIR/doc-comment-preserved.rs:20:12: 20:13 (#0),
},
Punct {
ch: ';',
spacing: Alone,
span: #0 bytes(LO..HI),
span: $DIR/doc-comment-preserved.rs:20:13: 20:14 (#0),
},
]
7 changes: 3 additions & 4 deletions src/test/ui/proc-macro/dollar-crate-issue-57089.rs
@@ -1,11 +1,10 @@
// check-pass
// edition:2018
// compile-flags: -Z span-debug
// aux-build:test-macros.rs

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

#[macro_use]
extern crate test_macros;
Expand Down
32 changes: 16 additions & 16 deletions src/test/ui/proc-macro/dollar-crate-issue-57089.stdout
Expand Up @@ -2,79 +2,79 @@ PRINT-BANG INPUT (DISPLAY): struct M($crate :: S) ;
PRINT-BANG INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-57089.rs:17:13: 17:19 (#3),
},
Ident {
ident: "M",
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-57089.rs:17:20: 17:21 (#3),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "$crate",
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-57089.rs:17:22: 17:28 (#3),
},
Punct {
ch: ':',
spacing: Joint,
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-57089.rs:17:28: 17:30 (#3),
},
Punct {
ch: ':',
spacing: Alone,
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-57089.rs:17:28: 17:30 (#3),
},
Ident {
ident: "S",
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-57089.rs:17:30: 17:31 (#3),
},
],
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-57089.rs:17:21: 17:32 (#3),
},
Punct {
ch: ';',
spacing: Alone,
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-57089.rs:17:32: 17:33 (#3),
},
]
PRINT-ATTR INPUT (DISPLAY): struct A($crate :: S) ;
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-57089.rs:21:9: 21:15 (#3),
},
Ident {
ident: "A",
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-57089.rs:21:16: 21:17 (#3),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "$crate",
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-57089.rs:21:18: 21:24 (#3),
},
Punct {
ch: ':',
spacing: Joint,
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-57089.rs:21:24: 21:26 (#3),
},
Punct {
ch: ':',
spacing: Alone,
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-57089.rs:21:24: 21:26 (#3),
},
Ident {
ident: "S",
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-57089.rs:21:26: 21:27 (#3),
},
],
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-57089.rs:21:17: 21:28 (#3),
},
Punct {
ch: ';',
spacing: Alone,
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-57089.rs:21:28: 21:29 (#3),
},
]
8 changes: 4 additions & 4 deletions src/test/ui/proc-macro/dollar-crate-issue-62325.rs
@@ -1,12 +1,12 @@
// check-pass
// edition:2018
// compile-flags: -Z span-debug
// aux-build:test-macros.rs
// aux-build:dollar-crate-external.rs

// Anonymize unstable non-dummy spans while still showing dummy spans `0..0`.
// normalize-stdout-test "bytes\([^0]\w*\.\.(\w+)\)" -> "bytes(LO..$1)"
// normalize-stdout-test "bytes\((\w+)\.\.[^0]\w*\)" -> "bytes($1..HI)"
// normalize-stdout-test "#\d+" -> "#CTXT"

#![no_std] // Don't load unnecessary hygiene information from std
extern crate std;

#[macro_use]
extern crate test_macros;
Expand Down
44 changes: 22 additions & 22 deletions src/test/ui/proc-macro/dollar-crate-issue-62325.stdout
Expand Up @@ -2,109 +2,109 @@ PRINT-ATTR INPUT (DISPLAY): struct A(identity ! ($crate :: S)) ;
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-62325.rs:19:5: 19:11 (#3),
},
Ident {
ident: "A",
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-62325.rs:19:12: 19:13 (#3),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "identity",
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-62325.rs:19:14: 19:22 (#3),
},
Punct {
ch: '!',
spacing: Alone,
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-62325.rs:19:22: 19:23 (#3),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "$crate",
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-62325.rs:19:24: 19:30 (#3),
},
Punct {
ch: ':',
spacing: Joint,
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-62325.rs:19:30: 19:32 (#3),
},
Punct {
ch: ':',
spacing: Alone,
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-62325.rs:19:30: 19:32 (#3),
},
Ident {
ident: "S",
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-62325.rs:19:32: 19:33 (#3),
},
],
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-62325.rs:19:23: 19:34 (#3),
},
],
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-62325.rs:19:13: 19:35 (#3),
},
Punct {
ch: ';',
spacing: Alone,
span: #CTXT bytes(LO..HI),
span: $DIR/dollar-crate-issue-62325.rs:19:35: 19:36 (#3),
},
]
PRINT-ATTR INPUT (DISPLAY): struct B(identity ! ($crate :: S)) ;
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
span: #CTXT bytes(LO..HI),
span: $DIR/auxiliary/dollar-crate-external.rs:21:5: 21:11 (#10),
},
Ident {
ident: "B",
span: #CTXT bytes(LO..HI),
span: $DIR/auxiliary/dollar-crate-external.rs:21:12: 21:13 (#10),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "identity",
span: #CTXT bytes(LO..HI),
span: $DIR/auxiliary/dollar-crate-external.rs:21:14: 21:22 (#10),
},
Punct {
ch: '!',
spacing: Alone,
span: #CTXT bytes(LO..HI),
span: $DIR/auxiliary/dollar-crate-external.rs:21:22: 21:23 (#10),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "$crate",
span: #CTXT bytes(LO..HI),
span: $DIR/auxiliary/dollar-crate-external.rs:21:24: 21:30 (#10),
},
Punct {
ch: ':',
spacing: Joint,
span: #CTXT bytes(LO..HI),
span: $DIR/auxiliary/dollar-crate-external.rs:21:30: 21:32 (#10),
},
Punct {
ch: ':',
spacing: Alone,
span: #CTXT bytes(LO..HI),
span: $DIR/auxiliary/dollar-crate-external.rs:21:30: 21:32 (#10),
},
Ident {
ident: "S",
span: #CTXT bytes(LO..HI),
span: $DIR/auxiliary/dollar-crate-external.rs:21:32: 21:33 (#10),
},
],
span: #CTXT bytes(LO..HI),
span: $DIR/auxiliary/dollar-crate-external.rs:21:23: 21:34 (#10),
},
],
span: #CTXT bytes(LO..HI),
span: $DIR/auxiliary/dollar-crate-external.rs:21:13: 21:35 (#10),
},
Punct {
ch: ';',
spacing: Alone,
span: #CTXT bytes(LO..HI),
span: $DIR/auxiliary/dollar-crate-external.rs:21:35: 21:36 (#10),
},
]
7 changes: 3 additions & 4 deletions src/test/ui/proc-macro/dollar-crate.rs
@@ -1,12 +1,11 @@
// check-pass
// edition:2018
// compile-flags: -Z span-debug
// aux-build:test-macros.rs
// aux-build:dollar-crate-external.rs

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

#[macro_use]
extern crate test_macros;
Expand Down

0 comments on commit db6b3c1

Please sign in to comment.