about summary refs log tree commit diff
path: root/compiler/rustc_expand/src/mbe
AgeCommit message (Collapse)AuthorLines
2023-12-23Give `DiagnosticBuilder` a default type.Nicholas Nethercote-3/+3
`IntoDiagnostic` defaults to `ErrorGuaranteed`, because errors are the most common diagnostic level. It makes sense to do likewise for the closely-related (and much more widely used) `DiagnosticBuilder` type, letting us write `DiagnosticBuilder<'a, ErrorGuaranteed>` as just `DiagnosticBuilder<'a>`. This cuts over 200 lines of code due to many multi-line things becoming single line things.
2023-12-18Rename many `DiagCtxt` and `EarlyDiagCtxt` locals.Nicholas Nethercote-3/+3
2023-12-18Rename `Session::span_diagnostic` as `Session::dcx`.Nicholas Nethercote-7/+7
2023-12-18Rename `ParseSess::span_diagnostic` as `ParseSess::dcx`.Nicholas Nethercote-34/+30
2023-12-17Rollup merge of #118928 - EliseZeroTwo:EliseZeroTwo/fix-issue-118786, r=cjgillotMatthias Krüger-0/+7
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/+7
2023-12-13Auto merge of #117050 - c410-f3r:here-we-go-again, r=petrochenkovbors-32/+65
[`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-11Add spacing information to delimiters.Nicholas Nethercote-32/+51
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-1/+1
`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-01Attempt to try to resolve blocking concernsCaio-32/+65
2023-12-02Use `Session::diagnostic` in more places.Nicholas Nethercote-10/+7
2023-12-02Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`.Nicholas Nethercote-2/+2
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug` follows the pattern used everywhere else: `span_err`, `span_warning`, etc.
2023-12-02Rename `*note_without_error` as `*note`.Nicholas Nethercote-5/+3
Because the variant name in `Level` is `Note`, and the `without_error` suffix is omitted in similar cases like `struct_allow` and `struct_help`.
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-18/+16
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-16More detail when expecting expression but encountering bad macro argumentEsteban Küber-2/+8
Partially address #71039.
2023-10-13Format all the let chains in compilerMichael Goulet-19/+19
2023-08-18Auto merge of #114915 - nnethercote:Nonterminal-cleanups, r=petrochenkovbors-8/+7
`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-18Rename `NtOrTt` as `ParseNtResult`.Nicholas Nethercote-3/+3
It's more descriptive, and future-proofs it if/when additional variants get added.
2023-08-17[RFC-3086] Restrict the parsing of `count`Caio-1/+11
2023-08-17Remove unnecessary braces on `PatWithOr` patterns.Nicholas Nethercote-1/+1
2023-08-17Remove some unnecessary (and badly named) local variables.Nicholas Nethercote-4/+3
2023-08-11rustc: Move `features` from `Session` to `GlobalCtxt`Vadim Petrochenkov-2/+5
Removes two pieces of mutable state. Follow up to #114622.
2023-08-01Auto merge of #114273 - nnethercote:move-doc-comment-desugaring, r=petrochenkovbors-12/+16
Move doc comment desugaring out of `TokenCursor`. It's awkward that `TokenCursor` sometimes desugars doc comments on the fly, but usually doesn't. r? `@petrochenkov`
2023-07-31Remove `desugar_doc_comments` arg from `Parser::new()`.Nicholas Nethercote-4/+9
It's only true at one call site; do the desugaring there instead.
2023-07-31No need to desugar doc comments when parsing decl macro definitions.Nicholas Nethercote-1/+1
2023-07-31Reflow an overlong comment.Nicholas Nethercote-2/+2
2023-07-31Remove more unnecessary `return` keywords.Nicholas Nethercote-6/+5
2023-07-30inline format!() args up to and including rustc_middleMatthias Krüger-16/+15
2023-07-27Avoid some token tree cloning in decl macro parsing.Nicholas Nethercote-23/+23
By changing `into_trees` into `trees`. Some of the subsequent paths require explicit clones, but not all.
2023-07-19Make it clearer that edition functions are >=, not ==Michael Goulet-1/+1
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-12/+10
2023-07-03perform TokenStream replacement in-place when possible in expand_macroThe 8472-2/+1
2023-06-21Fix msg passed to span_bugRaminder Singh-1/+1
2023-06-16Add `SyntaxContext::is_root`Maybe Waffle-2/+2
2023-06-07feat(expand): emit note for doc comment in macro matcherbohan-11/+35
2023-06-06fix(expand): prevent infinity loop in macro containing only "///"bohan-0/+2
2023-05-29Use `Cow` in `{D,Subd}iagnosticMessage`.Nicholas Nethercote-5/+5
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment: ``` // FIXME(davidtwco): can a `Cow<'static, str>` be used here? ``` This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging. This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths. Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile.
2023-05-16Avoid `&format("...")` calls in error message code.Nicholas Nethercote-7/+12
Error message all end up passing into a function as an `impl Into<{D,Subd}iagnosticMessage>`. If an error message is creatd as `&format("...")` that means we allocate a string (in the `format!` call), then take a reference, and then clone (allocating again) the reference to produce the `{D,Subd}iagnosticMessage`, which is silly. This commit removes the leading `&` from a lot of these cases. This means the original `String` is moved into the `{D,Subd}iagnosticMessage`, avoiding the double allocations. This requires changing some function argument types from `&str` to `String` (when all arguments are `String`) or `impl Into<{D,Subd}iagnosticMessage>` (when some arguments are `String` and some are `&str`).
2023-05-04Auto merge of #111014 - klensy:no-rc, r=WaffleLapkinbors-11/+12
try to downgrade Arc -> Lrc -> Rc -> no-Rc in few places Expecting this be not slower on non-parallel compiler and probably faster on parallel (checked that this PR builds on it).
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-13/+13
Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile.
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-04-30Lrc -> Rcklensy-11/+12
2023-04-25Fix static string lintsclubby789-4/+2
2023-04-17Spelling - compilerJosh Soref-2/+2
* account * achieved * advising * always * ambiguous * analysis * annotations * appropriate * build * candidates * cascading * category * character * clarification * compound * conceptually * constituent * consts * convenience * corresponds * debruijn * debug * debugable * debuggable * deterministic * discriminant * display * documentation * doesn't * ellipsis * erroneous * evaluability * evaluate * evaluation * explicitly * fallible * fulfill * getting * has * highlighting * illustrative * imported * incompatible * infringing * initialized * into * intrinsic * introduced * javascript * liveness * metadata * monomorphization * nonexistent * nontrivial * obligation * obligations * offset * opaque * opportunities * opt-in * outlive * overlapping * paragraph * parentheses * poisson * precisely * predecessors * predicates * preexisting * propagated * really * reentrant * referent * responsibility * rustonomicon * shortcircuit * simplifiable * simplifications * specify * stabilized * structurally * suggestibility * translatable * transmuting * two * unclosed * uninhabited * visibility * volatile * workaround Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-12compiler: print the suggestion only for local macrosLena Milizé-2/+5
And wrap the link in the diagnostic in angle brackets. Signed-off-by: Lena Milizé <me@lvmn.org>
2023-04-12compiler: improve captured metavariables diagnosticLena Milizé-1/+3
Adds a link to the relevant part of The Rust Reference in the eror message, and suggests a possible fix (replacing the fragment specifier with :tt in the macro definition). Fixes typos in the original message. Signed-off-by: Lena Milizé <me@lvmn.org>
2023-04-09Fix some clippy::complexityNilstrieb-1/+1
2023-03-17Suggest surrounding the macro with `{}` to interpret as a statementMu42-6/+18
2023-03-15unequal → not equalgimbles-1/+1
2023-03-10Add note when matching token with nonterminalNilstrieb-3/+9
The current error message is _really_ confusing.