about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2025-02-12Rollup merge of #136900 - workingjubilee:format-externabi-directly, r=oli-obkGuillaume Gomez-4/+4
compiler: replace `ExternAbi::name` calls with formatters Most of these just format the ABI string, so... just format ExternAbi? This makes it more consistent and less jank when we can do it.
2025-02-11compiler: replace ExternAbi::name calls with formattersJubilee Young-4/+4
Most of these just format the ABI string, so... just format ExternAbi? This makes it more consistent and less jank when we can do it.
2025-02-11Handle pattern types wrapped in `Option` in FFI checksOli Scherer-0/+32
2025-02-11Correctly handle pattern types in FFI redeclaration lintsOli Scherer-58/+60
2025-02-11Correctly handle pattern types in FFI safetyOli Scherer-5/+3
2025-02-10Rename rustc_middle::Ty::is_unsafe_ptr to is_raw_ptrBastian Kersting-1/+1
The wording unsafe pointer is less common and not mentioned in a lot of places, instead this is usually called a "raw pointer". For the sake of uniformity, we rename this method. This came up during the review of https://github.com/rust-lang/rust/pull/134424.
2025-02-09Remove lifetime_capture_rules_2024 featureMichael Goulet-4/+2
2025-02-09Rollup merge of #136760 - chenyukang:fix-overflowing-int-lint-crash, r=oli-obkMatthias Krüger-4/+7
Fix unwrap error in overflowing int literal Fixes #136675 it's maybe `negative` only from [check_lit](https://github.com/chenyukang/rust/blob/526e3288feb68eac55013746e03fb54d6a0b9a1e/compiler/rustc_lint/src/types.rs#L546), in this scenario the fields in `TypeLimits` is none. r? ``@oli-obk``
2025-02-09Auto merge of #136751 - bjorn3:update_rustfmt, r=Mark-Simulacrumbors-407/+543
Update bootstrap compiler and rustfmt The rustfmt version we previously used formats things differently from what the latest nightly rustfmt does. This causes issues for subtrees that get formatted both in-tree and in their own repo. Updating the rustfmt used in-tree solves those issues. Also bumped the bootstrap compiler as the stage0 update command always updates both at the same time.
2025-02-09Fix unwrap error in overflowing int literalyukang-4/+7
2025-02-08Rustfmtbjorn3-407/+543
2025-02-08Rollup merge of #136657 - jdonszelmann:empty-line-after, ↵Matthias Krüger-0/+10
r=y21,flip1995,WaffleLapkin Make empty-line-after an early clippy lint r? ```@y21``` 95% a refiling of https://github.com/rust-lang/rust-clippy/pull/13658 but for correctness it needed 2 extra methods in `rust_lint` which made it much easier to apply on `rust-lang/rust` than `rust-lang/rust-clippy`. Commits have been thoroughly reviewed on `rust-lang/clippy already`. The last two review comments there (about using `Option` and popping for assoc items have been applied here.
2025-02-07fix empty after lint on impl/trait itemsJonathan Dönszelmann-0/+10
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
2025-02-06allow+update `deref_into_dyn_supertrait`Waffle Lapkin-13/+11
this commit makes `deref_into_dyn_supertrait` lint allow-by-default, removes future incompatibility (we finally live in a broken world), and changes the wording in the documentation. previously documentation erroneously said that it lints against *usage* of the deref impl, while it actually (since 104742) lints on the impl itself (oooops, my oversight, should have updated it 2+ years ago...)
2025-02-06change `deref_into_dyn_supertrait` lint wordingWaffle Lapkin-5/+6
(so that it doesn't talk about trait upcasting stabilization in the future tense)
2025-02-06stabilize `feature(trait_upcasting)`Waffle Lapkin-1/+1
2025-02-06Rollup merge of #136393 - oli-obk:pattern-type-lit-oflo-checks, ↵Matthias Krüger-32/+60
r=compiler-errors Fix accidentally not emitting overflowing literals lints anymore in patterns This was regressed in https://github.com/rust-lang/rust/pull/134228 (not in beta yet). The issue was that previously we nested `hir::Expr` inside `hir::PatKind::Lit`, so it was linted by the expression code. So now I've set it up for visitors to be able to directly visit literals and get all literals
2025-02-05Uniformly handle HIR literals in visitors and lintsOli Scherer-5/+24
2025-02-05Avoid passing around an `Expr` that is only needed for its HirId and its SpanOli Scherer-31/+40
2025-02-05Rollup merge of #135964 - ehuss:cenum_impl_drop_cast, r=Nadrieril许杰友 Jieyou Xu (Joe)-0/+5
Make cenum_impl_drop_cast a hard error This changes the `cenum_impl_drop_cast` lint to be a hard error. This lint has been deny-by-default and warning in dependencies since https://github.com/rust-lang/rust/pull/97652 about 2.5 years ago. Closes https://github.com/rust-lang/rust/issues/73333
2025-02-04Rollup merge of #136242 - samueltardieu:remove-match-def-path, r=flip1995Matthias Krüger-25/+1
Remove `LateContext::match_def_path()` This function was only kept for Clippy use. The last use in Clippy was removed in c9315bc3953fcf15154df21f788f2f7a5e8d6e7d.
2025-02-02Rollup merge of #136422 - nnethercote:convert-lint-functions, r=NoratriebMatthias Krüger-9/+8
Convert two `rustc_middle::lint` functions to `Span` methods. `rustc_middle` is a huge crate and it's always good to move stuff out of it. There are lots of similar methods already on `Span`, so these two functions, `in_external_macro` and `is_from_async_await`, fit right in. The diff is big because `in_external_macro` is used a lot by clippy lints. r? ``@Noratrieb``
2025-02-02Convert two `rustc_middle::lint` functions to `Span` methods.Nicholas Nethercote-9/+8
`rustc_middle` is a huge crate and it's always good to move stuff out of it. There are lots of similar methods already on `Span`, so these two functions, `in_external_macro` and `is_from_async_await`, fit right in. The diff is big because `in_external_macro` is used a lot by clippy lints.
2025-02-01Rename `tcx.ensure()` to `tcx.ensure_ok()`Zalathar-1/+1
2025-01-31Rollup merge of #135860 - fmease:compiler-mv-obj-save-dyn-compat-ii, r=jieyouxuMatthias Krüger-1/+1
Compiler: Finalize dyn compatibility renaming Update the Reference link to use the new URL fragment from https://github.com/rust-lang/reference/pull/1666 (this change has finally hit stable). Fixes a FIXME. Follow-up to #130826. Part of #130852. ~~Blocking it on #133372.~~ (merged) r? ghost
2025-01-30Auto merge of #136038 - compiler-errors:outlives, r=lcnrbors-4/+2
Simplify and consolidate the way we handle construct `OutlivesEnvironment` for lexical region resolution This is best reviewed commit-by-commit. I tried to consolidate the API for lexical region resolution *first*, then change the API when it was finally behind a single surface. r? lcnr or reassign
2025-01-29Eliminate PatKind::PathOli Scherer-8/+10
2025-01-29Remove `LateContext::match_def_path()`Samuel Tardieu-25/+1
This function was only kept for Clippy use. The last use in Clippy was removed in c9315bc3953fcf15154df21f788f2f7a5e8d6e7d.
2025-01-29Rollup merge of #136164 - celinval:chores-fnkind, r=oli-obkLeón Orell Valerian Liehr-3/+5
Refactor FnKind variant to hold &Fn Pulling the change suggested in #128045 to reduce the impact of changing `Fn` item. r? `@oli-obk`
2025-01-28Refactor FnKind variant to hold &FnCelina G. Val-3/+5
2025-01-28Make item self/non-self bound naming less whackMichael Goulet-19/+16
2025-01-28Move outlives env computation into methodsMichael Goulet-4/+2
2025-01-28Consolidate OutlivesEnv construction with resolve_regionsMichael Goulet-1/+1
2025-01-27Rollup merge of #136114 - compiler-errors:more-idents, r=jieyouxuGuillaume Gomez-6/+6
Use identifiers more in diagnostics code This should make the diagnostics code slightly more correct when rendering idents in mixed crate edition situations. Kinda a no-op, but a cleanup regardless. r? oli-obk or reassign
2025-01-27Remove redundant to_ident_string callsMichael Goulet-2/+2
2025-01-27Use identifiers in diagnostics more oftenMichael Goulet-4/+4
2025-01-26Compiler: Finalize dyn compatibility renamingLeón Orell Valerian Liehr-1/+1
2025-01-26implement lint `double_negations`Kalle Wachsmuth-11/+83
2025-01-26unrelated cleanupKalle Wachsmuth-10/+2
2025-01-25Rollup merge of #133951 - bjorn3:wasm_c_abi_lint_hard_error, r=workingjubileeJacob Pratt-5/+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-25Rollup merge of #136016 - Urgau:check-cfg-allow-test-improv, r=jieyouxuMatthias Krüger-4/+25
Improve check-cfg expected names diagnostic This PR improves the check-cfg `allow-same-level` test by ~~normalizing it's output and by~~ adding more context to the test. It also filters the well known cfgs from the `expected names are` note, as to reduce the size of the diagnostic. Users can still find the full list on the [rustc book](https://doc.rust-lang.org/nightly/rustc/check-cfg.html#well-known-names-and-values), which is reinforced for Cargo users by adding a note in the Cargo check-cfg specific section. Fixes https://github.com/rust-lang/rust/issues/135995 r? `@jieyouxu`
2025-01-25Rollup merge of #134300 - RalfJung:remove-dead-attrs, r=chenyukangMatthias Krüger-21/+2
remove long-deprecated no-op attributes no_start and crate_id These have emitted a deprecation warning since forever (https://github.com/rust-lang/rust/pull/64471) and they already don't do anything. In fact they [apparently](https://github.com/rust-lang/rust/pull/64471#issuecomment-531517332) have done nothing since pre-1.0, so... do we even need a crater run? Doesn't seem worth it.
2025-01-25Filter well known names from check-cfg diagnosticsUrgau-4/+25
2025-01-24Auto merge of #135272 - BoxyUwU:generic_arg_infer_reliability_2, ↵bors-25/+23
r=compiler-errors Forbid usage of `hir` `Infer` const/ty variants in ambiguous contexts The feature `generic_arg_infer` allows providing `_` as an argument to const generics in order to infer them. This introduces a syntactic ambiguity as to whether generic arguments are type or const arguments. In order to get around this we introduced a fourth `GenericArg` variant, `Infer` used to represent `_` as an argument to generic parameters when we don't know if its a type or a const argument. This made hir visitors that care about `TyKind::Infer` or `ConstArgKind::Infer` very error prone as checking for `TyKind::Infer`s in `visit_ty` would find *some* type infer arguments but not *all* of them as they would sometimes be lowered to `GenericArg::Infer` instead. Additionally the `visit_infer` method would previously only visit `GenericArg::Infer` not *all* infers (e.g. `TyKind::Infer`), this made it very easy to override `visit_infer` and expect it to visit all infers when in reality it would only visit *some* infers. --- This PR aims to fix those issues by making the `TyKind` and `ConstArgKind` types generic over whether the infer types/consts are represented by `Ty/ConstArgKind::Infer` or out of line (e.g. by a `GenericArg::Infer` or accessible by overiding `visit_infer`). We then make HIR Visitors convert all const args and types to the versions where infer vars are stored out of line and call `visit_infer` in cases where a `Ty`/`Const` would previously have had a `Ty/ConstArgKind::Infer` variant: API Summary ```rust enum AmbigArg {} enum Ty/ConstArgKind<Unambig = ()> { ... Infer(Unambig), } impl Ty/ConstArg { fn try_as_ambig_ty/ct(self) -> Option<Ty/ConstArg<AmbigArg>>; } impl Ty/ConstArg<AmbigArg> { fn as_unambig_ty/ct(self) -> Ty/ConstArg; } enum InferKind { Ty(Ty), Const(ConstArg), Ambig(InferArg), } trait Visitor { ... fn visit_ty/const_arg(&mut self, Ty/ConstArg<AmbigArg>) -> Self::Result; fn visit_infer(&mut self, id: HirId, sp: Span, kind: InferKind) -> Self::Result; } // blanket impl'd, not meant to be overriden trait VisitorExt { fn visit_ty/const_arg_unambig(&mut self, Ty/ConstArg) -> Self::Result; } fn walk_unambig_ty/const_arg(&mut V, Ty/ConstArg) -> Self::Result; fn walk_ty/const_arg(&mut V, Ty/ConstArg<AmbigArg>) -> Self::Result; ``` The end result is that `visit_infer` visits *all* infer args and is also the *only* way to visit an infer arg, `visit_ty` and `visit_const_arg` can now no longer encounter a `Ty/ConstArgKind::Infer`. Representing this in the type system means that it is now very difficult to mess things up, either accessing `TyKind::Infer` "just works" and you won't miss *some* type infers- or it doesn't work and you have to look at `visit_infer` or some `GenericArg::Infer` which forces you to think about the full complexity involved. Unfortunately there is no lint right now about explicitly matching on uninhabited variants, I can't find the context for why this is the case :woman_shrugging: I'm not convinced the framing of un/ambig ty/consts is necessarily the right one but I'm not sure what would be better. I somewhat like calling them full/partial types based on the fact that `Ty<Partial>`/`Ty<Full>` directly specifies how many of the type kinds are actually represented compared to `Ty<Ambig>` which which leaves that to the reader to figure out based on the logical consequences of it the type being in an ambiguous position. --- tool changes have been modified in their own commits for easier reviewing by anyone getting cc'd from subtree changes. I also attempted to split out "bug fixes arising from the refactoring" into their own commit so they arent lumped in with a big general refactor commit Fixes #112110
2025-01-23Make cenum_impl_drop_cast a hard errorEric Huss-0/+5
This changes the `cenum_impl_drop_cast` lint to be a hard error. This lint has been deny-by-default and warning in dependencies since https://github.com/rust-lang/rust/pull/97652 about 2.5 years ago. Closes https://github.com/rust-lang/rust/issues/73333
2025-01-23Auto merge of #132666 - dingxiangfei2009:skip-if-let-rescope-lint, ↵bors-6/+5
r=compiler-errors Skip `if-let-rescope` lint unless requested by migration Tracked by #124085 Related to https://github.com/rust-lang/rust/pull/131984#issuecomment-2448329667 Given that `if-let-rescope` is a lint to be enabled globally by an edition migration, there is no point in extracting the precise lint level on the HIR expression. This mitigates the performance regression discovered by the earlier perf-run. cc `@Kobzol` `@rylev` `@traviscross` I propose a `rust-timer` run to measure how much performance that we can recover from the mitigation. :bow:
2025-01-23Make the wasm_c_abi future compat warning a hard errorbjorn3-5/+0
This is the next step in getting rid of the broken C abi for wasm32-unknown-unknown.
2025-01-23Rollup merge of #135552 - ↵Matthias Krüger-5/+133
amy-kwan:amy-kwan/reprc-struct-diagnostic-power-alignment, r=workingjubilee [AIX] Lint on structs that have a different alignment in AIX's C ABI This PR adds a linting diagnostic on AIX for repr(C) structs that are required to follow the power alignment rule. A repr(C) struct needs to follow the power alignment rule if the struct: - Has a floating-point data type (greater than 4-bytes) as its first member, or - The first member of the struct is an aggregate, whose recursively first member is a floating-point data type (greater than 4-bytes). The power alignment rule for eligible structs is currently unimplemented, so a linting diagnostic is produced when such a struct is encountered.
2025-01-23make `hir::Ty/ConstArg` methods generic where applicableBoxy-1/+1
2025-01-23`visit_x_unambig`Boxy-3/+3