-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@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. |
📌 Commit 55fc986 has been approved by |
…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.
…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
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] {}`
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: `for<'a>fn(&'a u8)` After: `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
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: `extern "C" { static S: i32 ; }` After: `extern "C" { static S: i32; }`
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: <code>try {}</code> After: <code>try {}</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
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: `0 ..=1` After: `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
…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: <code>Struct { }</code> After: <code>Struct {}</code>
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: `impl <T> Struct<T> {}` After: `impl<T> Struct<T> {}` Before: `impl const <T> Trait for T {}` 😿 After: `impl<T> const Trait for T {}`
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.