about summary refs log tree commit diff
path: root/compiler/rustc_macros
AgeCommit message (Collapse)AuthorLines
2024-01-23Rename `LintContext::struct_span_lint` as `LintContext::span_lint`.Nicholas Nethercote-1/+1
2024-01-14Rework how diagnostic lints are stored.Nicholas Nethercote-1/+1
`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-09u8 tags for smaller enumsMark Rousskov-6/+24
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-06Auto merge of #119478 - bjorn3:no_serialize_specialization, r=wesleywiserbors-0/+18
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-03Rename some `Diagnostic` setters.Nicholas Nethercote-19/+19
`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.
2023-12-31Avoid specialization for the Span Encodable and Decodable implsbjorn3-0/+18
2023-12-19Add `level` arg to `into_diagnostic`.Nicholas Nethercote-2/+7
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-19Streamline `Diagnostic` proc macro.Nicholas Nethercote-83/+45
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-19Remove unnecessary `use` items in derived `IntoDiagnostic` impls.Nicholas Nethercote-3/+0
Presumably these are a hangover from an earlier time when they were necessary.
2023-12-18Rename many `DiagCtxt` and `EarlyDiagCtxt` locals.Nicholas Nethercote-2/+2
2023-12-18Rename `__diagnostic_handler_sess` as `_sess`.Nicholas Nethercote-4/+5
2023-12-18Rename `DiagnosticDeriveKind::Diagnostic::handler` as ↵Nicholas Nethercote-10/+10
`DiagnosticDeriveKind::Diagnostic::dcx`.
2023-12-18Rename `Handler` as `DiagCtxt`.Nicholas Nethercote-1/+1
2023-12-16Simplify lint decorator derive tooMichael Goulet-2/+2
2023-12-10remove redundant importssurechen-3/+3
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-11-21Unify HashStable implementationsMichael Goulet-64/+49
2023-11-21Add HashStable_NoContext to simplify HashStable implementations in rustc_type_irMichael Goulet-0/+51
2023-11-18Begin nightly-ifying rustc_type_irMichael Goulet-334/+0
2023-11-15Re-format code with new rustfmtMark Rousskov-1/+3
2023-11-10Factor out some duplicated code.Nicholas Nethercote-42/+31
2023-11-10Update instructions in a comment.Nicholas Nethercote-10/+3
And avoid duplication.
2023-11-10Minor cleanups.Nicholas Nethercote-11/+14
- Reduce some function exposure. - Fix some comment formatting.
2023-11-10Simplify the `current_rustc_version` macro.Nicholas Nethercote-29/+11
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-04Derive TyEncodable/TyDecodable implementations that are parameterized over ↵Michael Goulet-10/+20
interner
2023-10-30Clean up `rustc_*/Cargo.toml`.Nicholas Nethercote-2/+4
- 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-28Rollup merge of #117256 - dtolnay:currentversion, r=compiler-errorsJubilee-0/+65
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. https://github.com/rust-lang/rust/blob/dab715641e96a61a534587fda9de1128b75b34dc/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs#L385 https://github.com/rust-lang/rust/blob/dab715641e96a61a534587fda9de1128b75b34dc/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-27Rollup merge of #117241 - compiler-errors:auto-trait-leak-cycle, r=oli-obkMatthias Krüger-0/+8
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-26Parse rustc version at compile timeDavid Tolnay-0/+65
2023-10-26Stash and cancel cycle errors for auto trait leakage in opaquesMichael Goulet-0/+8
2023-10-26Fix symbols::tests::test_symbolsDavid Tolnay-1/+9
---- 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-26Improve span of env-related errorsDavid Tolnay-7/+7
2023-10-26Continue generating other symbols if an expr is not supportedDavid Tolnay-9/+14
2023-10-26Support environment variable for interned Symbol valueDavid Tolnay-4/+58
2023-10-26Move symbols macro map into a structDavid Tolnay-20/+32
2023-10-26Delete counter from symbols proc macro in favor of hashmap as source of truthDavid Tolnay-18/+24
2023-10-26Add a Parse impl for symbol ValueDavid Tolnay-2/+8
2023-10-26Represent symbol value as enum to prepare for supporting env varsDavid Tolnay-4/+10
2023-10-26Touch up syn parsing in symbols macroDavid Tolnay-4/+2
2023-10-23Allow `ensure` queries to return `Result<(), ErrorGuaranteed>`Oli Scherer-0/+10
2023-10-18Use v0.0.0 in compiler cratesMichael Goulet-1/+1
2023-10-13Format all the let chains in compilerMichael Goulet-19/+23
2023-08-23Bump cfg(bootstrap)Mark Rousskov-1/+1
2023-08-18Make enum decoding errors more informative.Nicholas Nethercote-2/+2
By printing the actual value, as long as the expected range. I found this helpful when I encountered one of these errors.
2023-08-03Add `internal_features` lintNilstrieb-0/+1
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-07-30inline format!() args up to and including rustc_middleMatthias Krüger-1/+1
2023-07-26Bump syn now that it doesn't affect diagnostics anymoreOli Scherer-2/+1
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-7/+17
2023-07-02Downgrade tracing and synNilstrieb-1/+2
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-06-28Auto merge of #111269 - clubby789:validate-fluent-variables, r=davidtwcobors-4/+57
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-23avoid `&format` in error message codeTakayuki Maeda-8/+6