about summary refs log tree commit diff
path: root/compiler/rustc_lint/src/early.rs
AgeCommit message (Collapse)AuthorLines
2025-08-22Refactor lint buffering to avoid requiring a giant enumJosh Triplett-3/+7
Lint buffering currently relies on a giant enum `BuiltinLintDiag` containing all the lints that might potentially get buffered. In addition to being an unwieldy enum in a central crate, this also makes `rustc_lint_defs` a build bottleneck: it depends on various types from various crates (with a steady pressure to add more), and many crates depend on it. Having all of these variants in a separate crate also prevents detecting when a variant becomes unused, which we can do with a dedicated type defined and used in the same crate. Refactor this to use a dyn trait, to allow using `LintDiagnostic` types directly. This requires boxing, but all of this is already on the slow path (emitting an error). Because the existing `BuiltinLintDiag` requires some additional types in order to decorate some variants, which are only available later in `rustc_lint`, use an enum `DecorateDiagCompat` to handle both the `dyn LintDiagnostic` case and the `BuiltinLintDiag` case.
2025-08-09remove `P`Deadbeef-2/+1
2025-06-12early linting: avoid redundant calls to `check_id`Deadbeef-14/+2
2025-06-10Remove unneeded `check_id` calls as they are already called in `visit_id` in ↵Guillaume Gomez-2/+0
`EarlyContextAndPass` type
2025-06-01Add `visit_id` to ast `Visitor`Deadbeef-34/+3
This helps with efforts to deduplicate the `MutVisitor` and the `Visitor` code. All users of `Visitor`'s methods that have extra `NodeId` as parameters really just want to visit the id on its own. Also includes some methods deduplicated and cleaned up as a result of this change.
2025-05-27Rollup merge of #140894 - Urgau:check-cfg-rustdoc, r=GuillaumeGomezTrevor Gross-2/+2
Make check-cfg diagnostics work in `#[doc(cfg(..))]` This PR makes it so that the check-cfg `unexpected_cfgs` lint, is correctly emitted in `rustdoc`'s `#[doc(cfg(..))]`. This is achieved by adding a custom trait to `cfg_matches` (the method that emits the lint) which permits `rustc` and `rustdoc` to each have their way to emitting lints (via buffered lints/AST for `rustc` and via `TyCtxt`/HIR for `rustdoc`). The reason this is required is because buffered lints operates on the AST but `rustdoc` uses the HIR and by the time `rustdoc` calls `cfg_matches` we are way passed the point where buffered lints have been drain and emitted. Best reviewed commit by commit. r? `@jieyouxu` (for the compiler part) r? `@GuillaumeGomez` (for the rustdoc part)
2025-05-26Expose `rustc_lint::decorate_builtin_lint` for use in `rustdoc`Urgau-2/+2
2025-05-23further deduplicate ast visitor codeDeadbeef-1/+1
2025-03-25Track whether an assoc item is in a trait impl or an inherent implOli Scherer-2/+2
2025-02-07fix empty after lint on impl/trait itemsJonathan Dönszelmann-0/+8
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-15Cleanup lifetimes around `EarlyContextAndPass` and `EarlyCheckNode`Urgau-58/+44
2024-12-15Simplify `opt_span_lint` call in early diagnosticUrgau-36/+4
2024-12-15Access `TyCtxt` from early diagnostic decorationUrgau-13/+52
2024-12-07Actually walk into lifetimes and attrs in EarlyContextAndPassMichael Goulet-0/+2
2024-11-20Itemsmaxcabrajac-8/+9
2024-11-12Change rustc_lintmaxcabrajac-19/+4
2024-10-27Clean up some comments on lint implementationEric Huss-14/+4
2024-10-26Auto merge of #125116 - blyxyas:ignore-allowed-lints-final, r=cjgillotbors-0/+3
(Big performance change) Do not run lints that cannot emit Before this change, adding a lint was a difficult matter because it always had some overhead involved. This was because all lints would run, no matter their default level, or if the user had `#![allow]`ed them. This PR changes that. This change would improve both the Rust lint infrastructure and Clippy, but Clippy will see the most benefit, as it has about 900 registered lints (and growing!) So yeah, with this little patch we filter all lints pre-linting, and remove any lint that is either: - Manually `#![allow]`ed in the whole crate, - Allowed in the command line, or - Not manually enabled with `#[warn]` or similar, and its default level is `Allow` As some lints **need** to run, this PR also adds **loadbearing lints**. On a lint declaration, you can use the ``@eval_always` = true` marker to label it as loadbearing. A loadbearing lint will never be filtered (it will always run) Fixes #106983
2024-10-25Rollup merge of #132106 - maxcabrajac:ident_ref, r=petrochenkovMatthias Krüger-1/+1
Pass Ident by reference in ast Visitor `MutVisitor`'s version of `visit_ident` passes around `&Ident`, but `Visitor` copies `Ident`. This PR changes that r? `@petrochenkov` related to #128974
2024-10-24Pass Ident by reference in ast Visitormaxcabrajac-1/+1
2024-10-24Remove visit_expr_postmaxcabrajac-15/+12
2024-10-19Do not run lints that cannot emitblyxyas-0/+3
Before this change, adding a lint was a difficult matter because it always had some overhead involved. This was because all lints would run, no matter their default level, or if the user had #![allow]ed them. This PR changes that
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-3/+3
2024-08-27Add `warn(unreachable_pub)` to `rustc_lint`.Nicholas Nethercote-1/+1
2024-08-07Make `Span` optional in `BufferedEarlyLint`Urgau-1/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-2/+3
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-05-23Remove `#[macro_use] extern crate tracing` from `rustc_lint`.Nicholas Nethercote-0/+1
2024-05-21Make early lints translatableXiretza-2/+2
2024-05-21Generate lint diagnostic message from BuiltinLintDiagXiretza-8/+2
Translation of the lint message happens when the actual diagnostic is created, not when the lint is buffered. Generating the message from BuiltinLintDiag ensures that all required data to construct the message is preserved in the LintBuffer, eventually allowing the messages to be moved to fluent. Remove the `msg` field from BufferedEarlyLint, it is either generated from the data in the BuiltinLintDiag or stored inside BuiltinLintDiag::Normal.
2024-04-25ast: Generalize item kind visitingVadim Petrochenkov-1/+1
And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign).
2024-03-24Rename `{enter,exit}_lint_attrs` to `check_attributes{,_post}`Alex Macleod-2/+2
2024-03-05Move visitor utils to `rustc_ast_ir`Jason Newcomb-2/+2
2024-02-14Use fewer delayed bugs.Nicholas Nethercote-7/+6
For some cases where it's clear that an error has already occurred, e.g.: - there's a comment stating exactly that, or - things like HIR lowering, where we are lowering an error kind The commit also tweaks some comments around delayed bug sites.
2024-01-23Rename `LintContext::lookup_with_diagnostics` as ↵Nicholas Nethercote-1/+7
`LintContext::span_lint_with_diagnostics`.
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-1/+1
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-15Don't pass lint back out of lint decoratorMichael Goulet-7/+1
2023-12-08Rename some more coro_kind -> coroutine_kindMichael Goulet-4/+5
2023-12-08Introduce closure_id method on CoroutineKindMichael Goulet-8/+2
2023-12-08Make some matches exhaustive to avoid bugs, fix toolsMichael Goulet-12/+11
2023-12-08coro_kind -> coroutine_kindMichael Goulet-2/+2
2023-12-04Option<CoroutineKind>Eric Holk-4/+8
2023-12-04Merge Async and Gen into CoroutineKindEric Holk-2/+6
2023-12-02Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`.Nicholas Nethercote-1/+1
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug` follows the pattern used everywhere else: `span_err`, `span_warning`, etc.
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-08-31diagnostics: avoid wrong `unused_parens` on `x as (T) < y`Michael Howell-0/+1
2023-08-11rustc: Move `features` from `Session` to `GlobalCtxt`Vadim Petrochenkov-0/+3
Removes two pieces of mutable state. Follow up to #114622.
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-1/+1
Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile.
2023-03-27Rollup merge of #109354 - Swatinem:rm-closureid, r=compiler-errorsGuillaume Gomez-2/+1
Remove the `NodeId` of `ast::ExprKind::Async` This is a followup to https://github.com/rust-lang/rust/pull/104833#pullrequestreview-1314537416. In my original attempt, I was using `LoweringContext::expr`, which was not correct as it creates a fresh `DefId`. It now uses the correct `DefId` for the wrapping `Expr`, and also makes forwarding `#[track_caller]` attributes more explicit.
2023-03-23rustc_interface: Add a new query `pre_configure`Vadim Petrochenkov-5/+5
It partially expands crate attributes before the main expansion pass (without modifying the crate), and the produced preliminary crate attribute list is used for querying a few attributes that are required very early. Crate-level cfg attributes are then expanded normally during the main expansion pass, like attributes on any other nodes.