Commit Graph

339 Commits

Author SHA1 Message Date
Nicholas Nethercote
d71f535a6f Rework how diagnostic lints are stored.
`Diagnostic::code` has the type `DiagnosticId`, which has `Error` and
`Lint` variants. Plus `Diagnostic::is_lint` is a bool, which should be
redundant w.r.t. `Diagnostic::code`.

Seems simple. Except it's possible for a lint to have an error code, in
which case its `code` field is recorded as `Error`, and `is_lint` is
required to indicate that it's a lint. This is what happens with
`derive(LintDiagnostic)` lints. Which means those lints don't have a
lint name or a `has_future_breakage` field because those are stored in
the `DiagnosticId::Lint`.

It's all a bit messy and confused and seems unintentional.

This commit:
- removes `DiagnosticId`;
- changes `Diagnostic::code` to `Option<String>`, which means both
  errors and lints can straightforwardly have an error code;
- changes `Diagnostic::is_lint` to `Option<IsLint>`, where `IsLint` is a
  new type containing a lint name and a `has_future_breakage` bool, so
  all lints can have those, error code or not.
2024-01-14 14:04:25 +11:00
Mark Rousskov
5e8f67bbc9 u8 tags for smaller enums
100% of the serialized enums during libcore compilation fit into the
smaller tag, and this eliminates hitting the leb128 code for
coding/decoding when we can statically guarantee that's not required.

30% of all leb128 integers serialized in libcore (12981183 total) come
from the usize's removed here.
2024-01-09 20:08:44 -05:00
bors
e21f4cd98f Auto merge of #119478 - bjorn3:no_serialize_specialization, r=wesleywiser
Avoid specialization in the metadata serialization code

With the exception of a perf-only specialization for byte slices and byte vectors.

This uses the same trick of introducing a new trait and having the Encodable and Decodable derives add a bound to it as used for TyEncoder/TyDecoder. The new code is clearer about which encoder/decoder uses which impl and it reduces the dependency of rustc on specialization, making it easier to remove support for specialization entirely or turn it into a construct that is only allowed for perf optimizations if we decide to do this.
2024-01-06 09:56:00 +00:00
Nicholas Nethercote
505c1371d0 Rename some Diagnostic setters.
`Diagnostic` has 40 methods that return `&mut Self` and could be
considered setters. Four of them have a `set_` prefix. This doesn't seem
necessary for a type that implements the builder pattern. This commit
removes the `set_` prefixes on those four methods.
2024-01-03 19:40:20 +11:00
bjorn3
6ed37bdc42 Avoid specialization for the Span Encodable and Decodable impls 2023-12-31 20:42:17 +00:00
Nicholas Nethercote
e7724a2e31 Add level arg to into_diagnostic.
And make all hand-written `IntoDiagnostic` impls generic, by using
`DiagnosticBuilder::new(dcx, level, ...)` instead of e.g.
`dcx.struct_err(...)`.

This means the `create_*` functions are the source of the error level.
This change will let us remove `struct_diagnostic`.

Note: `#[rustc_lint_diagnostics]` is added to `DiagnosticBuilder::new`,
it's necessary to pass diagnostics tests now that it's used in
`into_diagnostic` functions.
2023-12-19 09:19:25 +11:00
Nicholas Nethercote
31df50c897 Streamline Diagnostic proc macro.
First, it is parameterized by the name of the diagnostic and the
DiagCtxt. These are given to `session_diagnostic_derive` and
`lint_diagnostic_derive`. But the names are hard-wired as "diag" and
"handler" (should be "dcx"), and there's no clear reason for the
parameterization. So this commit removes the parameterization and
hard-wires the names internally.

Once that is done `DiagnosticDeriveBuilder` is reduced to a trivial
wrapper around `DiagnosticDeriveKind`, and can be removed.

Also, `DiagnosticDerive` and `LintDiagnosticDerive` don't need the
`builder` field, because it has been reduced to a kind, and they know
their own kind. This avoids the need for some
`let`/`else`/`unreachable!` kind checks

