about summary refs log tree commit diff
path: root/compiler/rustc_expand/src/mbe/diagnostics.rs
AgeCommit message (Collapse)AuthorLines
2023-12-23Give `DiagnosticBuilder` a default type.Nicholas Nethercote-1/+1
`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-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-11-16More detail when expecting expression but encountering bad macro argumentEsteban Küber-0/+6
Partially address #71039.
2023-07-30inline format!() args up to and including rustc_middleMatthias Krüger-1/+1
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-1/+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-2/+2
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-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-03-17Suggest surrounding the macro with `{}` to interpret as a statementMu42-6/+18
2023-03-10Add note when matching token with nonterminalNilstrieb-3/+9
The current error message is _really_ confusing.
2023-01-05Shrink `ParseResult` in the hot path.Nilstrieb-2/+23
A recent PR increased the size, which caused regressions. This uses the existing generic infrastructure to differentiate between the hot path and the diagnostics path.
2023-01-01Merge multiple mutable borrows of immutable binding errorsEsteban Küber-2/+2
Fix #53466.
2022-12-12Properly calculate best failure in macro matchingNilstrieb-10/+30
Previously, we used spans. This was not good. Sometimes, the span of the token that failed to match may come from a position later in the file which has been transcribed into a token stream way earlier in the file. If precisely this token fails to match, we think that it was the best match because its span is so high, even though other arms might have gotten further in the token stream. We now try to properly use the location in the token stream.
2022-11-20Move macro_rules diagnostics to diagnostics moduleNilstrieb-0/+257