about summary refs log tree commit diff
path: root/compiler/rustc_lint/src/lints.rs
AgeCommit message (Collapse)AuthorLines
2025-09-14Move more early buffered lints to dyn lint diagnostics (4/N)León Orell Valerian Liehr-44/+0
2025-09-14Move more early buffered lints to dyn lint diagnostics (3/N)León Orell Valerian Liehr-21/+0
2025-09-14Remove a dead early lintLeón Orell Valerian Liehr-8/+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-31/+0
2025-09-14Move more early buffered lints to dyn lint diagnostics (1/N)León Orell Valerian Liehr-61/+1
2025-08-27Disable `int_to_ptr_transmutes` suggestion for unsized typesUrgau-1/+1
2025-08-24Prefer verbose suggestions for `integer_to_ptr_transmutes` lintUrgau-2/+4
2025-08-24Add lint against integer to pointer transmutesUrgau-0/+42
2025-08-22Migrate `BuiltinLintDiag::HiddenUnicodeCodepoints` to use `LintDiagnostic` ↵Josh Triplett-74/+0
directly
2025-08-22Remove unused `BuiltinLintDiag` variant `InnerAttributeUnstable`Josh Triplett-8/+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-9/+0
2025-08-22Migrate `BuiltinLintDiag::UnexpectedBuiltinCfg` to use `LintDiagnostic` directlyJosh Triplett-10/+0
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-13Rollup merge of #145274 - compiler-errors:unused-must-use, r=fmeaseJakub Beránek-1/+2
Remove unused `#[must_use]` Self-explanatory Fixes https://github.com/rust-lang/rust/issues/145257
2025-08-12Remove unused must_useMichael Goulet-1/+2
2025-08-11Add link to docs on malformed attributesEsteban Küber-0/+3
2025-08-08Refactor map_unit_fn lintCameron Steffen-2/+1
2025-08-07Rollup merge of #144601 - kornelski:cargo-fix-mismatched_lifetime_syntaxes, ↵Stuart Cook-21/+39
r=petrochenkov Allow `cargo fix` to partially apply `mismatched_lifetime_syntaxes` Workaround for https://github.com/rust-lang/rust/issues/144588#issuecomment-3128445308 Not all suggestions have to be hidden from `cargo fix`, only redundant ones. The redundant ones are already hidden from the user, so the same `tool_only` flag can be used to hide them from `cargo fix`. This way `cargo fix` will be able to correctly apply the fixes, and will apply only the fix that the compiler visibly suggests to the user.
2025-07-31Add lint against dangling pointers form local variablesUrgau-0/+16
2025-07-28Allow `cargo fix` to partially apply `mismatched_lifetime_syntaxes`Kornel-21/+39
2025-07-17Rollup merge of #143914 - shepmaster:mismatched-lifetime-syntaxes-rewording, ↵Matthias Krüger-18/+54
r=traviscross,jieyouxu Reword mismatched-lifetime-syntaxes text based on feedback Key changes include: - Removal of the word "syntax" from the lint message. More accurately, it could have been something like "syntax group" or "syntax category", but avoiding it completely is easier. - The primary lint message now reflects exactly which mismatch is occurring, instead of trying to be general. A new `help` line is general across the mismatch kinds. - Suggestions have been reduced to be more minimal, no longer also changing non-idiomatic but unrelated aspects. - Suggestion text no longer mentions changes when those changes don't occur in that specific suggestion. r? ``@jieyouxu``
2025-07-17Rollup merge of #143856 - mladedav:dm/private-reexport, r=petrochenkovLeón Orell Valerian Liehr-0/+8
Linting public reexport of private dependencies Part of public/private dependencies rust-lang/rust#44663 Partially addresses rust-lang/rust#71043 I'm adding a warning for reexports of private dependencies into `rustc_resolve`. I get that this should not be a warning, but should instead be a lint to be controlled by the feature gate, but I did not figure out how exactly to do that at that point. I tried doing the same thing as is done in `rustc_privacy`, but the linting system is not ready yet as far as I understand the error I got, so I made a warning for now instead. Some guidance on how to emit lints with `dcx` would be appreciated. This also sets the `std_detect` crate as a public dependency of `std` because some macros are reexported from there. I did not check closer, but the other option may be to allow the specific reexports instead.
2025-07-15Implement resolver warnings about reexporting private dependenciesDavid Mládek-0/+8
2025-07-14Reword mismatched-lifetime-syntaxes text based on feedbackJake Goulding-18/+54
Key changes include: - Removal of the word "syntax" from the lint message. More accurately, it could have been something like "syntax group" or "syntax category", but avoiding it completely is easier. - The primary lint message now reflects exactly which mismatch is occurring, instead of trying to be general. A new `help` line is general across the mismatch kinds. - Suggestions have been reduced to be more minimal, no longer also changing non-idiomatic but unrelated aspects. - Suggestion text no longer mentions changes when those changes don't occur in that specific suggestion.
2025-07-10added error for invalid char castKivooeo-0/+14
2025-07-07Remove unused allow attrsYotam Ofek-1/+0
2025-06-25Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obkJana Dönszelmann-5/+6
Add runtime check to avoid overwrite arg in `Diag` ## Origin PR description At first, I set up a `debug_assert` check for the arg method to make sure that `args` in `Diag` aren't easily overwritten, and I added the `remove_arg()` method, so that if you do need to overwrite an arg, then you can explicitly call `remove_arg()` to remove it first, then call `arg()` to overwrite it. For the code before the rust-lang/rust#142015 change, it won't compile because it will report an error ``` arg `instance`already exists. ``` This PR also modifies all diagnostics that fail the check to pass the check. There are two cases of check failure: 1. ~~Between *the parent diagnostic and the subdiagnostic*, or *between the subdiagnostics* have the same field between them. In this case, I renamed the conflicting fields.~~ 2. ~~For subdiagnostics stored in `Vec`, the rendering may iteratively write the same arg over and over again. In this case, I changed the auto-generation with `derive(SubDiagnostic)` to manually implementing `SubDiagnostic` and manually rendered it with `eagerly_translate()`, similar to https://github.com/rust-lang/rust/issues/142031#issuecomment-2984812090, and after rendering it I manually deleted useless arg with the newly added `remove_arg` method.~~ ## Final Decision After trying and discussing, we made a final decision. For `#[derive(Subdiagnostic)]`, This PR made two changes: 1. After the subdiagnostic is rendered, remove all args of this subdiagnostic, which allows for usage like `Vec<Subdiag>`. 2. Store `diag.args` before setting arguments, so that you can restore the contents of the main diagnostic after deleting the arguments after subdiagnostic is rendered, to avoid deleting the main diagnostic's arg when they have the same name args.
2025-06-25Add runtime check to avoid overwrite arg easily in diag and store and ↵xizheyin-5/+6
restore snapshot when set subdiag arg Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-24Rollup merge of #142980 - shepmaster:mismatched-syntaxes-multi-suggestions, ↵Jubilee-3/+3
r=ehuss Reduce mismatched-lifetime-syntaxes suggestions to MaybeIncorrect `cargo fix` does not have a way of distinguishing a suggestion with multiple spans which should all be applied from multiple suggestions where only one should be applied (see rust-lang/rust#53934). `cargo fix` only works with `MachineApplicable` suggestions, so downgrading the applicability will stop `cargo` from suggesting the user run `cargo fix`. rust-analyzer does work with `MaybeIncorrect`, so interactive fixes are still available. r? `@ehuss`
2025-06-24Reduce mismatched-lifetime-syntaxes suggestions to MaybeIncorrectJake Goulding-3/+3
`cargo fix` does not have a way of distinguishing a suggestion with multiple spans which should all be applied from multiple suggestions where only one should be applied (see issue 53934). `cargo fix` only works with `MachineApplicable` suggestions, so downgrading the applicability will stop `cargo` from suggesting the user run `cargo fix`. rust-analyzer does work with `MaybeIncorrect`, so interactive fixes are still available.
2025-06-24Rollup merge of #142645 - Urgau:usage-non_upper_case_globals, r=fmeaseMatthias Krüger-1/+18
Also emit suggestions for usages in the `non_upper_case_globals` lint This PR adds suggestions for all the usages of the renamed item in the warning of the `non_upper_case_globals` lint. Fixes https://github.com/rust-lang/rust/issues/124061
2025-06-22Address review commentsUrgau-1/+3
2025-06-20Switch `non_upper_case_globals` suggestions to being machine-applicableUrgau-2/+2
2025-06-18Emit the usages suggestions as tool-only suggestionsUrgau-1/+14
2025-06-18Implement lint against direct uses of rustc_type_ir in compiler cratesRomain Perier-0/+5
This commit adds a lint to prevent the use of rustc_type_ir in random compiler crates, except for type system internals traits, which are explicitly allowed. Moreover, this fixes diagnostic_items() to include the CRATE_OWNER_ID, otherwise rustc_diagnostic_item attribute is ignored on the crate root.
2025-06-18Auto merge of #138165 - jdonszelmann:inline, r=oli-obkbors-0/+1
Rewrite `inline` attribute parser to use new infrastructure and improve diagnostics for all parsed attributes r? `@oli-obk` This PR: - creates a new parser for inline attributes - creates consistent error messages and error codes between attribute parsers; inline and others - as such changes a few error messages for other attributes to be (in my eyes) much more consistent - tests ast-lowering lints introduced by rust-lang/rust#138164 since this is now useful for the first time - Coalesce some useless error codes Builds on top of rust-lang/rust#138164 Closes rust-lang/rust#137950
2025-06-18Also emit suggestions for usages in the `non_upper_case_globals` lintUrgau-0/+2
2025-06-17fix bugs in inline/force_inline and diagnostics of all attr parsersJana Dönszelmann-0/+1
2025-06-18Dont suggest remove semi inside macro expansion for redundant semi lintxizheyin-2/+10
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-13Auto merge of #142443 - matthiaskrgr:rollup-l1l6d0v, r=matthiaskrgrbors-4/+0
Rollup of 9 pull requests Successful merges: - rust-lang/rust#128425 (Make `missing_fragment_specifier` an unconditional error) - rust-lang/rust#135927 (retpoline and retpoline-external-thunk flags (target modifiers) to enable retpoline-related target features) - rust-lang/rust#140770 (add `extern "custom"` functions) - rust-lang/rust#142176 (tests: Split dont-shuffle-bswaps along opt-levels and arches) - rust-lang/rust#142248 (Add supported asm types for LoongArch32) - rust-lang/rust#142267 (assert more in release in `rustc_ast_lowering`) - rust-lang/rust#142274 (Update the stdarch submodule) - rust-lang/rust#142276 (Update dependencies in `library/Cargo.lock`) - rust-lang/rust#142308 (Upgrade `object`, `addr2line`, and `unwinding` in the standard library) Failed merges: - rust-lang/rust#140920 (Extract some shared code from codegen backend target feature handling) r? `@ghost` `@rustbot` modify labels: rollup try-job: aarch64-apple try-job: x86_64-msvc-1 try-job: x86_64-gnu try-job: dist-i586-gnu-i586-i686-musl try-job: test-various
2025-06-12Rollup merge of #141162 - mejrs:gated, r=fee1-deadMatthias Krüger-26/+0
refactor `AttributeGate` and `rustc_attr!` to emit notes during feature checking First commit changes the following: - `AttributeGate ` from an enum with (four) tuple fields to (five) named fields - adds a `notes` fields that is emitted as notes in the `PostExpansionVisitor` pass - removes the `this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date` note if the feature gate is `rustc_attrs`. - various phrasing changes and touchups - and finally, the reason why I went down this path to begin with: tell people they can use the diagnostic namespace when they hit the rustc_on_unimplemented feature gate 🙈 Second commit removes unused machinery for deprecated attributes
2025-06-12Make `missing_fragment_specifier` an unconditional errorTrevor Gross-4/+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-09Remove rustc_feature::Stabilitymejrs-26/+0
2025-06-09refactor `AttributeGate` and `rustc_attr!` to emit notes during feature ↵mejrs-4/+4
checking
2025-06-04Replace `elided_named_lifetimes` with `mismatched_lifetime_syntaxes`Jake Goulding-54/+2
2025-06-04Introduce the `mismatched_lifetime_syntaxes` lintJake Goulding-0/+125
2025-05-30Rollup merge of #133823 - estebank:issue-56328, r=petrochenkovMatthias Krüger-1/+3
Use `cfg_attr_trace` in AST with a placeholder attribute for accurate suggestion In rust-lang/rust#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 rust-lang/rust#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; | ``` r? `@petrochenkov` try-job: x86_64-gnu-aux
2025-05-29Use `cfg_attr` AST placeholder AST `cfg_attr_trace` for diagnosticsEsteban Küber-1/+3
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-27Rollup merge of #141536 - Urgau:ambi_wide_ptr-cmp-diag, r=fee1-deadMichael Goulet-42/+68
Improve `ambiguous_wide_pointer_comparisons` lint compare diagnostics This PR improves the `ambiguous_wide_pointer_comparisons` lint compare diagnostics: `cmp`/`partial_cmp`, but also the operators `<`/`>`/`>=`/`<=`, by: 1. removing the reference to `std::ptr::addr_eq` which only works for equality 2. and adding an `#[expect]` suggestion for keeping the current behavior Fixes rust-lang/rust#141510
2025-05-25Improve `ambiguous_wide_pointer_comparisons` lint compare diagnosticsUrgau-42/+68