And `DiagnosticDeriveVariantBuilder` no longer needs a lifetime, because
the `parent` field is changed to `kind`, which is now a trivial copy
type.
2023-12-19 09:05:23 +11:00
Nicholas Nethercote
18251c480b Remove unnecessary use items in derived IntoDiagnostic impls.
Presumably these are a hangover from an earlier time when they were
necessary.
2023-12-19 08:11:25 +11:00
Nicholas Nethercote
f6aa418c9f Rename many DiagCtxt and EarlyDiagCtxt locals. 2023-12-18 16:06:22 +11:00
Nicholas Nethercote
4dc7fab56f Rename __diagnostic_handler_sess as _sess. 2023-12-18 16:06:22 +11:00
Nicholas Nethercote
7b8644e5cf Rename DiagnosticDeriveKind::Diagnostic::handler as DiagnosticDeriveKind::Diagnostic::dcx. 2023-12-18 16:06:22 +11:00
Nicholas Nethercote
cde19c016e Rename Handler as DiagCtxt. 2023-12-18 16:06:19 +11:00
Michael Goulet
108bec6723 Simplify lint decorator derive too 2023-12-16 02:07:01 +00:00
surechen
40ae34194c remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
Michael Goulet
c9143ea1d9 Unify HashStable implementations 2023-11-21 05:49:45 +00:00
Michael Goulet
426bc70ad6 Add HashStable_NoContext to simplify HashStable implementations in rustc_type_ir 2023-11-21 05:49:44 +00:00
Michael Goulet
4506681e2f Begin nightly-ifying rustc_type_ir 2023-11-18 00:20:00 +00:00
Mark Rousskov
917f6540ed Re-format code with new rustfmt 2023-11-15 21:45:48 -05:00
Nicholas Nethercote
dd6bab9eff Factor out some duplicated code. 2023-11-10 10:54:26 +11:00
Nicholas Nethercote
316ffba3c8 Update instructions in a comment.
And avoid duplication.
2023-11-10 10:54:26 +11:00
Nicholas Nethercote
b35e576657 Minor cleanups.
- Reduce some function exposure.
- Fix some comment formatting.
2023-11-10 10:54:26 +11:00
Nicholas Nethercote
49908b4d90 Simplify the current_rustc_version macro.
It currently has the syntax
`current_rustc_version!(env!("CFG_RELEASE"))` where the
`env!("CFG_RELEASE")` part looks like a normal expression but it is
actually parsed and processed by the `current_rustc_version` macro.

The documented rationale for this is that you'll find it if you grep for
`env!("CFG_RELEASE")`. But I think that's of very little use -- I would
personally grep for just "CFG_RELEASE" -- and it complicates the macro,
requiring the use of `syn`.

This commit simplifies the macro.
2023-11-10 10:54:21 +11:00
Michael Goulet
bee7b5889e Derive TyEncodable/TyDecodable implementations that are parameterized over interner 2023-11-04 16:44:42 +00:00
Nicholas Nethercote
8ff624a9f2 Clean up rustc_*/Cargo.toml.
- Sort dependencies and features sections.
- Add `tidy` markers to the sorted sections so they stay sorted.
- Remove empty `[lib`] sections.
- Remove "See more keys..." comments.

Excluded files:
- rustc_codegen_{cranelift,gcc}, because they're external.
- rustc_lexer, because it has external use.
- stable_mir, because it has external use.
2023-10-30 08:46:02 +11:00
Jubilee
1db8c9d6e2
Rollup merge of #117256 - dtolnay:currentversion, r=compiler-errors
Parse rustc version at compile time

This PR eliminates a couple awkward codepaths where it was not clear how the compiler should proceed if its own version number is incomprehensible.

dab715641e/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs (L385)

dab715641e/compiler/rustc_attr/src/builtin.rs (L630)

We can guarantee that every compiled rustc comes with a working version number, so the ICE codepaths above shouldn't need to be written.
2023-10-28 01:07:38 -07:00
Matthias Krüger
5459333ffc
Rollup merge of #117241 - compiler-errors:auto-trait-leak-cycle, r=oli-obk
Stash and cancel cycle errors for auto trait leakage in opaques

We don't need to emit a traditional cycle error when we have a selection error that explains what's going on but in more detail.

We may want to augment this error to actually point out the cycle, now that the cycle error is not being emitted. We could do that by storing the set of opaques that was in the `CyclePlaceholder` that gets returned from `type_of_opaque`.

