about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2025-06-23compiler: Remove unsupported_fn_ptr_calling_conventions lintJubilee Young-0/+1
2025-06-22Port `#[no_mangle]` to new attribute parsing infrastructureJonathan Brouwer-13/+20
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-22Rollup merge of #142780 - JonathanBrouwer:must_use_new_attr, r=jdonszelmannGuillaume Gomez-3/+6
Port `#[must_use]` to new attribute parsing infrastructure Ports `must_use` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971353197 r? `@jdonszelmann`
2025-06-22Rollup merge of #142593 - blyxyas:improve-docs-itty-bitty-change, ↵Guillaume Gomez-0/+9
r=compiler-errors Add a warning to LateContext::get_def_path Preventing anyone from doing the same error as https://github.com/rust-lang/rust-clippy/pull/15043 fixed
2025-06-22Address review commentsUrgau-9/+31
2025-06-22Port `#[must_use]` to new attribute parsing infrastructureJonathan Brouwer-3/+6
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-21All HIR attributes are outerDavid Tolnay-3/+4
2025-06-21Add `emit_span_lint_lazy` to lazily create `LintDiagnostic` structsUrgau-4/+16
2025-06-21Lazily collect `NonUpperCaseGlobalSubTool` diagnosticsUrgau-18/+20
2025-06-20Switch `non_upper_case_globals` suggestions to being machine-applicableUrgau-2/+2
2025-06-20Rollup merge of #142687 - cjgillot:less-hir_crate, r=oli-obkTrevor Gross-2/+1
Reduce uses of `hir_crate`. I tried rebasing my old incremental-HIR branch. This is a by-product, which is required if we want to get rid of `hir_crate` entirely. The second commit is a drive-by cleanup. It can be pulled into its own PR. r? ````@oli-obk````
2025-06-18Emit the usages suggestions as tool-only suggestionsUrgau-11/+28
2025-06-18Reduce uses of `hir_crate`.Camille GILLOT-2/+1
2025-06-18Implement lint against direct uses of rustc_type_ir in compiler cratesRomain Perier-3/+34
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-11/+68
2025-06-17Rollup merge of #142631 - xizheyin:142143, r=UrgauJacob Pratt-6/+19
Dont suggest remove semi inside macro expansion for redundant semi lint Fixes rust-lang/rust#142143 r? compiler
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-6/+19
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-17Auto merge of #137944 - davidtwco:sized-hierarchy, r=oli-obkbors-1/+2
Sized Hierarchy: Part I This patch implements the non-const parts of rust-lang/rfcs#3729. It introduces two new traits to the standard library, `MetaSized` and `PointeeSized`. See the RFC for the rationale behind these traits and to discuss whether this change makes sense in the abstract. These traits are unstable (as is their constness), so users cannot refer to them without opting-in to `feature(sized_hierarchy)`. These traits are not behind `cfg`s as this would make implementation unfeasible, there would simply be too many `cfg`s required to add the necessary bounds everywhere. So, like `Sized`, these traits are automatically implemented by the compiler. RFC 3729 describes changes which are necessary to preserve backwards compatibility given the introduction of these traits, which are implemented and as follows: - `?Sized` is rewritten as `MetaSized` - `MetaSized` is added as a default supertrait for all traits w/out an explicit sizedness supertrait already. There are no edition migrations implemented in this, as these are primarily required for the constness parts of the RFC and prior to stabilisation of this (and so will come in follow-up PRs alongside the const parts). All diagnostic output should remain the same (showing `?Sized` even if the compiler sees `MetaSized`) unless the `sized_hierarchy` feature is enabled. Due to the use of unstable extern types in the standard library and rustc, some bounds in both projects have had to be relaxed already - this is unfortunate but unavoidable so that these extern types can continue to be used where they were before. Performing these relaxations in the standard library and rustc are desirable longer-term anyway, but some bounds are not as relaxed as they ideally would be due to the inability to relax `Deref::Target` (this will be investigated separately). It is hoped that this is implemented such that it could be merged and these traits could exist "under the hood" without that being observable to the user (other than in any performance impact this has on the compiler, etc). Some details might leak through due to the standard library relaxations, but this has not been observed in test output. **Notes:** - Any commits starting with "upstream:" can be ignored, as these correspond to other upstream PRs that this is based on which have yet to be merged. - This best reviewed commit-by-commit. I've attempted to make the implementation easy to follow and keep similar changes and test output updates together. - Each commit has a short description describing its purpose. - This patch is large but it's primarily in the test suite. - I've worked on the performance of this patch and a few optimisations are implemented so that the performance impact is neutral-to-minor. - `PointeeSized` is a different name from the RFC just to make it more obvious that it is different from `std::ptr::Pointee` but all the names are yet to be bikeshed anyway. - `@nikomatsakis` has confirmed [that this can proceed as an experiment from the t-lang side](https://rust-lang.zulipchat.com/#narrow/channel/435869-project-goals/topic/SVE.20and.20SME.20on.20AArch64.20.28goals.23270.29/near/506196491) - FCP in https://github.com/rust-lang/rust/pull/137944#issuecomment-2912207485 Fixes rust-lang/rust#79409. r? `@ghost` (I'll discuss this with relevant teams to find a reviewer)
2025-06-17Add a warning to LateContext::get_def_pathblyxyas-0/+9
2025-06-16lint: don't consider sizedness in upcastable lintDavid Wood-1/+2
Adding a sizedness supertrait shouldn't require multiple vtables so shouldn't be linted against.
2025-06-16Port `#[rustc_as_ptr]` to the new attribute systemPavel Grigorenko-1/+2
2025-06-15Rollup merge of #134661 - dtolnay:prefixattr, r=fmeaseLeón Orell Valerian Liehr-0/+15
Reduce precedence of expressions that have an outer attr Previously, `-Zunpretty=expanded` would expand this program as follows: ```rust #![feature(stmt_expr_attributes)] macro_rules! repro { ($e:expr) => { #[allow(deprecated)] $e }; } #[derive(Default)] struct Thing { #[deprecated] field: i32, } fn main() { let thing = Thing::default(); let _ = repro!(thing).field; } ``` ```rs #![feature(prelude_import)] #![feature(stmt_expr_attributes)] #[prelude_import] use std::prelude::rust_2021::*; #[macro_use] extern crate std; struct Thing { #[deprecated] field: i32, } #[automatically_derived] impl ::core::default::Default for Thing { #[inline] fn default() -> Thing { Thing { field: ::core::default::Default::default() } } } fn main() { let thing = Thing::default(); let _ = #[allow(deprecated)] thing.field; } ``` This is not the correct expansion. The correct output would have `(#[allow(deprecated)] thing).field` with the attribute applying only to `thing`, not to `thing.field`.
2025-06-15Rollup merge of #133952 - bjorn3:remove_wasm_legacy_abi, r=alexcrichtonLeón Orell Valerian Liehr-0/+1
Remove wasm legacy abi Closes https://github.com/rust-lang/rust/issues/122532 Closes https://github.com/rust-lang/rust/issues/138762 Fixes https://github.com/rust-lang/rust/issues/71871 https://github.com/rust-lang/rust/issues/88152 Fixes https://github.com/rust-lang/rust/issues/115666 Fixes https://github.com/rust-lang/rust/issues/129486
2025-06-15Auto merge of #142398 - fee1-dead-contrib:push-ynxrtswtkyxw, r=oli-obkbors-14/+2
early linting: avoid redundant calls to `check_id` An attempt to address the regression at https://github.com/rust-lang/rust/pull/142240#issuecomment-2964425460 r? `@oli-obk` cc `@nnethercote` who might have a better understanding of the performance implications
2025-06-14Auto merge of #142129 - ↵bors-7/+33
shepmaster:mismatched-syntaxes-in-function-like-places, r=jieyouxu Apply `mismatched-lifetime-syntaxes` to trait and extern functions r? `@jieyouxu`
2025-06-14Remove all support for wasm's legacy ABIbjorn3-0/+1
2025-06-13Rollup merge of #142441 - compiler-errors:lazier-binder-value-folding, r=lcnrJubilee-3/+2
Delay replacing escaping bound vars in `FindParamInClause` By uplifting the `BoundVarReplacer`, which is used by (e.g.) normalization to replace escaping bound vars that are encountered when folding binders, we can use a similar strategy to delay the instantiation of a binder's contents in the `FindParamInClause` used by the new trait solver. This should alleviate the recently added requirement that `Binder<T>: TypeVisitable` only if `T: TypeFoldable`, which was previously required b/c we were calling `enter_forall` so that we could structurally normalize aliases that we found within the predicates of a param-env clause. r? lcnr
2025-06-13Reduce precedence of expressions that have an outer attrDavid Tolnay-0/+15
2025-06-13TypeVisiting binders no longer requires TypeFolding its interiorMichael Goulet-3/+2
2025-06-13Auto merge of #142443 - matthiaskrgr:rollup-l1l6d0v, r=matthiaskrgrbors-7/+5
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-13Auto merge of #142432 - matthiaskrgr:rollup-ziuls9y, r=matthiaskrgrbors-77/+2
Rollup of 6 pull requests Successful merges: - rust-lang/rust#138016 (Added `Clone` implementation for `ChunkBy`) - rust-lang/rust#141162 (refactor `AttributeGate` and `rustc_attr!` to emit notes during feature checking) - rust-lang/rust#141474 (Add `ParseMode::Diagnostic` and fix multiline spans in diagnostic attribute lints) - rust-lang/rust#141947 (Specify that "option-like" enums must be `#[repr(Rust)]` to be ABI-compatible with their non-1ZST field.) - rust-lang/rust#142252 (Improve clarity of `core::sync::atomic` docs about "Considerations" in regards to CAS operations) - rust-lang/rust#142337 (miri: add flag to suppress float non-determinism) r? `@ghost` `@rustbot` modify labels: rollup
2025-06-13Rollup merge of #128425 - tgross35:missing-fragment-specifier-unconditional, ↵Matthias Krüger-7/+5
r=petrochenkov,traviscross Make `missing_fragment_specifier` an unconditional error 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, across all editions. More context: https://github.com/rust-lang/rust/pull/128006 Most recent crater: https://github.com/rust-lang/rust/pull/128425#issuecomment-2686949847 Fixes: https://github.com/rust-lang/rust/issues/40107 [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-12Auto merge of #142438 - matthiaskrgr:rollup-u1jdnhz, r=matthiaskrgrbors-1/+2
Rollup of 9 pull requests Successful merges: - rust-lang/rust#134536 (Lint on fn pointers comparisons in external macros) - rust-lang/rust#141069 (Suggest mut when possbile for temporary value dropped while borrowed) - rust-lang/rust#141934 (resolve: Tweak `private_macro_use` lint to be compatible with upcoming macro prelude changes) - rust-lang/rust#142034 (Detect method not being present that is present in other tuple types) - rust-lang/rust#142402 (chore(doctest): Remove redundant blank lines) - rust-lang/rust#142406 (Note when enum variants shadow an associated function) - rust-lang/rust#142407 (Remove bootstrap adhoc group) - rust-lang/rust#142408 (Add myself (WaffleLapkin) to review rotation) - rust-lang/rust#142418 (Remove lower_arg_ty as all callers were passing `None`) r? `@ghost` `@rustbot` modify labels: rollup
2025-06-12Rollup merge of #134536 - Urgau:fn-ptr-option, r=compiler-errors,traviscrossMatthias Krüger-1/+2
Lint on fn pointers comparisons in external macros This PR extends the recently stabilized `unpredictable_function_pointer_comparisons` lint ~~to also lint on `Option<{function pointer}>` and~~ as well as linting in external macros (as to catch `assert_eq!` and others). ```rust assert_eq!(Some::<FnPtr>(func), Some(func as unsafe extern "C" fn())); //~^ WARN function pointer comparisons #[derive(PartialEq, Eq)] struct A { f: fn(), //~^ WARN function pointer comparisons } ``` Fixes https://github.com/rust-lang/rust/issues/134527
2025-06-12Rollup merge of #141162 - mejrs:gated, r=fee1-deadMatthias Krüger-77/+2
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-12early linting: avoid redundant calls to `check_id`Deadbeef-14/+2
2025-06-12Make `missing_fragment_specifier` an unconditional errorTrevor Gross-7/+5
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-12introduce new lint infraJana Dönszelmann-1/+1
lint on duplicates during attribute parsing To do this we stuff them in the diagnostic context to be emitted after hir is constructed
2025-06-12Report the `unpredictable_function_pointer_comparisons` lint in macroUrgau-1/+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-09Remove rustc_feature::Stabilitymejrs-74/+2
2025-06-09refactor `AttributeGate` and `rustc_attr!` to emit notes during feature ↵mejrs-16/+13
checking
2025-06-09Auto merge of #141435 - RalfJung:unsupported_calling_conventions, ↵bors-1/+0
r=workingjubilee Add (back) `unsupported_calling_conventions` lint to reject more invalid calling conventions This adds back the `unsupported_calling_conventions` lint that was removed in https://github.com/rust-lang/rust/pull/129935, in order to start the process of dealing with https://github.com/rust-lang/rust/issues/137018. Specifically, we are going for the plan laid out [here](https://github.com/rust-lang/rust/issues/137018#issuecomment-2672118326): - thiscall, stdcall, fastcall, cdecl should only be accepted on x86-32 - vectorcall should only be accepted on x86-32 and x86-64 The difference to the status quo is that: - We stop accepting stdcall, fastcall on targets that are windows && non-x86-32 (we already don't accept these on targets that are non-windows && non-x86-32) - We stop accepting cdecl on targets that are non-x86-32 - (There is no difference for thiscall, this was already a hard error on non-x86-32) - We stop accepting vectorcall on targets that are windows && non-x86-* Vectorcall is an unstable ABI so we can just make this a hard error immediately. The others are stable, so we emit the `unsupported_calling_conventions` forward-compat lint. I set up the lint to show up in dependencies via cargo's future-compat report immediately, but we could also make it show up just for the local crate first if that is preferred. try-job: i686-msvc-1 try-job: x86_64-msvc-1 try-job: test-various
2025-06-08add (back) unsupported_calling_conventions lint to reject more invalid ↵Ralf Jung-1/+0
calling conventions
2025-06-07Rollup merge of #141661 - Urgau:deny-dangerous_implicit_autorefs, r=traviscrossGuillaume Gomez-2/+2
Make the `dangerous_implicit_autorefs` lint deny-by-default I intended for the `dangerous_implicit_autorefs` lint to be deny-by-default, the [T-lang nomination comment](https://github.com/rust-lang/rust/pull/123239#issuecomment-2727551097) even clearly mentioned deny-by-default, but somehow I and other missed that it is only warn-by-default. I think the lint should still be deny-by-default as the implicit aliasing requirements can be quite dangerous. In any-case, opening this PR for T-lang awareness. `@rustbot` label +I-lang-nominated +T-lang r? `@traviscross`
2025-06-06Apply `mismatched-lifetime-syntaxes` to trait and extern functionsJake Goulding-7/+33
2025-06-06Rollup merge of #142012 - oli-obk:no-optional-spans, r=fee1-deadMatthias Krüger-2/+3
Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of None Turns out many locations actually have a span available that we could use, so I used it
2025-06-05Auto merge of #138677 - shepmaster:consistent-elided-lifetime-syntax, ↵bors-68/+637
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.