Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test suite for stringify macro #92238

Merged
merged 3 commits into from
Dec 28, 2021
Merged

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Dec 24, 2021

This attempts to cover the behavior of stringify! on various interpolated syntax tree nodes.

The pretty printer has a history of unsightly whitespace (double spaces, missing spaces, spaces where there shouldn't be spaces) — #91437, #91562, #91568. There are several such issues left; the test cases that I consider to be currently behaving incorrectly are marked with // FIXME in the PR.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 24, 2021
@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 24, 2021
@rust-log-analyzer

This comment has been minimized.

assert_eq!(stringify_expr!(async move || self), "async move || self");
assert_eq!(stringify_expr!(static || self), "static || self");
assert_eq!(stringify_expr!(static move || self), "static move || self");
#[rustfmt::skip] // https://github.com/rust-lang/rustfmt/issues/5149
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW src/test/ui isn't formatted by x.py fmt, and is in the ignore list in rustfmt.toml, so in theory this isn't necessary but seems OK for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good call. I hit this because I wrote this whole file in a standalone main.rs to iterate faster than x.py, and just moved the whole finished thing into src/test/ui.

@Mark-Simulacrum
Copy link
Member

@bors r+ rollup

This seems like a good set of tests to me, regardless of whether we necessarily agree to the FIXMEs -- they all looked like places I'd want to see changes as well but I didn't spend too long on that evaluation as it seems not directly relevant to this PR's approval.

@bors
Copy link
Contributor

bors commented Dec 28, 2021

📌 Commit 55fc986 has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 28, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 28, 2021
…acrum

Add a test suite for stringify macro

This attempts to cover the behavior of `stringify!` on various interpolated syntax tree nodes.

The pretty printer has a history of unsightly whitespace (double spaces, missing spaces, spaces where there shouldn't be spaces) — rust-lang#91437, rust-lang#91562, rust-lang#91568. There are several such issues left; the test cases that I consider to be currently behaving incorrectly are marked with `// FIXME` in the PR.
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 28, 2021
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#92076 (Ignore other `PredicateKind`s in rustdoc auto trait finder)
 - rust-lang#92219 (Remove VCVARS_BAT)
 - rust-lang#92238 (Add a test suite for stringify macro)
 - rust-lang#92330 (Add myself to .mailmap)
 - rust-lang#92333 (Tighten span when suggesting lifetime on path)
 - rust-lang#92335 (Document units for `std::column`)
 - rust-lang#92344 (:arrow_up: rust-analyzer)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0b0666e into rust-lang:master Dec 28, 2021
@rustbot rustbot added this to the 1.59.0 milestone Dec 28, 2021
@dtolnay dtolnay deleted the stringifytest branch December 28, 2021 20:21
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 29, 2021
Remove pretty printer space inside block with only outer attrs

Follow-up to rust-lang#92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($expr:expr) => {
        stringify!($expr)
    };
}

fn main() {
    println!("{}", repro!(#[attr] {}));
}
```

Before: `#[attr] { }`
After: `#[attr] {}`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 29, 2021
Print space after formal generic params in fn type

Follow-up to rust-lang#92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($ty:ty) => {
        stringify!($ty)
    };
}

fn main() {
    println!("{}", repro!(for<'a> fn(&'a u8)));
}
```

Before:&ensp;`for<'a>fn(&'a u8)`
After:&ensp;`for<'a> fn(&'a u8)`

The pretty printer's `print_formal_generic_params` already prints formal generic params correctly with a space, we just need to call it when printing BareFn types instead of reimplementing the printing incorrectly without a space.

https://github.com/rust-lang/rust/blob/83b15bfe1c15f325bc186ebfe3691b729ed59f2b/compiler/rustc_ast_pretty/src/pprust/state.rs#L1394-L1400
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 30, 2021
Fix spacing of pretty printed const item without body

Follow-up to rust-lang#92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($item:item) => {
        stringify!($item)
    };
}

fn main() {
    println!("{}", repro!(extern "C" { static S: i32; }));
}
```

Before:&ensp;`extern "C" { static S: i32 ; }`
After:&ensp;`extern "C" { static S: i32; }`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 1, 2022
Fix double space in pretty printed TryBlock

Follow-up to rust-lang#92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($expr:expr) => {
        stringify!($expr)
    };
}

fn main() {
    println!("{}", repro!(try {}));
}
```

Before:&ensp;<code>try&nbsp;&nbsp;{}</code>
After:&ensp;<code>try&nbsp;{}</code>

The `head` helper already appends a space:

https://github.com/rust-lang/rust/blob/2b67c30bfece00357d5fc09d99b49f21066f04ba/compiler/rustc_ast_pretty/src/pprust/state.rs#L654-L664

so doing `head` followed by `space` resulted in a double space:

https://github.com/rust-lang/rust/blob/2b67c30bfece00357d5fc09d99b49f21066f04ba/compiler/rustc_ast_pretty/src/pprust/state.rs#L2241-L2242
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 1, 2022
Fix whitespace in pretty printed PatKind::Range

Follow-up to rust-lang#92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($pat:pat) => {
        stringify!($pat)
    };
}

fn main() {
    println!("{}", repro!(0..=1));
}
```

Before:&ensp;`0 ..=1`
After:&ensp;`0..=1`

The canonical spacing applied by rustfmt has no space after the lower expr. Rustc's parser diagnostics also do not put a space there:

https://github.com/rust-lang/rust/blob/df96fb166f59431e3de443835e50d5b8a7a4adb0/compiler/rustc_parse/src/parser/pat.rs#L754
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 3, 2022
…erister

Fix spacing in pretty printed PatKind::Struct with no fields

Follow-up to rust-lang#92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($pat:pat) => {
        stringify!($pat)
    };
}

fn main() {
    println!("{}", repro!(Struct {}));
}
```

Before:&ensp;<code>Struct&nbsp;{&nbsp;&nbsp;}</code>
After:&ensp;<code>Struct&nbsp;{}</code>
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 6, 2022
Fix spacing and ordering of words in pretty printed Impl

Follow-up to rust-lang#92238 fixing one of the FIXMEs.

```rust
macro_rules! repro {
    ($item:item) => {
        stringify!($item)
    };
}

fn main() {
    println!("{}", repro!(impl<T> Struct<T> {}));
    println!("{}", repro!(impl<T> const Trait for T {}));
}
```

Before:&ensp;`impl <T> Struct<T> {}`
After:&ensp;`impl<T> Struct<T> {}`

Before:&ensp;`impl const <T> Trait for T {}` 😿
After:&ensp;`impl<T> const Trait for T {}`
@dtolnay dtolnay added the A-pretty Area: Pretty printing. label Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pretty Area: Pretty printing. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants