about summary refs log tree commit diff
path: root/compiler/rustc_lint_defs/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2025-09-14Move more early buffered lints to dyn lint diagnostics (4/N)León Orell Valerian Liehr-12/+0
2025-09-14Move more early buffered lints to dyn lint diagnostics (3/N)León Orell Valerian Liehr-8/+0
2025-09-14Remove a dead early lintLeón Orell Valerian Liehr-4/+0
Dropped in favor a hard error in RUST-127907.
2025-09-14Move more early buffered lints to dyn lint diagnostics (2/N)León Orell Valerian Liehr-9/+0
2025-09-14Move more early buffered lints to dyn lint diagnostics (1/N)León Orell Valerian Liehr-17/+1
2025-08-22Migrate `BuiltinLintDiag::HiddenUnicodeCodepoints` to use `LintDiagnostic` ↵Josh Triplett-8/+0
directly
2025-08-22Remove unused `BuiltinLintDiag` variant `InnerAttributeUnstable`Josh Triplett-3/+0
This variant doesn't appear to have ever been used. There's a matching message in `rustc_resolve`, that used to have a FIXME for porting it to the new diagnostic infrastructure, but that message is using `feature_err`, which doesn't use buffered lints. Thus, even when that does get ported, it won't use `BuiltinLintDiag`.
2025-08-22Migrate `BuiltinLintDiag::MissingAbi` to use `LintDiagnostic` directlyJosh Triplett-2/+0
2025-08-22Migrate `BuiltinLintDiag::UnexpectedBuiltinCfg` to use `LintDiagnostic` directlyJosh Triplett-5/+0
2025-08-22Refactor lint buffering to avoid requiring a giant enumJosh Triplett-51/+1
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-20rustc_lint_defs: Eliminate the dependency on `rustc_hir` for `Namespace`Josh Triplett-2/+1
`rustc_lint_defs` uses `rustc_hir` solely for the `Namespace` type, which it only needs the static description from. Use the static description directly, to eliminate the dependency on `rustc_hir`. This reduces a long dependency chain: - Many things depend on `rustc_errors` - `rustc_errors` depends on `rustc_lint_defs` - `rustc_lint_defs` depended on `rustc_hir` prior to this commit - `rustc_hir` depends on `rustc_target`
2025-08-20rustc_lint_defs: Use `DefPathHash` from `rustc_span` rather than `rustc_hir`Josh Triplett-1/+1
2025-08-20Split `rustc_hir_id` out of `rustc_hir`Josh Triplett-3/+3
Some crates depend on `rustc_hir` but only want `HirId` and similar id types. `rustc_hir` is a heavy dependency, since it pulls in `rustc_target`. Split these types out into their own crate `rustc_hir_id`. This allows `rustc_errors` to drop its direct dependency on `rustc_hir`. (`rustc_errors` still depends on `rustc_hir` indirectly through `rustc_lint_defs`; a subsequent commit will fix that.)
2025-08-20Move `IntoDiagArg` earlier in the dependency chainsJosh Triplett-1/+9
`rustc_errors` depends on numerous crates, solely to implement its `IntoDiagArg` trait on types from those crates. Many crates depend on `rustc_errors`, and it's on the critical path. We can't swap things around to make all of those crates depend on `rustc_errors` instead, because `rustc_errors` would end up in dependency cycles. Instead, move `IntoDiagArg` into `rustc_error_messages`, which has far fewer dependencies, and then have most of these crates depend on `rustc_error_messages`. This allows `rustc_errors` to drop dependencies on several crates, including the large `rustc_target`. (This doesn't fully reduce dependency chains yet, as `rustc_errors` still depends on `rustc_hir` which depends on `rustc_target`. That will get fixed in a subsequent commit.)
2025-08-13Rollup merge of #145274 - compiler-errors:unused-must-use, r=fmeaseJakub Beránek-0/+1
Remove unused `#[must_use]` Self-explanatory Fixes https://github.com/rust-lang/rust/issues/145257
2025-08-12Remove unused must_useMichael Goulet-0/+1
2025-08-11Add link to docs on malformed attributesEsteban Küber-0/+1
2025-07-15Implement resolver warnings about reexporting private dependenciesDavid Mládek-0/+5
2025-06-12Make `missing_fragment_specifier` an unconditional errorTrevor Gross-1/+0
This was attempted in [1] then reverted in [2] because of fallout. Recently, this was made an edition-dependent error in [3]. Make missing fragment specifiers an unconditional error again. [1]: https://github.com/rust-lang/rust/pull/75516 [2]: https://github.com/rust-lang/rust/pull/80210 [3]: https://github.com/rust-lang/rust/pull/128006
2025-06-05Auto merge of #138677 - shepmaster:consistent-elided-lifetime-syntax, ↵bors-11/+1
r=traviscross,jieyouxu Add a new `mismatched-lifetime-syntaxes` lint The lang-team [discussed this](https://hackmd.io/nf4ZUYd7Rp6rq-1svJZSaQ) and I attempted to [summarize](https://github.com/rust-lang/rust/pull/120808#issuecomment-2701863833) their decision. The summary-of-the-summary is: - Using two different kinds of syntax for elided lifetimes is confusing. In rare cases, it may even [lead to unsound code](https://github.com/rust-lang/rust/issues/48686)! Some examples: ```rust // Lint will warn about these fn(v: ContainsLifetime) -> ContainsLifetime<'_>; fn(&'static u8) -> &u8; ``` - Matching up references with no lifetime syntax, references with anonymous lifetime syntax, and paths with anonymous lifetime syntax is an exception to the simplest possible rule: ```rust // Lint will not warn about these fn(&u8) -> &'_ u8; fn(&'_ u8) -> &u8; fn(&u8) -> ContainsLifetime<'_>; ``` - Having a lint for consistent syntax of elided lifetimes will make the [future goal](https://github.com/rust-lang/rust/issues/91639) of warning-by-default for paths participating in elision much simpler. --- This new lint attempts to accomplish the goal of enforcing consistent syntax. In the process, it supersedes and replaces the existing `elided-named-lifetimes` lint, which means it starts out life as warn-by-default.
2025-06-04Replace `elided_named_lifetimes` with `mismatched_lifetime_syntaxes`Jake Goulding-11/+1
2025-06-03decouple "reporting in deps" from future incompatibility reasonWaffle Lapkin-51/+26
2025-05-30Rollup merge of #141004 - matthewjasper:unicode-before-expansion, r=davidtwcoMatthias Krüger-0/+8
Report text_direction_codepoint_in_literal when parsing The lint is now reported in code that gets removed/modified/duplicated by macro expansion, and spans are more accurate so we don't get ICEs from trying to split a span in the middle of a character. This removes support for lint level attributes for `text_direction_codepoint_in_literal` except at the crate level, I don't think that there's an easy way around this when the lint can be reported on code that's removed by `cfg` or that is only in the input of a macro. Fixes #140281
2025-05-29Use `cfg_attr` AST placeholder AST `cfg_attr_trace` for diagnosticsEsteban Küber-0/+1
PR 138515, we insert a placeholder attribute so that checks for attributes can still know about the placement of `cfg` attributes. When we suggest removing items with `cfg_attr`s (fix Issue 56328) and make them verbose. We tweak the wording of the existing "unused `extern crate`" lint. ``` warning: unused extern crate --> $DIR/removing-extern-crate.rs:9:1 | LL | extern crate removing_extern_crate as foo; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused | note: the lint level is defined here --> $DIR/removing-extern-crate.rs:6:9 | LL | #![warn(rust_2018_idioms)] | ^^^^^^^^^^^^^^^^ = note: `#[warn(unused_extern_crates)]` implied by `#[warn(rust_2018_idioms)]` help: remove the unused `extern crate` | LL - #[cfg_attr(test, macro_use)] LL - extern crate removing_extern_crate as foo; LL + | ```
2025-05-27Report text_direction_codepoint_in_literal when parsingMatthew Jasper-0/+8
- The lint is now reported in code that gets removed/modified/duplicated by macro expansion. - Spans are more accurate - Fixes #140281
2025-04-17Replace infallible `name_or_empty` methods with fallible `name` methods.Nicholas Nethercote-1/+1
I'm removing empty identifiers everywhere, because in practice they always mean "no identifier" rather than "empty identifier". (An empty identifier is impossible.) It's better to use `Option` to mean "no identifier" because you then can't forget about the "no identifier" possibility. Some specifics: - When testing an attribute for a single name, the commit uses the `has_name` method. - When testing an attribute for multiple names, the commit uses the new `has_any_name` method. - When using `match` on an attribute, the match arms now have `Some` on them. In the tests, we now avoid printing empty identifiers by not printing the identifier in the `error:` line at all, instead letting the carets point out the problem.
2025-04-03impl !PartialOrd for HirIdOli Scherer-5/+7
2025-04-03Remove `LintExpectationId` from `Level` variantsOli Scherer-23/+22
2025-03-11Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-4/+0
It's no longer necessary now that `-Wunreachable_pub` is being passed.
2025-03-10Revert "Use workspace lints for crates in `compiler/` #138084"许杰友 Jieyou Xu (Joe)-0/+4
Revert <https://github.com/rust-lang/rust/pull/138084> to buy time to consider options that avoids breaking downstream usages of cargo on distributed `rustc-src` artifacts, where such cargo invocations fail due to inability to inherit `lints` from workspace root manifest's `workspace.lints` (this is only valid for the source rust-lang/rust workspace, but not really the distributed `rustc-src` artifacts). This breakage was reported in <https://github.com/rust-lang/rust/issues/138304>. This reverts commit 48caf81484b50dca5a5cebb614899a3df81ca898, reversing changes made to c6662879b27f5161e95f39395e3c9513a7b97028.
2025-03-08Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-4/+0
(Except for `rustc_codegen_cranelift`.) It's no longer necessary now that `unreachable_pub` is in the workspace lints.
2025-02-24Introduce new-style attribute parsers for several attributesJana Dönszelmann-9/+13
note: compiler compiles but librustdoc and clippy don't
2025-02-22Fix binding mode problemsMichael Goulet-2/+2
2025-02-20Reword messageEsteban Küber-1/+1
2025-02-19Specify scope in `out_of_scope_macro_calls` lintEsteban Küber-0/+2
``` warning: cannot find macro `in_root` in the crate root --> $DIR/key-value-expansion-scope.rs:1:10 | LL | #![doc = in_root!()] | ^^^^^^^ not found in the crate root | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535> = help: import `macro_rules` with `use` to make it callable above its definition = note: `#[warn(out_of_scope_macro_calls)]` on by default ```
2025-01-31Make comma separated lists of anything easier to make for errorsEsteban Küber-0/+17
Provide a new function `listify`, meant to be used in cases similar to `pluralize!`. When you have a slice of arbitrary elements that need to be presented to the user, `listify` allows you to turn that into a list of comma separated strings. This reduces a lot of redundant logic that happens often in diagnostics.
2025-01-25Rollup merge of #133951 - bjorn3:wasm_c_abi_lint_hard_error, r=workingjubileeJacob Pratt-1/+0
Make the wasm_c_abi future compat warning a hard error This is the next step in getting rid of the broken C abi for wasm32-unknown-unknown. The lint was made deny-by-default in https://github.com/rust-lang/rust/pull/129534 3 months ago. This still keeps the `-Zwasm-c-abi` flag set to `legacy` by default. It will be flipped in a future PR. cc https://github.com/rust-lang/rust/issues/122532
2025-01-23Make the wasm_c_abi future compat warning a hard errorbjorn3-1/+0
This is the next step in getting rid of the broken C abi for wasm32-unknown-unknown.
2025-01-20make it possible to silence linker warnings with a crate-level attributejyn-1/+13
this was slightly complicated because codegen_ssa doesn't have access to a tcx.
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-4/+3
`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-15Add hir::AttributeJonathan Dönszelmann-3/+4
2024-11-25fix confusing diagnostic for reserved `##`Peter Jaszkowiak-2/+5
2024-11-19lints_that_dont_need_to_run: never skip future-compat-reported lintsRalf Jung-0/+14
2024-11-14Mark `never_type_fallback_flowing_into_unsafe` as a semantic changeMaybe Lapkin-1/+13
...rather than a future error
2024-11-14Mention both release *and* edition breakage for never type lintsMaybe Lapkin-3/+21
2024-10-30compiler: Switch to rustc_abi in hir_pretty, lint_defs, and mir_buildJubilee Young-2/+2
Completely abandon usage of rustc_target in these crates, as they need no special knowledge of rustc's target tuples.
2024-10-21Move COGNITIVE_COMPLEXITY to use macro againblyxyas-3/+3
2024-10-19Apply review comments + use `shallow_lint_levels_on`blyxyas-11/+0
2024-10-19Unify syntax (all to @eval_always)blyxyas-2/+2
2024-10-19Remove module passes filteringblyxyas-9/+14