r? `@oli-obk` cc `@estebank` #117235
2023-10-27 11:48:06 +02:00
David Tolnay
b7debe34e6
Parse rustc version at compile time 2023-10-26 18:55:05 -07:00
Michael Goulet
1836c1fbbd Stash and cancel cycle errors for auto trait leakage in opaques 2023-10-26 17:58:02 +00:00
David Tolnay
c1552dfddd
Fix symbols::tests::test_symbols
---- symbols::tests::test_symbols stdout ----
    thread 'symbols::tests::test_symbols' panicked at library/proc_macro/src/bridge/client.rs:311:17:
    procedural macro API is used outside of a procedural macro
2023-10-26 02:02:22 -07:00
David Tolnay
5563a9ba3d
Improve span of env-related errors 2023-10-26 01:57:12 -07:00
David Tolnay
1078250f48
Continue generating other symbols if an expr is not supported 2023-10-26 01:57:12 -07:00
David Tolnay
65f0253334
Support environment variable for interned Symbol value 2023-10-26 01:57:11 -07:00
David Tolnay
726a43c1de
Move symbols macro map into a struct 2023-10-26 01:57:10 -07:00
David Tolnay
8dea49ad7b
Delete counter from symbols proc macro in favor of hashmap as source of truth 2023-10-26 01:57:09 -07:00
David Tolnay
95742ff23c
Add a Parse impl for symbol Value 2023-10-26 01:57:08 -07:00
David Tolnay
ba17934bc1
Represent symbol value as enum to prepare for supporting env vars 2023-10-26 01:57:07 -07:00
David Tolnay
173dcb211a
Touch up syn parsing in symbols macro 2023-10-26 01:57:06 -07:00
Oli Scherer
fe8ebb1890 Allow ensure queries to return Result<(), ErrorGuaranteed> 2023-10-23 08:20:29 +00:00
Michael Goulet
60c95448c3 Use v0.0.0 in compiler crates 2023-10-18 21:55:15 +00:00
Michael Goulet
b2d2184ede Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
Mark Rousskov
0a916062aa Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
Nicholas Nethercote
3449304722 Make enum decoding errors more informative.
By printing the actual value, as long as the expected range. I found
this helpful when I encountered one of these errors.
2023-08-18 16:50:41 +10:00
Nilstrieb
5830ca216d Add internal_features lint
It lints against features that are inteded to be internal to the
compiler and standard library. Implements MCP #596.

We allow `internal_features` in the standard library and compiler as those
use many features and this _is_ the standard library from the "internal to the compiler and
standard library" after all.

Marking some features as internal wasn't exactly the most scientific approach, I just marked some
mostly obvious features. While there is a categorization in the macro,
it's not very well upheld (should probably be fixed in another PR).

We always pass `-Ainternal_features` in the testsuite
About 400 UI tests and several other tests use internal features.
Instead of throwing the attribute on each one, just always allow them.
There's nothing wrong with testing internal features^^
2023-08-03 14:50:50 +02:00
Matthias Krüger
23815467a2 inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
Oli Scherer
cf325e8187 Bump syn now that it doesn't affect diagnostics anymore 2023-07-26 08:26:50 +00:00
Mark Rousskov
cc907f80b9 Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
Nilstrieb
171be8ce94 Downgrade tracing and syn
There's currently a deadlock with tracing when RUSTC_LOG is enabled.
Downgrade tracing-core for now to avoid blocking the other updates.

syns upgrades cause some nontrivial changes in the diagnostics derive tests,
which are best dealt with in another PR.
2023-07-02 21:02:31 +02:00
bors
08fd6f719e Auto merge of #111269 - clubby789:validate-fluent-variables, r=davidtwco
Validate fluent variable references in tests

Closes #101109

Under `cfg(test)`, the `fluent_messages` macro will emit a list of variables referenced by each message and its attributes. The derive attribute will now emit a `#[test]` that checks that each referenced variable exists in the structure it's applied to.
2023-06-28 03:47:02 +00:00
Takayuki Maeda
c8960622a2 avoid &format in error message code 2023-06-23 02:17:39 +09:00
Deadbeef
4f83717cf7 Use translatable diagnostics in rustc_const_eval 2023-06-01 14:45:18 +00:00