about summary refs log tree commit diff
path: root/tests/ui/macros
AgeCommit message (Collapse)AuthorLines
2023-12-17Rollup merge of #118928 - EliseZeroTwo:EliseZeroTwo/fix-issue-118786, r=cjgillotMatthias Krüger-0/+63
fix: Overlapping spans in delimited meta-vars Closes #118786 Delimited meta-vars inside of MBE's spans were set to have the same opening and closing position resulting in an ICE when debug assertions were enabled and an error was present in the templated code. This ensures that the spans do not overlap, whilst still having the spans point at the usage of the meta-var inside the macro definition. It includes a regression test. 🖤
2023-12-13fix: Overlapping spans in delimited meta-varsEliseZeroTwo-0/+63
2023-12-13Auto merge of #117050 - c410-f3r:here-we-go-again, r=petrochenkovbors-210/+198
[`RFC 3086`] Attempt to try to resolve blocking concerns Implements what is described at https://github.com/rust-lang/rust/issues/83527#issuecomment-1744822345 to hopefully make some progress. It is unknown if such approach is or isn't desired due to the lack of further feedback, as such, it is probably best to nominate this PR to the official entities. `@rustbot` labels +I-compiler-nominated
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-22/+22
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-195/+147
`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-12-04dedup for duplicate suggestionsbohan-0/+31
2023-12-01Attempt to try to resolve blocking concernsCaio-210/+198
2023-11-29Add `never_patterns` feature gateNadrieril-0/+5
2023-11-24Show number in error message even for one errorNilstrieb-65/+65
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-16More detail when expecting expression but encountering bad macro argumentEsteban Küber-4/+50
Partially address #71039.
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-10Don't `escape_debug` the condition of `assert!`.Nicholas Nethercote-1/+2
The assertion in `assert-long-condition.rs` used to be fail like this, all on one line: ``` thread 'main' panicked at 'assertion failed: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18\n + 19 + 20 + 21 + 22 + 23 + 24 + 25 == 0', tests/ui/macros/assert-long-condition.rs:7:5 ``` The `\n` and subsequent indent is because the condition is pretty-printed, and the pretty-printer inserts a newline. Printing the newline in this way is arguably reasonable given that the message appears within single quotes, which is very similar to a string literal. However, after the assertion printing improvements that were released in 1.73, the assertion now fails like this: ``` thread 'main' panicked at tests/ui/macros/assert-long-condition.rs:7:5: assertion failed: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18\n + 19 + 20 + 21 + 22 + 23 + 24 + 25 == 0 ``` Now that there are no single quotes around the pretty-printed condition, the `\n` is quite strange. This commit gets rid of the `\n`, by removing the `escape_debug` done on the pretty-printed message. This results in the following: ``` thread 'main' panicked at tests/ui/macros/assert-long-condition.rs:7:5: assertion failed: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 == 0 ``` The overly-large indent is still strange, but that's a separate pretty-printing issue. This change helps with #108341.
2023-10-10Add a ui test with an assertion that has a really long condition.Nicholas Nethercote-0/+12
The `\n` in the output is a little surprising. The next commit will deal with it.
2023-10-05Add a note to duplicate diagnosticsAlex Macleod-0/+10
2023-10-03Gate against auto traits pre-expansionMichael Goulet-0/+1
2023-09-04Add help to allow lint for the implied by suggestionUrgau-0/+1
2023-08-28Move testsCaio-0/+11
2023-08-24Move issue 29181, 2804, 17431, 66768Olanti-0/+81
2023-08-18Auto merge of #114915 - nnethercote:Nonterminal-cleanups, r=petrochenkovbors-2/+18
`Nonterminal`-related cleanups In #114647 I am trying to remove `Nonterminal`. It has a number of preliminary cleanups that are worth merging even if #114647 doesn't merge, so let's do them in this PR. r? `@petrochenkov`
2023-08-17[RFC-3086] Restrict the parsing of `count`Caio-0/+33
2023-08-17Add a failing case to `tests/ui/macros/macro-interpolation`.Nicholas Nethercote-2/+18
This test currently tests the successful paths for the `Interpolated`/`NtTy`/`Path` case in `parse_path_inner`, but it doesn't test the failure path.
2023-08-15Cleaner assert_eq! & assert_ne! panic messagesYuri Astrakhan-15/+15
Modify panic message for `assert_eq!`, `assert_ne!`, the currently unstable `assert_matches!`, as well as the corresponding `debug_assert_*` macros. ```rust assert_eq!(1 + 1, 3); assert_eq!(1 + 1, 3, "my custom message value={}!", 42); ``` ```plain thread 'main' panicked at $DIR/main.rs:6:5: assertion failed: `(left == right)` left: `2`, right: `3` ``` ```plain thread 'main' panicked at $DIR/main.rs:6:5: assertion failed: `(left == right)` left: `2`, right: `3`: my custom message value=42! ``` ```plain thread 'main' panicked at $DIR/main.rs:6:5: assertion `left == right` failed left: 2 right: 3 ``` ```plain thread 'main' panicked at $DIR/main.rs:6:5: assertion `left == right` failed: my custom message value=42! left: 2 right: 3 ``` This PR is a simpler subset of the #111030, but it does NOT stringify the original left and right source code assert expressions, thus should be faster to compile.
2023-07-29Change default panic handler message format.Mara Bos-10/+13
2023-07-25builtin_macros: raw str in diagnostic outputDavid Wood-3/+16
If a raw string was used in the `env!` invocation, then it should also be shown in the diagnostic messages as a raw string. Signed-off-by: David Wood <david@davidtw.co>
2023-07-24builtin_macros: expect raw strings tooDavid Wood-0/+17
`expr_to_string` allows raw strings through so this code should be expected to handle those. Signed-off-by: David Wood <david@davidtw.co>
2023-07-10Do not set up wrong span for adjustmentsMichael Goulet-6/+4
2023-07-07Add filter with next segment while lookup typo for pathyukang-4/+0
2023-07-04Auto merge of #112917 - chenyukang:yukang-fix-112590, r=estebankbors-8/+24
Suggest importing for partial mod path matching in name resolving Fixes #112590
2023-06-28Rollup merge of #111571 - jhpratt:proc-macro-span, r=m-ou-seDylan DPC-9/+3
Implement proposed API for `proc_macro_span` As proposed in [#54725 (comment)](https://github.com/rust-lang/rust/issues/54725#issuecomment-1546918161). I have omitted the byte-level API as it's already available as [`Span::byte_range`](https://doc.rust-lang.org/nightly/proc_macro/struct.Span.html#method.byte_range). `@rustbot` label +A-proc-macros r? `@m-ou-se`
2023-06-22Tweak privacy errors to account for reachable itemsEsteban Küber-2/+2
Suggest publicly accessible paths for items in private mod: When encountering a path in non-import situations that are not reachable due to privacy constraints, search for any public re-exports that the user could use instead. Track whether an import suggestion is offering a re-export. When encountering a path with private segments, mention if the item at the final path segment is not publicly accessible at all. Add item visibility metadata to privacy errors from imports: On unreachable imports, record the item that was being imported in order to suggest publicly available re-exports or to be explicit that the item is not available publicly from any path. In order to allow this, we add a mode to `resolve_path` that will not add new privacy errors, nor return early if it encounters one. This way we can get the `Res` corresponding to the final item in the import, which is used in the privacy error machinery.
2023-06-22suggest importing for partial mod path in name resolvingyukang-8/+24
2023-06-20Fix testsJacob Pratt-9/+3
2023-06-12Adjust UI tests for `unit_bindings`许杰友 Jieyou Xu (Joe)-7/+7
- Either explicitly annotate `let x: () = expr;` where `x` has unit type, or remove the unit binding to leave only `expr;` instead. - Fix disjoint-capture-in-same-closure test
2023-06-10Make "consider importing" consistent for macrosMu001999-11/+20
2023-06-07Auto merge of #109005 - Nilstrieb:dont-forgor-too-much-from-cfg, r=petrochenkovbors-0/+8
Remember names of `cfg`-ed out items to mention them in diagnostics # Examples ## `serde::Deserialize` without the `derive` feature (a classic beginner mistake) I had to slightly modify serde so that it uses explicit re-exports instead of a glob re-export. (Update: a serde PR was merged that adds the manual re-exports) ``` error[E0433]: failed to resolve: could not find `Serialize` in `serde` --> src/main.rs:1:17 | 1 | #[derive(serde::Serialize)] | ^^^^^^^^^ could not find `Serialize` in `serde` | note: crate `serde` has an item named `Serialize` but it is inactive because its cfg predicate evaluated to false --> /home/gh-Nilstrieb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.160/src/lib.rs:343:1 | 343 | #[cfg(feature = "serde_derive")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 344 | pub use serde_derive::{Deserialize, Serialize}; | ^^^^^^^^^ = note: the item is gated behind the `serde_derive` feature = note: see https://doc.rust-lang.org/cargo/reference/features.html for how to activate a crate's feature ``` (the suggestion is not ideal but that's serde's fault) I already tested the metadata size impact locally by compiling the `windows` crate without any features. `800k` -> `809k` r? `@ghost`
2023-06-07feat(expand): emit note for doc comment in macro matcherbohan-1/+84
2023-06-06fix(expand): prevent infinity loop in macro containing only "///"bohan-0/+93
2023-06-01Remember names of `cfg`-ed out items to mention them in diagnosticsNilstrieb-0/+8
`#[cfg]`s are frequently used to gate crate content behind cargo features. This can lead to very confusing errors when features are missing. For example, `serde` doesn't have the `derive` feature by default. Therefore, `serde::Serialize` fails to resolve with a generic error, even though the macro is present in the docs. This commit adds a list of all stripped item names to metadata. This is filled during macro expansion and then, through a fed query, persisted in metadata. The downstream resolver can then access the metadata to look at possible candidates for mentioning in the errors. This slightly increases metadata (800k->809k for the feature-heavy windows crate), but not enough to really matter.
2023-05-24[RFC-2011] Expand more expressionsCaio-80/+17
2023-05-21Rename `drop_copy` lint to `dropping_copy_types`Urgau-1/+1
2023-05-19fix: emit error when fragment is `MethodReceiverExpr` and items is emptybohan-0/+30