about summary refs log tree commit diff
path: root/compiler/rustc_macros
AgeCommit message (Collapse)AuthorLines
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-53/+44
2024-08-29Add `warn(unreachable_pub)` to `rustc_metadata`.Nicholas Nethercote-7/+21
2024-08-29Add `warn(unreachable_pub)` to `rustc_macros`.Nicholas Nethercote-16/+17
2024-08-26Remove a couple of unused feature enablesbjorn3-2/+0
2024-07-29Reformat `use` declarations.Nicholas Nethercote-29/+34
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-17lift_to_tcx -> lift_to_internerMichael Goulet-1/+1
2024-07-14Suppress some fallout from gen in synstructureMichael Goulet-0/+8
2024-07-10Make sure that labels are defined after the primary span in diagnosticsMichael Goulet-0/+9
2024-06-18Remove redundant argument from `subdiagnostic` methodOli Scherer-1/+1
2024-06-18Use a dedicated type instead of a reference for the diagnostic contextOli Scherer-1/+1
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-12Use `tidy` to sort crate attributes for all compiler crates.Nicholas Nethercote-2/+4
We already do this for a number of crates, e.g. `rustc_middle`, `rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`. For the ones we don't, in many cases the attributes are a mess. - There is no consistency about order of attribute kinds (e.g. `allow`/`deny`/`feature`). - Within attribute kind groups (e.g. the `feature` attributes), sometimes the order is alphabetical, and sometimes there is no particular order. - Sometimes the attributes of a particular kind aren't even grouped all together, e.g. there might be a `feature`, then an `allow`, then another `feature`. This commit extends the existing sorting to all compiler crates, increasing consistency. If any new attribute line is added there is now only one place it can go -- no need for arbitrary decisions. Exceptions: - `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`, because they have no crate attributes. - `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's ignored in `rustfmt.toml`).
2024-06-06Make the panic info more usefulOli Scherer-2/+19
2024-06-03Nits and formattingMichael Goulet-3/+6
2024-05-27Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercotebors-21/+13
[perf] Delay the construction of early lint diag structs Attacks some of the perf regressions from https://github.com/rust-lang/rust/pull/124417#issuecomment-2123700666. See individual commits for details. The first three commits are not strictly necessary. However, the 2nd one (06bc4fc67145e3a7be9b5a2cf2b5968cef36e587, *Remove `LintDiagnostic::msg`*) makes the main change way nicer to implement. It's also pretty sweet on its own if I may say so myself.
2024-05-23Remove `LintDiagnostic::msg`León Orell Valerian Liehr-20/+12
* instead simply set the primary message inside the lint decorator functions * it used to be this way before [#]101986 which introduced `msg` to prevent good path delayed bugs (which no longer exist) from firing under certain circumstances when lints were suppressed / silenced * this is no longer necessary for various reasons I presume * it shaves off complexity and makes further changes easier to implement
2024-05-23Slightly clean up some lint infra codeLeón Orell Valerian Liehr-1/+1
* inline `LintBuffer::add_lint`, it only had a single use * update a lint infra example code snippet * it used the wrong API (the snippet isn't tested) * presumably the arguments were updated from builder to diag struct style at some point without updating the method
2024-05-22Rollup merge of #125391 - nnethercote:serialize-rs-tweaks, r=compiler-errorsLeón Orell Valerian Liehr-8/+8
Minor serialize/span tweaks r? ``@jackh726``
2024-05-22Fix up whitespace in `compiler/rustc_macros/src/serialize.rs`.Nicholas Nethercote-8/+8
2024-05-21Fix subdiagnostic-only enum variants not generating codeXiretza-2/+2
2024-05-21Add note_once/help_once to diagnostic derivesXiretza-4/+30
2024-05-10Lift `Lift`Michael Goulet-1/+1
2024-04-25Rollup merge of #124287 - 41Leahcim:master, r=fmeaseMatthias Krüger-1/+1
Improved code with clippy I haven't used the bootstrapped compiler, but I think I have made some improvements using clippy. I have already made the following changes to the compiler: Replaced `self.first().is_digit(10)` with `self.first().is_ascii_digit()` on lines 633, 664, and 680 of compiler/rust_lexer/src/lib.rs. Removed unnecessary cast on line 262 of compiler/rustc_lexer/src/unescape.rs Replaced ok_or_else with ok_or on line 303 of compiler/rustc_lexer/src/unescape.rs Replaced `!std::env::var("RUSTC_BOOTSTRAP").is_ok()` with `std::env::var("RUSTC_BOOTSTRAP").is_err()` on line 4 of compiler/rustc_macros/build.rs Removed needless borrow for generic argument `env`on line 53 of compiler/rust_llvm/build.rs
2024-04-24Improved the compiler code with clippyMichael Scholten-1/+1
2024-04-21Allow nesting subdiagnosticsXiretza-12/+26
2024-04-21Pass translation closure to add_to_diag_with() as referenceXiretza-1/+1
2024-03-11Rename diagnostic derive things.Nicholas Nethercote-9/+9
For increased consistency. - session_diagnostic_derive -> diagnostic_derive - session_subdiagnostic_derive -> subdiagnostic_derive - SubdiagnosticDeriveBuilder -> SubdiagnosticDerive
2024-03-11Rename `DecorateLint` as `LintDiagnostic`.Nicholas Nethercote-1/+1
To match `derive(LintDiagnostic)`.
2024-03-11Rename `AddToDiagnostic` as `Subdiagnostic`.Nicholas Nethercote-3/+3
To match `derive(Subdiagnostic)`. Also rename `add_to_diagnostic{,_with}` as `add_to_diag{,_with}`.
2024-03-11Rename `IntoDiagnostic` as `Diagnostic`.Nicholas Nethercote-6/+3
To match `derive(Diagnostic)`. Also rename `into_diagnostic` as `into_diag`.
2024-03-05Convert `TypeVisitor` and `DefIdVisitor` to use `VisitorResult`Jason Newcomb-3/+10
2024-03-05Rename `SubdiagnosticMessageOp` as `SubdiagMessageOp`.Nicholas Nethercote-1/+1
2024-03-05Rename `DiagnosticMessage` as `DiagMessage`.Nicholas Nethercote-1/+1
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-6/+6
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-25Auto merge of #120393 - Urgau:rfc3373-non-local-defs, r=WaffleLapkinbors-4/+24
Implement RFC 3373: Avoid non-local definitions in functions This PR implements [RFC 3373: Avoid non-local definitions in functions](https://github.com/rust-lang/rust/issues/120363).
2024-02-21Docs for extension proc-macroMichael Goulet-0/+14
2024-02-20Reduce capabilities of `Diagnostic`.Nicholas Nethercote-3/+7
Currently many diagnostic modifier methods are available on both `Diagnostic` and `DiagnosticBuilder`. This commit removes most of them from `Diagnostic`. To minimize the diff size, it keeps them within `diagnostic.rs` but changes the surrounding `impl Diagnostic` block to `impl DiagnosticBuilder`. (I intend to move things around later, to give a more sensible code layout.) `Diagnostic` keeps a few methods that it still needs, like `sub`, `arg`, and `replace_args`. The `forward!` macro, which defined two additional methods per call (e.g. `note` and `with_note`), is replaced by the `with_fn!` macro, which defines one additional method per call (e.g. `with_note`). It's now also only used when necessary -- not all modifier methods currently need a `with_*` form. (New ones can be easily added as necessary.) All this also requires changing `trait AddToDiagnostic` so its methods take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`. There are three subdiagnostics -- `DelayedAtWithoutNewline`, `DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` -- that are created within the diagnostics machinery and appended to external diagnostics. These are handled at the `Diagnostic` level, which means it's now hard to construct them via `derive(Diagnostic)`, so instead we construct them by hand. This has no effect on what they look like when printed. There are lots of new `allow` markers for `untranslatable_diagnostics` and `diagnostics_outside_of_impl`. This is because `#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic` modifier methods, but missing from the `DiagnosticBuilder` modifier methods. They're now present.
2024-02-17Rollup merge of #121085 - davidtwco:always-eager-diagnostics, r=nnethercoteMatthias Krüger-38/+1
errors: only eagerly translate subdiagnostics Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context. This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change). r? ```@nnethercote```
2024-02-17Make synstructure underscore_const(true) the defaultUrgau-4/+24
since otherwise it will trigger the non_local_definitions lint
2024-02-16NitsMichael Goulet-1/+8
2024-02-16Move trait into attr so it's greppableMichael Goulet-14/+25
2024-02-16Add a simple extension trait deriveMichael Goulet-0/+142
2024-02-15errors: only eagerly translate subdiagnosticsDavid Wood-38/+1
Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context. This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change). Signed-off-by: David Wood <david@davidtw.co>
2024-02-09Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwcoMatthias Krüger-2/+0
Invert diagnostic lints. That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has been converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted. r? ````@davidtwco````
2024-02-08Add `SubdiagnosticMessageOp` as a trait alias.Nicholas Nethercote-4/+1
It avoids a lot of repetition.
2024-02-06Invert diagnostic lints.Nicholas Nethercote-2/+0
That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has be converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted.
2024-01-30Rollup merge of #120475 - Nilstrieb:cargo-build-my-a-, r=michaelwoeristerGuillaume Gomez-0/+16
Improve error message when `cargo build` is used to build the compiler Inspired by #76446. Doing it for `core` is probably higher value but also way harder because tools like cargo or rustc-build-sysroot would need to be fixed first, which I don't feel like doing.
2024-01-29Improve error message when `cargo build` is used to build the compilerNilstrieb-0/+16
2024-01-29Stop using `String` for error codes.Nicholas Nethercote-3/+3
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-25Remove unused featuresclubby789-1/+0
2024-01-24Correctly explain `ensure_forwards_result_if_red`Oli Scherer-1/+2