Commit Graph

390 Commits

Author SHA1 Message Date
Michael Goulet
c682aa162b Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
Nicholas Nethercote
05e07381d0 Add warn(unreachable_pub) to rustc_metadata. 2024-08-29 20:13:06 +10:00
Nicholas Nethercote
4b92682530 Add warn(unreachable_pub) to rustc_macros. 2024-08-29 20:13:06 +10:00
bjorn3
4e1555462f Remove a couple of unused feature enables 2024-08-26 19:52:14 +00:00
Nicholas Nethercote
84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Michael Goulet
a6510507e7 lift_to_tcx -> lift_to_interner 2024-07-17 10:46:10 -04:00
Michael Goulet
f08c43afc7 Suppress some fallout from gen in synstructure 2024-07-14 14:22:11 -04:00
Michael Goulet
df72e478b0 Make sure that labels are defined after the primary span in diagnostics 2024-07-10 18:55:45 -04:00
Oli Scherer
3f34196839 Remove redundant argument from subdiagnostic method 2024-06-18 15:42:11 +00:00
Oli Scherer
7ba82d61eb Use a dedicated type instead of a reference for the diagnostic context
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-18 15:42:11 +00:00
Nicholas Nethercote
75b164d836 Use tidy to sort crate attributes for all compiler crates.
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-12 15:49:10 +10:00
Oli Scherer
c7ced1ba53 Make the panic info more useful 2024-06-06 09:47:10 +00:00
Michael Goulet
a41c44f21c Nits and formatting 2024-06-03 10:02:08 -04:00
bors
b582f807fa Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercote
[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 (06bc4fc671, *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-27 08:44:12 +00:00
León Orell Valerian Liehr
06bc4fc671
Remove LintDiagnostic::msg
* 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-23 04:08:35 +02:00
León Orell Valerian Liehr
366ef95407
Slightly clean up some lint infra code
* 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-23 03:21:12 +02:00
León Orell Valerian Liehr
0646c7d066
Rollup merge of #125391 - nnethercote:serialize-rs-tweaks, r=compiler-errors
Minor serialize/span tweaks

r? ``@jackh726``
2024-05-22 23:41:13 +02:00
Nicholas Nethercote
2c61c00859 Fix up whitespace in compiler/rustc_macros/src/serialize.rs. 2024-05-22 16:03:46 +10:00
Xiretza
36902fbcf6 Fix subdiagnostic-only enum variants not generating code 2024-05-21 20:11:42 +00:00
Xiretza
eee14e9adf Add note_once/help_once to diagnostic derives 2024-05-21 20:11:42 +00:00
Michael Goulet
5e606c0bde Lift Lift 2024-05-10 15:44:03 -04:00
Matthias Krüger
b28721fd96
Rollup merge of #124287 - 41Leahcim:master, r=fmease
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-25 18:57:56 +02:00
Michael Scholten
3c5e88c7d1 Improved the compiler code with clippy 2024-04-24 09:41:44 +02:00
Xiretza
c88bb6c011 Allow nesting subdiagnostics 2024-04-21 07:45:03 +00:00
Xiretza
5646b65cf5 Pass translation closure to add_to_diag_with() as reference 2024-04-21 07:45:03 +00:00
Nicholas Nethercote
43c06335cf Rename diagnostic derive things.
For increased consistency.

- session_diagnostic_derive    -> diagnostic_derive
- session_subdiagnostic_derive -> subdiagnostic_derive
- SubdiagnosticDeriveBuilder   -> SubdiagnosticDerive
2024-03-11 10:06:34 +11:00
Nicholas Nethercote
e9f0d9be0e Rename DecorateLint as LintDiagnostic.
To match `derive(LintDiagnostic)`.
2024-03-11 10:04:50 +11:00
Nicholas Nethercote
541d7cc65c Rename AddToDiagnostic as Subdiagnostic.
To match `derive(Subdiagnostic)`.

Also rename `add_to_diagnostic{,_with}` as `add_to_diag{,_with}`.
2024-03-11 10:04:49 +11:00
Nicholas Nethercote
7a294e998b Rename IntoDiagnostic as Diagnostic.
To match `derive(Diagnostic)`.

Also rename `into_diagnostic` as `into_diag`.
2024-03-11 09:15:09 +11:00
Jason Newcomb
be9b125d41 Convert TypeVisitor and DefIdVisitor to use VisitorResult 2024-03-05 13:28:15 -05:00
Nicholas Nethercote
573267cf3c Rename SubdiagnosticMessageOp as SubdiagMessageOp. 2024-03-05 12:14:49 +11:00
Nicholas Nethercote
18715c98c6 Rename DiagnosticMessage as DiagMessage. 2024-03-05 12:14:49 +11:00
Nicholas Nethercote
899cb40809 Rename DiagnosticBuilder as Diag.
Much better!

Note that this involves renaming (and updating the value of)
`DIAGNOSTIC_BUILDER` in clippy.
2024-02-28 08:55:35 +11:00
bors
b0d3e04ca9 Auto merge of #120393 - Urgau:rfc3373-non-local-defs, r=WaffleLapkin
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-25 19:11:06 +00:00
Michael Goulet
62e7414a19 Docs for extension proc-macro 2024-02-21 05:32:08 +00:00
Nicholas Nethercote
f6f8779843 Reduce capabilities of Diagnostic.
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-20 13:22:17 +11:00
Matthias Krüger
45d5773704
Rollup merge of #121085 - davidtwco:always-eager-diagnostics, r=nnethercote
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-17 18:47:40 +01:00
Urgau
c1144436f6 Make synstructure underscore_const(true) the default
since otherwise it will trigger the non_local_definitions lint
2024-02-17 13:57:33 +01:00
Michael Goulet
f624d55ea7 Nits 2024-02-16 15:07:37 +00:00
Michael Goulet
a9dbf63087 Move trait into attr so it's greppable 2024-02-16 15:07:37 +00:00
Michael Goulet
3250e95305 Add a simple extension trait derive 2024-02-16 15:07:37 +00:00
David Wood
b80fc5d4e8
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).

Signed-off-by: David Wood <david@davidtw.co>
2024-02-15 10:34:41 +00:00
Matthias Krüger
46a0448405
Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco
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-09 14:41:50 +01:00
Nicholas Nethercote
6b175a848d Add SubdiagnosticMessageOp as a trait alias.
It avoids a lot of repetition.
2024-02-08 13:02:44 +11:00
Nicholas Nethercote
0ac1195ee0 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 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-02-06 13:12:33 +11:00
Guillaume Gomez
399b81faac
Rollup merge of #120475 - Nilstrieb:cargo-build-my-a-, r=michaelwoerister
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-30 16:57:50 +01:00
Nilstrieb
6468d44c37 Improve error message when cargo build is used to build the compiler 2024-01-29 20:32:55 +01:00
Nicholas Nethercote
5d9dfbd08f Stop using String for error codes.
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-29 07:41:41 +11:00
clubby789
fd29f74ff8 Remove unused features 2024-01-25 14:01:33 +00:00
Oli Scherer
cc34dc2bc7 Correctly explain ensure_forwards_result_if_red 2024-01-24 11:04:13 +00:00