about summary refs log tree commit diff
path: root/src/tools/clippy/clippy_utils
AgeCommit message (Collapse)AuthorLines
2025-07-06clippy: migrate BareFn -> FnPtrJubilee Young-13/+13
2025-07-06Rewrite empty attribute lintJonathan Brouwer-1/+1
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-05clippy: conditions are no longer wrapped in `DropTemps`dianne-30/+19
2025-07-04Port `#[non_exhaustive]` to the new attribute parsing infrastructureJonathan Brouwer-4/+5
2025-07-03Replace kw_span by full span.Camille GILLOT-2/+2
2025-07-02Rollup merge of #143306 - samueltardieu:track-clippy-lints-emission, ↵Matthias Krüger-0/+7
r=petrochenkov Add `track_caller` attributes to trace origin of Clippy lints This allows the use of `-Z track-diagnostics` to see the origin of Clippy lints emission, as is already the case for lints coming from rustc.
2025-07-02Add `track_caller` attributes to trace origin of Clippy lintsSamuel Tardieu-0/+7
This allows the use of `-Z track-diagnostics` to see the origin of Clippy lints emission, as is already the case for lints coming from rustc.
2025-07-01Remove support for dyn*Michael Goulet-4/+0
2025-06-30Introduce `ByteSymbol`.Nicholas Nethercote-5/+7
It's like `Symbol` but for byte strings. The interner is now used for both `Symbol` and `ByteSymbol`. E.g. if you intern `"dog"` and `b"dog"` you'll get a `Symbol` and a `ByteSymbol` with the same index and the characters will only be stored once. The motivation for this is to eliminate the `Arc`s in `ast::LitKind`, to make `ast::LitKind` impl `Copy`, and to avoid the need to arena-allocate `ast::LitKind` in HIR. The latter change reduces peak memory by a non-trivial amount on literal-heavy benchmarks such as `deep-vector` and `tuple-stress`. `Encoder`, `Decoder`, `SpanEncoder`, and `SpanDecoder` all get some changes so that they can handle normal strings and byte strings. This change does slow down compilation of programs that use `include_bytes!` on large files, because the contents of those files are now interned (hashed). This makes `include_bytes!` more similar to `include_str!`, though `include_bytes!` contents still aren't escaped, and hashing is still much cheaper than escaping.
2025-06-27Auto merge of #143116 - matthiaskrgr:rollup-zy9ez06, r=matthiaskrgrbors-1/+1
Rollup of 9 pull requests Successful merges: - rust-lang/rust#139858 (New const traits syntax) - rust-lang/rust#140809 (Reduce special casing for the panic runtime) - rust-lang/rust#142730 (suggest declaring modules when file found but module not defined) - rust-lang/rust#142806 (Normalize before computing ConstArgHasType goal in new solver) - rust-lang/rust#143046 (const validation: properly ignore zero-sized UnsafeCell) - rust-lang/rust#143092 (const checks for lifetime-extended temporaries: avoid 'top-level scope' terminology) - rust-lang/rust#143096 (tag_for_variant: properly pass TypingEnv) - rust-lang/rust#143104 (hir_analysis: prohibit `dyn PointeeSized`) - rust-lang/rust#143106 (gce: don't ICE on non-local const) Failed merges: - rust-lang/rust#143036 (Remove support for `dyn*` from the compiler) r? `@ghost` `@rustbot` modify labels: rollup
2025-06-27Merge commit 'c5dbd1de07e0407b9687619a868384d6de06253f' into ↵Philipp Krones-31/+85
clippy-subtree-update
2025-06-26Change const trait bound syntax from ~const to [const]Oli Scherer-1/+1
2025-06-22Port `#[must_use]` to new attribute parsing infrastructureJonathan Brouwer-5/+16
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-20clippy: replace path uses by diagnostic itemsSamuel Tardieu-9/+0
2025-06-13TypeVisiting binders no longer requires TypeFolding its interiorMichael Goulet-2/+2
2025-06-13Auto merge of #142451 - flip1995:clippy-subtree-update, r=Manishearthbors-15/+72
Clippy subtree update r? `@Manishearth` 1 day late. Got distracted yesterday evening and forgot about it.
2025-06-13Merge commit '4ef75291b5dd6739212f1f61666d19d4e086690d' into ↵Philipp Krones-15/+72
clippy-subtree-update
2025-06-12intrinsics: rename min_align_of to align_ofRalf Jung-1/+0
2025-06-05Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of NoneOli Scherer-1/+1
2025-06-04Rollup merge of #141570 - chenyukang:yukang-fix-eq_unspanned, r=workingjubileeMatthias Krüger-1/+3
Fix incorrect eq_unspanned in TokenStream Fixes rust-lang/rust#141522 r? ``@workingjubilee`` should we remove this function? since it's used in several places, i'd prefer to keep it.
2025-06-03Rollup merge of #141741 - nnethercote:overhaul-UsePath, r=petrochenkovMatthias Krüger-4/+7
Overhaul `UsePath` It currently uses `SmallVec<[Res; 3]>` which is really weird. Details in the individual commits. r? `@petrochenkov`
2025-06-03Overhaul `UsePath`.Nicholas Nethercote-4/+7
`UsePath` contains a `SmallVec<[Res; 3]>`. This holds up to three `Res` results, one per namespace (type, value, or macro). `lower_import_res` takes a `PerNS<Option<Res<NodeId>>>` result and lowers it into the `SmallVec`. This is pretty weird. The input `PerNS` makes it clear which `Res` belongs to which namespace, but the `SmallVec` throws that information away. And code that operates on the `SmallVec` tends to use iteration (or even just grabbing the first entry!) without knowing which namespace the `Res` belongs to. Even weirder! Also, `SmallVec` is an overly flexible type to use here, because it can contain any number of elements (even though it's optimized for 3 in this case). This commit changes `UsePath` so it also contains a `PerNS<Option<Res<HirId>>>`. This type preserves more information and is more self-documenting. The commit also changes a lot of the use sites to access the result for a particular namespace. E.g. if you're looking up a trait, it will be in the `Res` for the type namespace if it's present; it's silly to look in the `Res` for the value namespace or macro namespace. Overall I find the new code much easier to understand. However, some use sites still iterate. These now use `present_items` because that filters out the `None` results. Also, `redundant_pub_crate.rs` gets a bigger change. A `UseKind:ListStem` item gets no `Res` results, which means the old `all` call in `is_not_macro_export` would succeed (because `all` succeeds on an empty iterator) and the `ListStem` would be ignored. This is what we want, but was more by luck than design. The new code detects `ListStem` explicitly. The commit generalizes the name of that function accordingly. Finally, the commit also removes the `use_path` arena, because `PerNS<Option<Res>>` impls `Copy` (unlike `SmallVec`) and it can be allocated in the arena shared by all `Copy` types.
2025-06-02Auto merge of #141814 - flip1995:clippy-subtree-update, r=Manishearthbors-11/+14
Clippy subtree update r? `@Manishearth`
2025-05-31Merge commit '57cbadd68ac473bc50453f6b1320a02b68115f12'Philipp Krones-11/+14
2025-05-30Reorder fields in `hir::ItemKind` variants.Nicholas Nethercote-2/+2
Specifically `TyAlias`, `Enum`, `Struct`, `Union`. So the fields match the textual order in the source code. The interesting part of the change is in `compiler/rustc_hir/src/hir.rs`. The rest is extremely mechanical refactoring.
2025-05-29Rollup merge of #141675 - nnethercote:ItemKind-field-order, r=fee1-deadJacob Pratt-4/+4
Reorder `ast::ItemKind::{Struct,Enum,Union}` fields. So they match the order of the parts in the source code, e.g.: ``` struct Foo<T, U> { t: T, u: U } <-><----> <------------> / | \ ident generics variant_data ``` r? `@fee1-dead`
2025-05-29Rollup merge of #141638 - oli-obk:builtin-index, r=lcnrJacob Pratt-3/+1
Use `builtin_index` instead of hand-rolling it Just using the dedicated method more
2025-05-28Use `builin_index` instead of hand-rolling itOli Scherer-3/+1
2025-05-28Reorder `ast::ItemKind::{Struct,Enum,Union}` fields.Nicholas Nethercote-4/+4
So they match the order of the parts in the source code, e.g.: ``` struct Foo<T, U> { t: T, u: U } <-><----> <------------> / | \ ident generics variant_data ```
2025-05-27Rename unpack to kindMichael Goulet-8/+8
2025-05-26remove eq_unspanned from TokenStreamyukang-1/+3
2025-05-23Properly analyze captures from unsafe bindersMichael Goulet-0/+2
2025-05-21Merge commit 'cadf98bb7d783e2ea3572446c3f80d3592ec5f86' into ↵Philipp Krones-154/+357
clippy-subtree-update
2025-05-19Rollup merge of #140874 - mejrs:rads, r=WaffleLapkinStuart Cook-4/+6
make `rustc_attr_parsing` less dominant in the rustc crate graph It has/had a glob re-export of `rustc_attr_data_structures`, which is a crate much lower in the graph, and a lot of crates were using it *just* (or *mostly*) for that re-export, while they can rely on `rustc_attr_data_structures` directly. Previous graph: ![graph_1](https://github.com/user-attachments/assets/f4a5f13c-4222-4903-b56d-28c83511fcbd) Graph with this PR: ![graph_2](https://github.com/user-attachments/assets/1e053d9c-75cc-402b-84df-86229c98277a) The first commit keeps the re-export, and just changes the dependency if possible. The second commit is the "breaking change" which removes the re-export, and "explicitly" adds the `rustc_attr_data_structures` dependency where needed. It also switches over some src/tools/*. The second commit is actually a lot more involved than I expected. Please let me know if it's a better idea to back it out and just keep the first commit.
2025-05-18Remove rustc_attr_data_structures re-export from rustc_attr_parsingmejrs-4/+6
2025-05-15Merge commit '0450db33a5d8587f7c1d4b6d233dac963605766b' into ↵Philipp Krones-444/+468
clippy-subtree-update
2025-05-07Require T: TypeFoldable in Binder<T> visitMichael Goulet-3/+3
2025-05-01Merge commit '03a5b6b976ac121f4233775c49a4bce026065b47' into ↵Philipp Krones-11/+54
clippy-subtree-update
2025-04-28Add or-patterns to pattern typesOli Scherer-0/+5
2025-04-23Clippy: Fix doc issuePhilipp Krones-0/+1
2025-04-22Merge commit '0621446356e20fd2ead13a6763bb936c95eb0cfa' into ↵Philipp Krones-345/+485
clippy-subtree-update
2025-04-18Rollup merge of #139615 - nnethercote:rm-name_or_empty, r=jdonszelmannMatthias Krüger-2/+2
Remove `name_or_empty` Another step towards #137978. r? ``@jdonszelmann``
2025-04-17Replace infallible `name_or_empty` methods with fallible `name` methods.Nicholas Nethercote-2/+2
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-16Rename `LifetimeName` as `LifetimeKind`.Nicholas Nethercote-4/+4
It's a much better name, more consistent with how we name such things. Also rename `Lifetime::res` as `Lifetime::kind` to match. I suspect this field used to have the type `LifetimeRes` and then the type was changed but the field name remained the same.
2025-04-14Move `has_self` field to `hir::AssocKind::Fn`.Nicholas Nethercote-3/+3
`hir::AssocItem` currently has a boolean `fn_has_self_parameter` field, which is misplaced, because it's only relevant for associated fns, not for associated consts or types. This commit moves it (and renames it) to the `AssocKind::Fn` variant, where it belongs. This requires introducing a new C-style enum, `AssocTag`, which is like `AssocKind` but without the fields. This is because `AssocKind` values are passed to various functions like `find_by_ident_and_kind` to indicate what kind of associated item should be searched for, and having to specify `has_self` isn't relevant there. New methods: - Predicates `AssocItem::is_fn` and `AssocItem::is_method`. - `AssocItem::as_tag` which converts `AssocItem::kind` to `AssocTag`. Removed `find_by_name_and_kinds`, which is unused. `AssocItem::descr` can now distinguish between methods and associated functions, which slightly improves some error messages.
2025-04-14Use `Symbol` in `LateContext::get_associated_type`.Nicholas Nethercote-1/+1
To avoid unnecessary interning.
2025-04-11Rollup merge of #139662 - nnethercote:tweak-DefPathData, r=compiler-errorsJacob Pratt-3/+3
Tweak `DefPathData` Some improvements in and around `DefPathData`, following on from #137977. r? `@spastorino`
2025-04-11Introduce `DefPathData::AnonAssocTy`.Nicholas Nethercote-3/+3
PR #137977 changed `DefPathData::TypeNs` to contain `Option<Symbol>` to account for RPITIT assoc types being anonymous. This commit changes it back to `Symbol` and gives anonymous assoc types their own variant. It makes things a bit nicer overall.
2025-04-11Rollup merge of #138682 - Alexendoo:extra-symbols, r=fee1-deadStuart Cook-1/+26
Allow drivers to supply a list of extra symbols to intern Allows adding new symbols as `const`s in external drivers, desirable in Clippy so we can use them in patterns to replace code like https://github.com/rust-lang/rust/blob/75530e9f72a1990ed2305e16fd51d02f47048f12/src/tools/clippy/clippy_lints/src/casts/cast_ptr_alignment.rs#L66 The Clippy change adds a couple symbols as a demo, the exact `clippy_utils` API and replacing other usages can be done on the Clippy side to minimise sync conflicts --- try-job: aarch64-gnu
2025-04-10Allow drivers to supply a list of extra symbols to internAlex Macleod-1/+26