about summary refs log tree commit diff
path: root/compiler/rustc_lint_defs/src/lib.rs
AgeCommit message (Collapse)AuthorLines
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
2024-10-19Do not run lints that cannot emitblyxyas-5/+25
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-10-08Reserve guarded string literals (RFC 3593)Peter Jaszkowiak-0/+2
2024-10-05Make deprecated_cfg_attr_crate_type_name a hard errorest31-2/+0
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-09-13Disallow hidden references to mutable staticObei Sideg-1/+1
2024-09-07Rollup merge of #126452 - compiler-errors:raw-lifetimes, r=spastorinoMatthias Krüger-0/+2
Implement raw lifetimes and labels (`'r#ident`) This PR does two things: 1. Reserve lifetime prefixes, e.g. `'prefix#lt` in edition 2021. 2. Implements raw lifetimes, e.g. `'r#async` in edition 2021. This PR additionally extends the `keyword_idents_2024` lint to also check lifetimes. cc `@traviscross` r? parser
2024-09-06Add initial support for raw lifetimesMichael Goulet-0/+2
2024-09-06elided_named_lifetimes: unify lint def & pass MissingLifetimeKindPavel Grigorenko-7/+10
2024-09-01Auto merge of #127313 - cjgillot:single-expect, r=jieyouxubors-26/+5
Rewrite lint_expectations in a single pass. This PR aims at reducing the perf regression from https://github.com/rust-lang/rust/pull/120924#issuecomment-2202486203 with drive-by simplifications. Basically, instead of using the lint level builder, which is slow, this PR splits `lint_expectations` logic in 2: - listing the `LintExpectations` is done in `shallow_lint_levels_on`, on a per-owner basis; - building the unstable->stable expectation id map is done by iterating on attributes. r? ghost for perf
2024-08-31Remove attr_id from stable lint ids.Camille GILLOT-26/+5
2024-08-31Implement `elided_named_lifetimes` lintPavel Grigorenko-0/+7
2024-08-27Add `warn(unreachable_pub)` to `rustc_lint_defs`.Nicholas Nethercote-0/+4
2024-08-07Disallow setting built-in cfgs via set the command-lineUrgau-0/+5
2024-08-07Make `Span` optional in `BufferedEarlyLint`Urgau-2/+2
2024-07-29Reformat `use` declarations.Nicholas Nethercote-6/+5
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-28Only require symbol name for @feature_gateMichael Goulet-6/+6
2024-06-24resolve: Implement a lint for out-of-scope use of `macro_rules`Vadim Petrochenkov-0/+3