rustc_ast_pretty: Don't print space after $

For example, this code:

    $arg:expr

used to be pretty-printed as:

    $ arg : expr

but is now pretty-printed as:

    $arg : expr
This commit is contained in:
Noah Lev 2021-07-03 15:10:06 -07:00
parent f82d4845f2
commit 7ffec7028a
11 changed files with 32 additions and 28 deletions

View file

@ -136,11 +136,11 @@ pub fn print_crate<'a>(
s.s.eof() s.s.eof()
} }
// This makes printed token streams look slightly nicer, /// This makes printed token streams look slightly nicer,
// and also addresses some specific regressions described in #63896 and #73345. /// and also addresses some specific regressions described in #63896 and #73345.
fn tt_prepend_space(tt: &TokenTree, prev: &TokenTree) -> bool { fn tt_prepend_space(tt: &TokenTree, prev: &TokenTree) -> bool {
if let TokenTree::Token(token) = prev { if let TokenTree::Token(token) = prev {
if matches!(token.kind, token::Dot) { if matches!(token.kind, token::Dot | token::Dollar) {
return false; return false;
} }
if let token::DocComment(comment_kind, ..) = token.kind { if let token::DocComment(comment_kind, ..) = token.kind {

View file

@ -8,6 +8,6 @@ extern crate std;
// pretty-mode:expanded // pretty-mode:expanded
// pp-exact:cast-lt.pp // pp-exact:cast-lt.pp
macro_rules! negative { ($ e : expr) => { $ e < 0 } } macro_rules! negative { ($e : expr) => { $e < 0 } }
fn main() { (1 as i32) < 0; } fn main() { (1 as i32) < 0; }

View file

@ -2,7 +2,7 @@
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
macro_rules! mac { ($ ($ tt : tt) *) => () } macro_rules! mac { ($($tt : tt) *) => () }
mac! { mac! {
struct S { field1 : u8, field2 : u16, } impl Clone for S struct S { field1 : u8, field2 : u16, } impl Clone for S

View file

@ -2,6 +2,6 @@
#![feature(decl_macro)] #![feature(decl_macro)]
pub(crate) macro mac { ($ arg : expr) => { $ arg + $ arg } } pub(crate) macro mac { ($arg : expr) => { $arg + $arg } }
fn main() { } fn main() { }

View file

@ -11,9 +11,9 @@ macro_rules! matcher_brackets {
} }
macro_rules! all_fragments { macro_rules! all_fragments {
($ b : block, $ e : expr, $ i : ident, $ it : item, $ l : lifetime, $ lit ($b : block, $e : expr, $i : ident, $it : item, $l : lifetime, $lit :
: literal, $ m : meta, $ p : pat, $ pth : path, $ s : stmt, $ tt : tt, $ literal, $m : meta, $p : pat, $pth : path, $s : stmt, $tt : tt, $ty : ty,
ty : ty, $ vis : vis) => { } ; $vis : vis) => { } ;
} }
fn main() { } fn main() { }

View file

@ -9,7 +9,7 @@ pub macro my_macro() {
} }
// @has decl_macro/macro.my_macro_2.html //pre 'pub macro my_macro_2($ ($ tok : tt) *) {' // @has decl_macro/macro.my_macro_2.html //pre 'pub macro my_macro_2($($tok : tt) *) {'
// @has - //pre '...' // @has - //pre '...'
// @has - //pre '}' // @has - //pre '}'
pub macro my_macro_2($($tok:tt)*) { pub macro my_macro_2($($tok:tt)*) {
@ -18,8 +18,8 @@ pub macro my_macro_2($($tok:tt)*) {
// @has decl_macro/macro.my_macro_multi.html //pre 'pub macro my_macro_multi {' // @has decl_macro/macro.my_macro_multi.html //pre 'pub macro my_macro_multi {'
// @has - //pre '(_) => { ... },' // @has - //pre '(_) => { ... },'
// @has - //pre '($ foo : ident.$ bar : expr) => { ... },' // @has - //pre '($foo : ident.$bar : expr) => { ... },'
// @has - //pre '($ ($ foo : literal), +) => { ... },' // @has - //pre '($($foo : literal), +) => { ... },'
// @has - //pre '}' // @has - //pre '}'
pub macro my_macro_multi { pub macro my_macro_multi {
(_) => { (_) => {
@ -33,7 +33,7 @@ pub macro my_macro_multi {
} }
} }
// @has decl_macro/macro.by_example_single.html //pre 'pub macro by_example_single($ foo : expr) {' // @has decl_macro/macro.by_example_single.html //pre 'pub macro by_example_single($foo : expr) {'
// @has - //pre '...' // @has - //pre '...'
// @has - //pre '}' // @has - //pre '}'
pub macro by_example_single { pub macro by_example_single {
@ -42,12 +42,12 @@ pub macro by_example_single {
mod a { mod a {
mod b { mod b {
// @has decl_macro/a/b/macro.by_example_vis.html //pre 'pub(super) macro by_example_vis($ foo : expr) {' // @has decl_macro/a/b/macro.by_example_vis.html //pre 'pub(super) macro by_example_vis($foo : expr) {'
pub(in super) macro by_example_vis { pub(in super) macro by_example_vis {
($foo:expr) => {} ($foo:expr) => {}
} }
mod c { mod c {
// @has decl_macro/a/b/c/macro.by_example_vis_named.html //pre 'pub(in a) macro by_example_vis_named($ foo : expr) {' // @has decl_macro/a/b/c/macro.by_example_vis_named.html //pre 'pub(in a) macro by_example_vis_named($foo : expr) {'
pub(in a) macro by_example_vis_named { pub(in a) macro by_example_vis_named {
($foo:expr) => {} ($foo:expr) => {}
} }

View file

@ -14,10 +14,12 @@
// @has - '//span[@class="op"]' '>' // @has - '//span[@class="op"]' '>'
// @has - '{ ... };' // @has - '{ ... };'
// @has - '($ ($' // @has - '($('
// @has - '//span[@class="ident"]' 'arg' // @has - '//span[@class="macro-nonterminal"]' '$'
// @has - '//span[@class="macro-nonterminal"]' 'arg'
// @has - ':' // @has - ':'
// @has - '//span[@class="ident"]' 'tt' // @has - '//span[@class="ident"]' 'tt'
// @has - '),'
// @has - '//span[@class="op"]' '+' // @has - '//span[@class="op"]' '+'
// @has - ')' // @has - ')'
pub use std::todo; pub use std::todo;
@ -27,10 +29,12 @@ mod mod1 {
// @has - 'macro_rules!' // @has - 'macro_rules!'
// @has - 'macro1' // @has - 'macro1'
// @has - '{ ()' // @has - '{ ()'
// @has - '($ (' // @has - '($('
// @has - 'arg' // @has - '//span[@class="macro-nonterminal"]' '$'
// @has - '//span[@class="macro-nonterminal"]' 'arg'
// @has - ':'
// @has - 'expr' // @has - 'expr'
// @has - ',' // @has - '),'
// @has - '+' // @has - '+'
// @has - ')' // @has - ')'
#[macro_export] #[macro_export]

View file

@ -1,7 +1,7 @@
// @has macros/macro.my_macro.html //pre 'macro_rules! my_macro {' // @has macros/macro.my_macro.html //pre 'macro_rules! my_macro {'
// @has - //pre '() => { ... };' // @has - //pre '() => { ... };'
// @has - //pre '($ a : tt) => { ... };' // @has - //pre '($a : tt) => { ... };'
// @has - //pre '($ e : expr) => { ... };' // @has - //pre '($e : expr) => { ... };'
#[macro_export] #[macro_export]
macro_rules! my_macro { macro_rules! my_macro {
() => []; () => [];
@ -12,8 +12,8 @@ macro_rules! my_macro {
// Check that exported macro defined in a module are shown at crate root. // Check that exported macro defined in a module are shown at crate root.
// @has macros/macro.my_sub_macro.html //pre 'macro_rules! my_sub_macro {' // @has macros/macro.my_sub_macro.html //pre 'macro_rules! my_sub_macro {'
// @has - //pre '() => { ... };' // @has - //pre '() => { ... };'
// @has - //pre '($ a : tt) => { ... };' // @has - //pre '($a : tt) => { ... };'
// @has - //pre '($ e : expr) => { ... };' // @has - //pre '($e : expr) => { ... };'
mod sub { mod sub {
#[macro_export] #[macro_export]
macro_rules! my_sub_macro { macro_rules! my_sub_macro {

View file

@ -8,7 +8,7 @@
#![feature /* 0#0 */(no_core)] #![feature /* 0#0 */(no_core)]
#![no_core /* 0#0 */] #![no_core /* 0#0 */]
macro_rules! foo /* 0#0 */ { ($ x : ident) => { y + $ x } } macro_rules! foo /* 0#0 */ { ($x : ident) => { y + $x } }
fn bar /* 0#0 */() { fn bar /* 0#0 */() {
let x /* 0#0 */ = 1; let x /* 0#0 */ = 1;

View file

@ -30,7 +30,7 @@ macro_rules! produce_it
*/ { */ {
() => () =>
{ {
meta_macro :: print_def_site! ($ crate :: dummy! ()) ; meta_macro :: print_def_site! ($crate :: dummy! ()) ;
// `print_def_site!` will respan the `$crate` identifier // `print_def_site!` will respan the `$crate` identifier
// with `Span::def_site()`. This should cause it to resolve // with `Span::def_site()`. This should cause it to resolve
// relative to `meta_macro`, *not* `make_macro` (despite // relative to `meta_macro`, *not* `make_macro` (despite

View file

@ -50,9 +50,9 @@ macro_rules! outer
/* /*
0#0 0#0
*/ { */ {
($ item : item) => ($item : item) =>
{ {
macro inner() { print_bang! { $ item } } inner! () ; macro inner() { print_bang! { $item } } inner! () ;
} ; } ;
} }