about summary refs log tree commit diff
path: root/compiler/rustc_expand/src/errors.rs
AgeCommit message (Collapse)AuthorLines
2025-07-09mbe: Refactor the diagnostic for unrecognized metavariable expressionsTrevor Gross-0/+10
Change to a structural diagnostic, update the valid list, and move the valid list to a note.
2025-07-09mbe: Refactor diagnostics for invalid metavar expression syntaxTrevor Gross-0/+34
Give a more user-friendly diagnostic about the following: * Trailing tokens within braces, e.g. `${foo() extra}` * Missing parentheses, e.g. `${foo}` * Incorrect number of arguments, with a hint about correct usage.
2025-07-01Rollup merge of #143245 - tgross35:metavariable-expr-organization, ↵Matthias Krüger-8/+13
r=petrochenkov mbe: Add tests and restructure metavariable expressions Add tests that show better diagnostics, and factor `concat` handling to a separate function. Each commit message has further details. This performs the nonfunctional perparation for further changes such as https://github.com/rust-lang/rust/pull/142950 and https://github.com/rust-lang/rust/pull/142975 .
2025-06-30mbe: Shorten `MetaVarExpr` -> `Mve` in structural diagnosticsTrevor Gross-8/+13
More diagnostic structs related to metavariable expressions will be introduced. Introduce the abbreviation "mve" which is reasonably unambiguous (`rg Mve` and `rg '(\b|_|-)mve(\b|_|-)'` return no results outside of a Thumb target feature) and use it for these diagnostic types. A new module is also created.
2025-06-24Rollup merge of #142943 - jieyouxu:no-rustc-version, r=compiler-errorsMatthias Krüger-1/+0
Don't include current rustc version string in feature removed help The version string is difficult to properly normalize out, and removing it isn't a huge deal (the user can query version info easily through `rustc --version` or `cargo --version`). The normalization options were all non-ideal (see https://github.com/rust-lang/rust/pull/142940#issuecomment-2998518450): - Per-test version string normalization is nasty to maintain, and we need to maintain `n` copies of it. See rust-lang/rust#142930 where the regex wasn't robust against different release channels. - Centralized compiletest normalization (with a directive opt-out) is also not ideal, because `cfg(version(..))` tests can't have those accidentally normalized out (and you'd have to remember to opt-out). r? `@workingjubilee` (discussed in rust-lang/rust#142940)
2025-06-24Rollup merge of #142657 - tgross35:nonoptional-fragment-specifiers-cleanup, ↵Matthias Krüger-1/+1
r=petrochenkov mbe: Clean up code with non-optional `NonterminalKind` Since [rust-lang/rust#128425], the fragment specifier is unconditionally required in all editions. This means `NonTerminalKind` no longer needs to be optional, as we can reject this code during the expansion of `macro_rules!` rather than handling it throughout the code. Do this cleanup here. [rust-lang/rust#128425]: https://github.com/rust-lang/rust/pull/128425
2025-06-24Don't include current rustc version string in feature removed helpJieyou Xu-1/+0
The version string is difficult to properly normalize out, and removing it isn't a huge deal (the user can query version info easily through `rustc --version` or `cargo --version`). The normalization options were all non-ideal: - Per-test version string normalization is nasty to maintain, and we need to maintain `n` copies of it. - Centralized compiletest normalization (with a directive opt-out) is also not ideal, because `cfg(version(..))` tests can't have those accidentally normalized out (and you'd have to remember to opt-out).
2025-06-24mbe: Use `TokenTree` as the fallback for invalid fragment specifiersTrevor Gross-1/+1
`tt` should match more, so use this for both missing and invalid fragment specifiers. Also remove one unneeded instance of `String`.
2025-06-20Use a symbol for `ExpansionConfig::crate_name`.Nicholas Nethercote-2/+2
This avoids some symbol interning and `to_string` conversions.
2025-06-09Note the version and PR of removed features when using itxizheyin-0/+4
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-10-28Tweak `expand_incomplete_parse` warning.Nicholas Nethercote-1/+1
By using `token_descr`, as is done for many other errors, we can get slightly better descriptions in error messages, e.g. "macro expansion ignores token `let` and any following" becomes "macro expansion ignores keyword `let` and any tokens following". This will be more important once invisible delimiters start being mentioned in error messages -- without this commit, that leads to error messages such as "error at ``" because invisible delimiters are pretty printed as an empty string.
2024-10-05Make deprecated_cfg_attr_crate_type_name a hard errorest31-0/+14
2024-08-27Add `warn(unreachable_pub)` to `rustc_expand`.Nicholas Nethercote-7/+7
Plus a tiny bit of reformatting.
2024-08-21Use bool in favor of Option<()> for diagnosticsMichael Goulet-1/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-1/+2
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-27Make `missing_fragment_specifier` an error in edition 2024Trevor Gross-0/+17
`missing_fragment_specifier` has been a future compatibility warning since 2017. Uplifting it to an unconditional hard error was attempted in 2020, but eventually reverted due to fallout. Make it an error only in edition >= 2024, leaving the lint for older editions. This change will make it easier to support more macro syntax that relies on usage of `$`. Fixes <https://github.com/rust-lang/rust/issues/40107>
2024-06-22delegation: Do not crash on qpaths without a traitVadim Petrochenkov-0/+7
2024-06-14delegation: Implement glob delegationVadim Petrochenkov-2/+10
2024-05-28Convert `proc_macro_back_compat` lint to an unconditional error.Nicholas Nethercote-0/+10
We still check for the `rental`/`allsorts-rental` crates. But now if they are detected we just emit a fatal error, instead of emitting a warning and providing alternative behaviour. The original "hack" implementing alternative behaviour was added in #73345. The lint was added in #83127. The tracking issue is #83125. The direct motivation for the change is that providing the alternative behaviour is interfering with #125174 and follow-on work.
2024-05-15delegation: Implement list delegationVadim Petrochenkov-0/+7
```rust reuse prefix::{a, b, c} ```
2024-04-29Remove `extern crate rustc_macros` from numerous crates.Nicholas Nethercote-1/+1
2024-04-26Move some functions from `rustc_expand` to `rustc_builtin_macros`.Nicholas Nethercote-23/+0
These functions are only used in `rustc_builtin_macros`, so it makes sense for them to live there. This allows them to be changed from `pub` to `pub(crate)`.
2024-03-20make "expected paren or brace" error translatableTshepang Mbambo-0/+8
2024-02-21Rollup merge of #121288 - tshepang:make-expand-translatable, r=michaelwoeristerDylan DPC-0/+30
make rustc_expand translatable these are the last of the easy ones
2024-02-20make "proc-macro derive panicked" translatableTshepang Mbambo-0/+15
2024-02-19make "custom attribute panicked" translatableTshepang Mbambo-0/+15
2024-02-16make "invalid fragment specifier" translatableTshepang Mbambo-0/+10
2024-01-29Stop using `String` for error codes.Nicholas Nethercote-5/+6
Error codes are integers, but `String` is used everywhere to represent them. Gross! This commit introduces `ErrCode`, an integral newtype for error codes, replacing `String`. It also introduces a constant for every error code, e.g. `E0123`, and removes the `error_code!` macro. The constants are imported wherever used with `use rustc_errors::codes::*`. With the old code, we have three different ways to specify an error code at a use point: ``` error_code!(E0123) // macro call struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call \#[diag(name, code = "E0123")] // string struct Diag; ``` With the new code, they all use the `E0123` constant. ``` E0123 // constant struct_span_code_err!(dcx, span, E0123, "msg"); // constant \#[diag(name, code = E0123)] // constant struct Diag; ``` The commit also changes the structure of the error code definitions: - `rustc_error_codes` now just defines a higher-order macro listing the used error codes and nothing else. - Because that's now the only thing in the `rustc_error_codes` crate, I moved it into the `lib.rs` file and removed the `error_codes.rs` file. - `rustc_errors` uses that macro to define everything, e.g. the error code constants and the `DIAGNOSTIC_TABLES`. This is in its new `codes.rs` file.
2024-01-17Improved collapse_debuginfo attribute, added command-line flag (no|external|yes)Andrew Zhogin-0/+7
2023-12-10Remove edition umbrella features.Eric Huss-10/+0
2023-12-03Detect attempts to expand a macro to a match arm againNadrieril-0/+2
Because a macro invocation can expand to a never pattern, we can't rule out a `arm!(),` arm at parse time. Instead we detect that case at expansion time, if the macro tries to output a pattern followed by `=>`.
2023-10-21Mention the syntax for `use` on `mod foo;` if `foo` doesn't existEsteban Küber-0/+1
Newcomers might get confused that `mod` is the only way of defining scopes, and that it can be used as if it were `use`. Fix #69492.
2023-04-25Fix static string lintsclubby789-0/+10
2023-03-04rustc_expand: make proc-macro derive error translatableTshepang Mbambo-0/+7
2023-02-24make "proc macro panicked" translatableTshepang Mbambo-0/+15
2023-02-22errors: generate typed identifiers in each crateDavid Wood-7/+7
Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter. Signed-off-by: David Wood <david.wood@huawei.com>
2023-01-30session: diagnostic migration lint on more fnsDavid Wood-0/+7
Apply the diagnostic migration lint to more functions on `Session`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-12-10Migrate parts of `rustc_expand` to session diagnosticsnils-2/+324
This migrates everything but the `mbe` and `proc_macro` modules. It also contains a few cleanups and drive-by/accidental diagnostic improvements which can be seen in the diff for the UI tests.
2022-10-23Migrate all diagnosticsNilstrieb-6/+6
2022-09-21UPDATE - rename DiagnosticHandler macro to DiagnosticJhonny Bill Mena-7/+7
2022-09-21UPDATE - rename DiagnosticHandler trait to IntoDiagnosticJhonny Bill Mena-7/+7
2022-08-21Replace #[lint/warning/error] with #[diag]Xiretza-6/+6
2022-08-17Hotfix for duplicated slug name on VarStillRepeating structnidnogg-1/+1
2022-08-17Moved structs to rustc_expand::errors, added several more migrations, fixed ↵nidnogg-3/+1
slug name
2022-08-17Moved structs to rustc_expand::errors, added several more migrations, fixed ↵nidnogg-0/+50
slug name