about summary refs log tree commit diff
path: root/tests/ui/macros/stringify.rs
AgeCommit message (Collapse)AuthorLines
2025-06-30Remove let_chains featureCameron Steffen-2/+1
2025-06-26Change const trait bound syntax from ~const to [const]Oli Scherer-3/+2
2025-04-29Improve pretty-printing of braces.Nicholas Nethercote-2/+2
Most notably, the `FIXME` for suboptimal printing of `use` groups in `tests/ui/macros/stringify.rs` is fixed. And all other test output changes result in pretty printed output being closer to the original formatting in the source code.
2025-04-29Add a few extra tests to `tests/ui/macros/stringify.rs`.Nicholas Nethercote-2/+18
2025-03-28Add `{ast,hir,thir}::PatKind::Missing` variants.Nicholas Nethercote-0/+2
"Missing" patterns are possible in bare fn types (`fn f(u32)`) and similar places. Currently these are represented in the AST with `ast::PatKind::Ident` with no `by_ref`, no `mut`, an empty ident, and no sub-pattern. This flows through to `{hir,thir}::PatKind::Binding` for HIR and THIR. This is a bit nasty. It's very non-obvious, and easy to forget to check for the exceptional empty identifier case. This commit adds a new variant, `PatKind::Missing`, to do it properly. The process I followed: - Add a `Missing` variant to `{ast,hir,thir}::PatKind`. - Chang `parse_param_general` to produce `ast::PatKind::Missing` instead of `ast::PatKind::Missing`. - Look through `kw::Empty` occurrences to find functions where an existing empty ident check needs replacing with a `PatKind::Missing` check: `print_param`, `check_trait_item`, `is_named_param`. - Add a `PatKind::Missing => unreachable!(),` arm to every exhaustive match identified by the compiler. - Find which arms are actually reachable by running the test suite, changing them to something appropriate, usually by looking at what would happen to a `PatKind::Ident`/`PatKind::Binding` with no ref, no `mut`, an empty ident, and no subpattern. Quite a few of the `unreachable!()` arms were never reached. This makes sense because `PatKind::Missing` can't happen in every pattern, only in places like bare fn tys and trait fn decls. I also tried an alternative approach: modifying `ast::Param::pat` to hold an `Option<P<Pat>>` instead of a `P<Pat>`, but that quickly turned into a very large and painful change. Adding `PatKind::Missing` is much easier.
2025-01-08Rename PatKind::Lit to ExprOli Scherer-1/+1
2024-12-13Stabilize async closuresMichael Goulet-1/+0
2024-08-18stabilize raw_ref_opRalf Jung-1/+0
2024-08-16Overhaul token collection.Nicholas Nethercote-16/+8
This commit does the following. - Renames `collect_tokens_trailing_token` as `collect_tokens`, because (a) it's annoying long, and (b) the `_trailing_token` bit is less accurate now that its types have changed. - In `collect_tokens`, adds a `Option<CollectPos>` argument and a `UsePreAttrPos` in the return type of `f`. These are used in `parse_expr_force_collect` (for vanilla expressions) and in `parse_stmt_without_recovery` (for two different cases of expression statements). Together these ensure are enough to fix all the problems with token collection and assoc expressions. The changes to the `stringify.rs` test demonstrate some of these. - Adds a new test. The code in this test was causing an assertion failure prior to this commit, due to an invalid `NodeRange`. The extra complexity is annoying, but necessary to fix the existing problems.
2024-08-16Add some attribute `stringify!` tests.Nicholas Nethercote-2/+53
A couple of these are marked `FIXME` because they demonstrate existing bugs with token collection.
2024-06-05Print `token::Interpolated` with token stream pretty printing.Nicholas Nethercote-207/+52
Instead of using AST pretty printing. This is a step towards removing `token::Interpolated`, which will eventually (in #124141) be replaced with a token stream within invisible delimiters. This changes (improves) the output of the `stringify!` macro in some cases. This is allowed. As the `stringify!` docs say: "Note that the expanded results of the input tokens may change in the future. You should be careful if you rely on the output." Test changes: - tests/ui/macros/stringify.rs: this used to test both token stream pretty printing and AST pretty printing via different ways of invoking of `stringify!` (i.e. `$expr` vs `$tt`). But those two different invocations now give the same result, which is a nice consistency improvement. This removes the need for all the `c2*` macros. The AST pretty printer now has more thorough testing thanks to #125236. - tests/ui/proc-macro/*: minor improvements where small differences between `INPUT (DISPLAY)` output and `DEEP-RE-COLLECTED (DISPLAY)` output disappear.
2024-05-12Add AST pretty-printer tests for let-elseDavid Tolnay-0/+15
2024-05-11Fix redundant parens around braced macro call in match armsDavid Tolnay-1/+1
2024-05-11Fix pretty printer statement boundaries after braced macro callDavid Tolnay-2/+2
2024-05-11Add ExprKind::MacCall statement boundary testsDavid Tolnay-0/+30
2024-02-16[AUTO-GENERATED] Migrate ui tests from `//` to `//@` directives许杰友 Jieyou Xu (Joe)-3/+3
2024-01-22Fix some cases in `space_between`.Nicholas Nethercote-17/+16
There are a number of cases where we erroneously omit the space between two tokens, all involving an exception to a more general case. The affected tokens are `$`, `!`, `.`, `,`, and `let` followed by a parenthesis. This fixes a lot of FIXME comments.
2023-12-18Fix parenthesization of subexprs containing statement boundaryDavid Tolnay-12/+6
2023-12-18Test parenthesization of leftmost subexprs containing stmt boundariesDavid Tolnay-0/+66
2023-12-11Rollup merge of #118726 - dtolnay:matchguardlet, r=compiler-errorsMatthias Krüger-1/+20
Do not parenthesize exterior struct lit inside match guards Before this PR, the AST pretty-printer injects parentheses around expressions any time parens _could_ be needed depending on what else is in the code that surrounds that expression. But the pretty-printer did not pass around enough context to understand whether parentheses really _are_ needed on any particular expression. As a consequence, there are false positives where unneeded parentheses are being inserted. Example: ```rust #![feature(if_let_guard)] macro_rules! pp { ($e:expr) => { stringify!($e) }; } fn main() { println!("{}", pp!(match () { () if let _ = Struct {} => {} })); } ``` **Before:** ```console match () { () if let _ = (Struct {}) => {} } ``` **After:** ```console match () { () if let _ = Struct {} => {} } ``` This PR introduces a bit of state that is passed across various expression printing methods to help understand accurately whether particular situations require parentheses injected by the pretty printer, and it fixes one such false positive involving match guards as shown above. There are other parenthesization false positive cases not fixed by this PR. I intend to address these in follow-up PRs. For example here is one: the expression `{ let _ = match x {} + 1; }` is pretty-printed as `{ let _ = (match x {}) + 1; }` despite there being no reason for parentheses to appear there.
2023-12-11Add a few cases with wonky formatting to `stringify.rs` test.Nicholas Nethercote-0/+4
Because the spacing-based pretty-printing partially preserves that.
2023-12-11Add spacing information to delimiters.Nicholas Nethercote-15/+15
This is an extension of the previous commit. It means the output of something like this: ``` stringify!(let a: Vec<u32> = vec![];) ``` goes from this: ``` let a: Vec<u32> = vec![] ; ``` With this PR, it now produces this string: ``` let a: Vec<u32> = vec![]; ```
2023-12-11Improve `print_tts` by changing `tokenstream::Spacing`.Nicholas Nethercote-192/+144
`tokenstream::Spacing` appears on all `TokenTree::Token` instances, both punct and non-punct. Its current usage: - `Joint` means "can join with the next token *and* that token is a punct". - `Alone` means "cannot join with the next token *or* can join with the next token but that token is not a punct". The fact that `Alone` is used for two different cases is awkward. This commit augments `tokenstream::Spacing` with a new variant `JointHidden`, resulting in: - `Joint` means "can join with the next token *and* that token is a punct". - `JointHidden` means "can join with the next token *and* that token is a not a punct". - `Alone` means "cannot join with the next token". This *drastically* improves the output of `print_tts`. For example, this: ``` stringify!(let a: Vec<u32> = vec![];) ``` currently produces this string: ``` let a : Vec < u32 > = vec! [] ; ``` With this PR, it now produces this string: ``` let a: Vec<u32> = vec![] ; ``` (The space after the `]` is because `TokenTree::Delimited` currently doesn't have spacing information. The subsequent commit fixes this.) The new `print_tts` doesn't replicate original code perfectly. E.g. multiple space characters will be condensed into a single space character. But it's much improved. `print_tts` still produces the old, uglier output for code produced by proc macros. Because we have to translate the generated code from `proc_macro::Spacing` to the more expressive `token::Spacing`, which results in too much `proc_macro::Along` usage and no `proc_macro::JointHidden` usage. So `space_between` still exists and is used by `print_tts` in conjunction with the `Spacing` field. This change will also help with the removal of `Token::Interpolated`. Currently interpolated tokens are pretty-printed nicely via AST pretty printing. `Token::Interpolated` removal will mean they get printed with `print_tts`. Without this change, that would result in much uglier output for code produced by decl macro expansions. With this change, AST pretty printing and `print_tts` produce similar results. The commit also tweaks the comments on `proc_macro::Spacing`. In particular, it refers to "compound tokens" rather than "multi-char operators" because lifetimes aren't operators.
2023-12-08Do not parenthesize exterior struct lit inside match guardsDavid Tolnay-1/+1
2023-12-08Add if_let_guard and let_chains pretty printer testsDavid Tolnay-1/+20
2023-11-29Add `never_patterns` feature gateNadrieril-0/+5
2023-11-08More tests for token stream pretty-printing with adjacent punctuation.Nicholas Nethercote-0/+29
We currently do the wrong thing on a lot of these. The next commit will fix things.
2023-11-08Clarify `space_between`.Nicholas Nethercote-0/+2
To avoid `!matches!(...)`, which is hard to think about. Instead every case now uses direct pattern matching and returns true or false. Also add a couple of cases to the `stringify.rs` test that currently print badly.
2023-10-24Augment `stringify.rs` test some more.Nicholas Nethercote-40/+38
By making some case more complex, adding some new cases, tweaking formatting, and removing unnecessary `rustfmt` attributes.
2023-10-24Augment `stringify.rs` test.Nicholas Nethercote-2/+47
By adding tests (or placeholders, or comments) for missing AST variants.
2023-10-24Redo `stringify.rs` test.Nicholas Nethercote-539/+412
Currently it only tests AST pretty-printing. This commit changes it to run every example through both AST pretty-printing and TokenStream pretty-printing. This makes it clear where there two pretty-printing approaches produce different results.
2023-10-20s/generator/coroutine/Oli Scherer-1/+1
2023-10-03Gate against auto traits pre-expansionMichael Goulet-0/+1
2023-05-01Rip it outNilstrieb-2/+1
My type ascription Oh rip it out Ah If you think we live too much then You can sacrifice diagnostics Don't mix your garbage Into my syntax So many weird hacks keep diagnostics alive Yet I don't even step outside So many bad diagnostics keep tyasc alive Yet tyasc doesn't even bother to survive!
2023-03-12Remove uses of `box_syntax` in rustc and toolsclubby789-4/+0
2023-02-07Expand const-if-const trait bounds correctlyMichael Goulet-3/+3
2023-01-11Move /src/test to /testsAlbert Larsan-0/+889