about summary refs log tree commit diff
path: root/compiler/rustc_lint_defs
AgeCommit message (Collapse)AuthorLines
2025-09-04Rollup merge of #145932 - JamieCunliffe:target-feature-inlining, r=jackh726Stuart Cook-0/+54
Allow `inline(always)` with a target feature behind a unstable feature `target_feature_inline_always`. Rather than adding the inline always attribute to the function definition, we add it to the callsite. We can then check that the target features match and that the call would be safe to inline. If the function isn't inlined due to a mismatch, we emit a warning informing the user that the function can't be inlined due to the target feature mismatch. See tracking issue rust-lang/rust#145574
2025-08-30Fix stage 1 compiler testsJakub Beránek-4/+7
2025-08-27inline at the callsite & warn when target features mismatchJames Barford-Evans-0/+54
Co-authored-by: Jamie Cunliffe <Jamie.Cunliffe@arm.com>
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-3/+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-3/+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/+4
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-18Remove the no_sanitize attribute in favor of sanitizeBastian Kersting-6/+6
This removes the #[no_sanitize] attribute, which was behind an unstable feature named no_sanitize. Instead, we introduce the sanitize attribute which is more powerful and allows to be extended in the future (instead of just focusing on turning sanitizers off). This also makes sanitize(kernel_address = ..) attribute work with -Zsanitize=address To do it the same as how clang disables address sanitizer, we now disable ASAN on sanitize(kernel_address = "off") and KASAN on sanitize(address = "off"). The same was added to clang in https://reviews.llvm.org/D44981.
2025-08-15Rollup merge of #144865 - WaffleLapkin:track-tail, r=lqdStuart Cook-0/+33
Fix tail calls to `#[track_caller]` functions We want `#[track_caller]` to be semver independent, i.e. it should not be a breaking change to add or remove it. Since it changes ABI of a function (adding an additional argument) we have to be careful to preserve this property when adding tail calls. The only way to achieve this that I can see is: - we forbid tail calls in functions which are marked with `#[track_caller]` (already implemented) - tail-calling a `#[track_caller]` marked function downgrades the tail-call to a normal call (or equivalently tail-calls the shim made by fn def to fn ptr cast) (this pr) Ideally the downgrade would be performed by a MIR pass, but that requires post mono MIR opts (cc ```@saethlin,``` rust-lang/rust#131650). For now I've changed code in cg_ssa to accomodate this behaviour (+ added a hack to mono collector so that the shim is actually generated) Additionally I added a lint, although I don't think it's strictly necessary. Alternative to rust-lang/rust#144762 (and thus closes rust-lang/rust#144762) Fixes https://github.com/rust-lang/rust/issues/144755
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-13fix tail calls to `#[track_caller]` functionsWaffle Lapkin-0/+33
2025-08-12Remove unused must_useMichael Goulet-0/+1
2025-08-11Add link to docs on malformed attributesEsteban Küber-0/+1
2025-08-10Start reporting future breakage for `ILL_FORMED_ATTRIBUTE_INPUT` in dependenciesJonathan Brouwer-0/+1
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-07Rollup merge of #144369 - joshtriplett:mbe-expr-semi-deny-by-default, ↵Stuart Cook-1/+1
r=petrochenkov Upgrade semicolon_in_expressions_from_macros from warn to deny This is already warn-by-default, and a future compatibility warning (FCW) that warns in dependencies. Upgrade it to deny-by-default, as the next step towards hard error. Per https://github.com/rust-lang/rust/issues/79813#issuecomment-3109105631
2025-08-05Mark all deprecation lints in name resolution as deny-by-default and ↵Vadim Petrochenkov-4/+8
report-in-deps
2025-08-01add unsupported_calling_conventions to lint listRalf Jung-0/+1
2025-07-24Rollup merge of #144014 - dianne:edition-guide-links, r=estebankLeón Orell Valerian Liehr-13/+13
don't link to the nightly version of the Edition Guide in stable lints As reported in rust-lang/rust#143557 for `rust_2024_incompatible_pat`, most future-Edition-incompatibility lints link to the nightly version of the Edition Guide; the lints were written before their respective Editions (and their guides) stabilized. But now that Rusts 2021 and 2024 are stable, these lints are emitted on stable versions of the compiler, where it makes more sense to present users with links that don't say "nightly" in them. This does not change the link for `rust_2024_incompatible_pat`. That's handled in rust-lang/rust#144006.
2025-07-23Upgrade semicolon_in_expressions_from_macros from warn to denyJosh Triplett-1/+1
This is already warn-by-default, and a future compatibility warning (FCW) that warns in dependencies. Upgrade it to deny-by-default, as the next step towards hard error.
2025-07-16future-incompat lints: don't link to the nightly edition-guide versiondianne-13/+13
2025-07-15Implement resolver warnings about reexporting private dependenciesDavid Mládek-0/+5
2025-07-13Auto merge of #140717 - mejrs:diagnostic_lints, r=oli-obkbors-12/+89
Split up the `unknown_or_malformed_diagnostic_attributes` lint This splits up the lint into the following lint group: - `unknown_diagnostic_attributes` - triggers if the attribute is unknown to the current compiler - `misplaced_diagnostic_attributes` - triggers if the attribute exists but it is not placed on the item kind it's meant for - `malformed_diagnostic_attributes` - triggers if the attribute's syntax or options are invalid - `malformed_diagnostic_format_literals` - triggers if the format string literal is invalid, for example if it has unpaired curly braces or invalid parameters - this pr doesn't create it, but future lints for things like deprecations can also go here. This PR does not start emitting lints in places that previously did not. ## Motivation I want to have finer control over what `unknown_or_malformed_diagnostic_attributes` does I have a project with fairly low msrv that is/will have a lower msrv than future diagnostic attributes. So lints will be emitted when I or others compile it on a lower msrv. At this time, there are two options to silence these lints: - `#[allow(unknown_or_malformed_diagnostic_attributes)]` - this risks diagnostic regressions if I (or others) mess up using the attribute, or if the attribute's syntax ever changes. - write a build script to detect the compiler version and emit cfgs, and then conditionally enable the attribute: ```rust #[cfg_attr(rust_version_99, diagnostic::new_attr_in_rust_99(thing = ..))]` struct Foo; ``` or conditionally `allow` the lint: ```rust // lib.rs #![cfg_attr(not(current_rust), allow(unknown_or_malformed_diagnostic_attributes))] ``` I like to avoid using build scripts if I can, so the following works much better for me. That is what this PR will let me do in the future: ```rust #[allow(unknown_diagnostic_attribute, reason = "attribute came out in rust 1.99 but msrv is 1.70")] #[diagnostic::new_attr_in_rust_99(thing = ..)]` struct Foo;
2025-07-11Split up the `unknown_or_malformed_diagnostic_attributes` lintmejrs-12/+89
2025-07-10Rollup merge of #143011 - LorrensP-2158466:warn-ambiguity-into-error, ↵Trevor Gross-1/+2
r=petrochenkov Make lint `ambiguous_glob_imports` deny-by-default and report-in-deps This pr aims to finish the second part of rust-lang/rust#114095. It converts the `ambiguous_glob_imports` lint from a warning to an error. Currently, only the lint definition and the related tests are changed, a crater run should provide us with information on whether we should go for this.
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-1/+1
2025-06-25make `tidy-alphabetical` use a natural sortFolkert de Vries-1/+1
2025-06-25deny AMBIGUOUS_GLOB_IMPORTS; tests fail in this commitLorrensP-2158466-1/+2
2025-06-23compiler: Remove unsupported_fn_ptr_calling_conventions lintJubilee Young-1/+0
2025-06-15Rollup merge of #141937 - WaffleLapkin:never-report-in-deps, ↵León Orell Valerian Liehr-0/+2
r=oli-obk,traviscross Report never type lints in dependencies This PR marks never type lints (`never_type_fallback_flowing_into_unsafe` & `dependency_on_unit_never_type_fallback`) to be included in cargo's reports / to be emitted when they happen in dependencies. This PR is based on rust-lang/rust#141936 r? oli-obk
2025-06-14Remove all support for wasm's legacy ABIbjorn3-45/+0
2025-06-13Auto merge of #142443 - matthiaskrgr:rollup-l1l6d0v, r=matthiaskrgrbors-47/+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-12Make `missing_fragment_specifier` an unconditional errorTrevor Gross-47/+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-11compiler: Avoid reporting unsupported_calling_conventions in depsJubilee Young-1/+1
2025-06-08add (back) unsupported_calling_conventions lint to reject more invalid ↵Ralf Jung-0/+48
calling conventions
2025-06-05Auto merge of #138677 - shepmaster:consistent-elided-lifetime-syntax, ↵bors-44/+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-44/+1
2025-06-03report never type lints in depsWaffle Lapkin-0/+2
2025-06-03decouple "reporting in deps" from future incompatibility reasonWaffle Lapkin-78/+64
2025-05-30Rollup merge of #141004 - matthewjasper:unicode-before-expansion, r=davidtwcoMatthias Krüger-3/+47
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-30Rollup merge of #133823 - estebank:issue-56328, r=petrochenkovMatthias Krüger-0/+1
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-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-27Warn on non-crate level text direction lintsMatthew Jasper-1/+3
2025-05-27Avoid including text direction codepoints in lint messagesMatthew Jasper-4/+4
2025-05-27Report text_direction_codepoint_in_literal when parsingMatthew Jasper-1/+43
- The lint is now reported in code that gets removed/modified/duplicated by macro expansion. - Spans are more accurate - Fixes #140281
2025-05-25Make UNNECESSARY_TRANSMUTES into a HIR lintMichael Goulet-25/+0