about summary refs log tree commit diff
path: root/compiler/rustc_attr
AgeCommit message (Collapse)AuthorLines
2024-04-25Rollup merge of #124324 - nnethercote:minor-ast-cleanups, r=estebankMatthias Krüger-1/+1
Minor AST cleanups r? ``@estebank``
2024-04-24Rename `NestedMetaItem::name_value_literal`.Nicholas Nethercote-1/+1
It's a highly misleading name, because it's completely different to `MetaItem::name_value_literal`. Specifically, it doesn't match `MetaItemKind::NameValue` (e.g. `#[foo = 3]`), it matches `MetaItemKind::List` (e.g. `#[foo(3)]`).
2024-04-22Stabilize generic `NonZero`.Markus Reiter-1/+0
2024-04-01Use the `Align` type when parsing alignment attributesbeetrees-6/+14
2024-03-11Rename `IntoDiagnostic` as `Diagnostic`.Nicholas Nethercote-7/+5
To match `derive(Diagnostic)`. Also rename `into_diagnostic` as `into_diag`.
2024-03-06Rewrite the `untranslatable_diagnostic` lint.Nicholas Nethercote-0/+3
Currently it only checks calls to functions marked with `#[rustc_lint_diagnostics]`. This commit changes it to check calls to any function with an `impl Into<{D,Subd}iagMessage>` parameter. This greatly improves its coverage and doesn't rely on people remembering to add `#[rustc_lint_diagnostics]`. The commit also adds `#[allow(rustc::untranslatable_diagnostic)`] attributes to places that need it that are caught by the improved lint. These places that might be easy to convert to translatable diagnostics. Finally, it also: - Expands and corrects some comments. - Does some minor formatting improvements. - Adds missing `DecorateLint` cases to `tests/ui-fulldeps/internal-lints/diagnostics.rs`.
2024-03-05Rename `BuiltinLintDiagnostics` as `BuiltinLintDiag`.Nicholas Nethercote-3/+3
Not the dropping of the trailing `s` -- this type describes a single diagnostic and its name should be singular.
2024-03-04Rollup merge of #121969 - nnethercote:ParseSess-cleanups, r=wesleywiserMatthias Krüger-7/+7
`ParseSess` cleanups The main change here is to rename all `ParseSess` values as `psess`. Plus a few other small cleanups. r? `@wesleywiser`
2024-03-05Rename all `ParseSess` variables/fields/lifetimes as `psess`.Nicholas Nethercote-7/+7
Existing names for values of this type are `sess`, `parse_sess`, `parse_session`, and `ps`. `sess` is particularly annoying because that's also used for `Session` values, which are often co-located, and it can be difficult to know which type a value named `sess` refers to. (That annoyance is the main motivation for this change.) `psess` is nice and short, which is good for a name used this much. The commit also renames some `parse_sess_created` values as `psess_created`.
2024-03-03fix spans of arguments in diagnosticyukang-5/+12
2024-03-02Fix misleading message when using a named constant as a struct alignment/packyukang-11/+46
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-5/+5
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-15Use generic `NonZero` internally.Markus Reiter-3/+4
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-29Stop using `String` for error codes.Nicholas Nethercote-24/+23
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-19Pack the u128 in LitKind::IntJosh Stone-3/+3
2024-01-13Add check for ui_testing via promoting parameters from `ParseSess` to `Session`George-lewis-12/+12
2024-01-10Rename consuming chaining methods on `DiagnosticBuilder`.Nicholas Nethercote-5/+5
In #119606 I added them and used a `_mv` suffix, but that wasn't great. A `with_` prefix has three different existing uses. - Constructors, e.g. `Vec::with_capacity`. - Wrappers that provide an environment to execute some code, e.g. `with_session_globals`. - Consuming chaining methods, e.g. `Span::with_{lo,hi,ctxt}`. The third case is exactly what we want, so this commit changes `DiagnosticBuilder::foo_mv` to `DiagnosticBuilder::with_foo`. Thanks to @compiler-errors for the suggestion.
2024-01-10Rename `{create,emit}_warning` as `{create,emit}_warn`.Nicholas Nethercote-1/+1
For consistency with `warn`/`struct_warn`, and also `{create,emit}_err`, all of which use an abbreviated form.
2024-01-08Use chaining in `DiagnosticBuilder` construction.Nicholas Nethercote-7/+6
To avoid the use of a mutable local variable, and because it reads more nicely.
2024-01-03Rename some `Diagnostic` setters.Nicholas Nethercote-4/+4
`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-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-48/+62
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-24Remove `ParseSess` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-12/+11
Also add missing `#[track_caller]` attributes to `DiagCtxt` methods as necessary to keep tests working.
2023-12-19Add `level` arg to `into_diagnostic`.Nicholas Nethercote-13/+14
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-18Rename many `DiagCtxt` arguments.Nicholas Nethercote-4/+4
2023-12-18Rename `Session::span_diagnostic` as `Session::dcx`.Nicholas Nethercote-1/+1
2023-12-18Rename `Handler` as `DiagCtxt`.Nicholas Nethercote-3/+3
2023-12-02Use `Session::diagnostic` in more places.Nicholas Nethercote-1/+1
2023-12-02Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`.Nicholas Nethercote-2/+2
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug` follows the pattern used everywhere else: `span_err`, `span_warning`, etc.
2023-11-27Detect and reject malformed repr(Rust) hintsLeón Orell Valerian Liehr-3/+3
2023-11-26Use `rustc_fluent_macro::fluent_messages!` directly.Nicholas Nethercote-3/+1
Currently we always do this: ``` use rustc_fluent_macro::fluent_messages; ... fluent_messages! { "./example.ftl" } ``` But there is no need, we can just do this everywhere: ``` rustc_fluent_macro::fluent_messages! { "./example.ftl" } ``` which is shorter.
2023-11-26Avoid need for `{D,Subd}iagnosticMessage` imports.Nicholas Nethercote-1/+0
The `fluent_messages!` macro produces uses of `crate::{D,Subd}iagnosticMessage`, which means that every crate using the macro must have this import: ``` use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; ``` This commit changes the macro to instead use `rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the imports.
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-1/+1
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-15Bump cfg(bootstrap)sMark Rousskov-3/+3
2023-10-31Auto merge of #117377 - dtolnay:deprecatedsince, r=cjgillotbors-22/+62
Store #[deprecated] attribute's `since` value in parsed form This PR implements the first followup bullet listed in https://github.com/rust-lang/rust/pull/117148#issue-1960240108. We centralize error handling to the attribute parsing code in `compiler/rustc_attr/src/builtin.rs`, and thereby remove some awkward error codepaths from later phases of compilation that had to make sense of these #\[deprecated\] attributes, namely `compiler/rustc_passes/src/stability.rs` and `compiler/rustc_middle/src/middle/stability.rs`.
2023-10-30Add method for checking if deprecation is a rustc versionDavid Tolnay-0/+4
2023-10-30Descriptive variant name deprecation versions outside the standard libraryDavid Tolnay-3/+3
2023-10-30Represent absence of 'since' attribute as a variant of DeprecatedSinceDavid Tolnay-15/+17
2023-10-30Preserve deprecation attribute even if 'since' version is missingDavid Tolnay-3/+3
2023-10-30Add a DeprecatedSince::Err variant for versions that fail to parseDavid Tolnay-19/+8
2023-10-30Move deprecation_in_effect to inherent method on DeprecationDavid Tolnay-0/+16
2023-10-29Store version of `deprecated` attribute in structured formDavid Tolnay-16/+45
2023-10-29Rename Since -> StableSince in preparation for a DeprecatedSinceDavid Tolnay-6/+6
2023-10-30Clean up `rustc_*/Cargo.toml`.Nicholas Nethercote-2/+2
- 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-26Parse rustc version at compile timeDavid Tolnay-29/+14
2023-10-26Pre-intern a symbol for env!("CFG_RELEASE")David Tolnay-4/+0
2023-10-24Expose a non-Symbol way to access current rustc version stringDavid Tolnay-2/+4
2023-10-24CFG_RELEASE is mandatory, no need for option_envDavid Tolnay-2/+1
The same file already contains another env!("CFG_RELEASE") on line 632, so it's impossible for this crate to compile without CFG_RELEASE set.
2023-10-24Handle structured stable attribute 'since' version in rustdocDavid Tolnay-0/+7
2023-10-24Keep track of #[stable] attribute even if version cannot be parsedDavid Tolnay-7/+11