Auto merge of #74627 - petrochenkov:docbeauty2, r=Aaron1011

rustc_ast: Stop using "string typing" for doc comment tokens

Explicitly store their kind and style retrieved during lexing in the `token::DocComment`.

Also don't "beautify" doc comments before converting them to `#[doc]` attributes when passing them to macros (both declarative and procedural).
The trimming of empty lines, lines containing only `*`s, etc is purely a rustdoc's job as a part of its presentation of doc strings to users, rustc must not do this and must pass tokens as precisely as possible internally.
This commit is contained in:
bors 2020-08-07 13:29:25 +00:00
commit 64f99b4cfb
25 changed files with 313 additions and 241 deletions

View file

@ -0,0 +1,24 @@
// check-pass
// 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)"
#[macro_use]
extern crate test_macros;
print_bang! {
/**
*******
* DOC *
* DOC *
* DOC *
*******
*/
pub struct S;
}
fn main() {}

View file

@ -0,0 +1,54 @@
PRINT-BANG INPUT (DISPLAY): /**
*******
* DOC *
* DOC *
* DOC *
*******
*/
pub struct S ;
PRINT-BANG RE-COLLECTED (DISPLAY): #[doc = "\n*******\n* DOC *\n* DOC *\n* DOC *\n*******\n"] pub struct S ;
PRINT-BANG INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
spacing: Alone,
span: #0 bytes(LO..HI),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "doc",
span: #0 bytes(LO..HI),
},
Punct {
ch: '=',
spacing: Alone,
span: #0 bytes(LO..HI),
},
Literal {
kind: Str,
symbol: "\n*******\n* DOC *\n* DOC *\n* DOC *\n*******\n",
suffix: None,
span: #0 bytes(LO..HI),
},
],
span: #0 bytes(LO..HI),
},
Ident {
ident: "pub",
span: #0 bytes(LO..HI),
},
Ident {
ident: "struct",
span: #0 bytes(LO..HI),
},
Ident {
ident: "S",
span: #0 bytes(LO..HI),
},
Punct {
ch: ';',
spacing: Alone,
span: #0 bytes(LO..HI),
},
]