Commit Graph

2157 Commits

Author SHA1 Message Date
Samuel Tardieu 2a5a2fae2c Use interned strings when possible, for efficiency purposes
Also, a number of unnecessary `.as_str()` calls have been removed for
clarity.
2025-06-03 20:50:40 +02:00
Jason Newcomb eafef84736 missing_const_for_fn: consider constness of instance (#14759)
When determining when a function or method can be called from a `const`
context, the determination must be made on the instance, not on the
declaration. This makes a difference, for example, with `const_trait`
traits whose implementations may or may not be `const`.

changelog: [`missing_const_for_fn`]: when checking if a function or
method can be called from a `const` context, look at the concrete
implementation rather than at the trait definition

Fixes rust-lang/rust-clippy#14658

r? @Jarcho
2025-06-03 14:03:51 +00:00
Alex Macleod 9b8c42cbb1 Test that all interned symbols are referenced in Clippy sources (#14842)
This test checks that all symbols defined in Clippy's `sym.rs` file are
used in Clippy. Otherwise, it will fail with a list of symbols which are
unused.

This test only runs when the `internal` feature is set, to allow
developers to temporarily define new, yet unused symbols without failing
the tests. Also, it will not run as part of the compiler test suite, as
an extra symbol should never be seen as a fatal problem in the compiler
repo.

changelog: none
2025-06-02 15:22:31 +00:00
Timo 3f48a2b01e Use interned symbols instead of strings in more places (#14855)
changelog: none
2025-06-01 12:02:36 +00:00
Samuel Tardieu 43b7d87be1 missing_const_for_fn: consider constness of instance
When determining when a function or method can be called from a `const`
context, the determination must be made on the instance, not on the
declaration. This makes a difference, for example, with `const_trait`
traits whose implementations may or may not be `const`.
2025-05-31 22:22:41 +02:00
Samuel Tardieu 3ed210c457 Use interned symbols instead of strings in more places 2025-05-31 18:25:49 +02:00
Philipp Krones cd71411f56 Bump nightly version -> 2025-05-31 2025-05-31 14:11:00 +02:00
Philipp Krones 384b53eee2 Merge remote-tracking branch 'upstream/master' into rustup 2025-05-31 14:09:03 +02:00
Jacob Pratt f7a97cc7b2 Rollup merge of #141675 - nnethercote:ItemKind-field-order, r=fee1-dead
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-29 04:49:43 +02:00
Jacob Pratt eeb4fa406c Rollup merge of #141638 - oli-obk:builtin-index, r=lcnr
Use `builtin_index` instead of hand-rolling it

Just using the dedicated method more
2025-05-29 04:49:42 +02:00
Oli Scherer 013ab6cdb1 Use builin_index instead of hand-rolling it 2025-05-28 10:03:01 +00:00
Nicholas Nethercote cb27c8af94 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
```
2025-05-28 15:48:45 +10:00
Michael Goulet 327967c351 Rename unpack to kind 2025-05-27 11:14:45 +00:00
Timo b719f99090 Consider consts in patterns as refutable (#14887)
changelog: none
2025-05-26 18:13:29 +00:00
Samuel Tardieu d82e51b640 Test that all interned symbols are referenced in Clippy sources 2025-05-25 11:52:24 +02:00
Alex Macleod 843a45f384 Consider consts in patterns as refutable 2025-05-24 18:11:35 +00:00
yanglsh 03af37302c fix: assign_op_pattern FP on unstable const trait 2025-05-25 02:02:11 +08:00
Michael Goulet 6059d59548 Properly analyze captures from unsafe binders 2025-05-23 10:43:13 +00:00
Philipp Krones 7debaf6b44 Merge commit 'cadf98bb7d783e2ea3572446c3f80d3592ec5f86' into clippy-subtree-update 2025-05-21 15:15:38 +02:00
Philipp Krones 8a28b797b8 Bump nightly version -> 2025-05-21 2025-05-21 14:50:25 +02:00
Philipp Krones 910e640f9b Merge remote-tracking branch 'upstream/master' into rustup 2025-05-21 14:50:06 +02:00
Timo 03ba508d0e Fixes manual_slice_size_computation ICE and triggers in const context (#14804)
The first commit fixes rust-lang/rust-clippy#14802: when a slice is
directly present, it must be dereferenced (instead of referenced -1
times) before being passed to `mem::size_of_val()`.

The second commit triggers the lint in a `const` contact when MSRV ≥
1.85.

changelog: [`manual_slice_size_computation`]: fix ICE in suggestion to
efficiently compute the size of a slice, and trigger the lint in `const`
context as well
2025-05-20 22:35:15 +00:00
Samuel Tardieu e16801e68c Use symbols instead of &str when possible 2025-05-19 22:47:57 +02:00
Samuel Tardieu 82bf659dc8 Ensure that symbols list stays sorted 2025-05-19 22:47:57 +02:00
Samuel Tardieu bb724f3421 Sort the existing list of symbols 2025-05-19 22:47:57 +02:00
Samuel Tardieu ebc2a68fe8 Add new useless_concat lint (#13829)
Fixes #13793.

Interestingly enough, to actually check that the macro call has at least
two arguments, we need to use the rust lexer after getting the original
source code snippet.

changelog: Add new `useless_concat` lint
2025-05-19 15:11:37 +00:00
Stuart Cook a22efe773d Rollup merge of #140874 - mejrs:rads, r=WaffleLapkin
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-19 13:24:54 +10:00
mejrs 035146e398 Remove rustc_attr_data_structures re-export from rustc_attr_parsing 2025-05-18 18:14:43 +02:00
Timo daeb6a1d18 Misc changes (#14702)
This mainly fixes `with_leading_whitespace` not always adding the
whitespace it can.

changelog: None
2025-05-17 10:40:21 +00:00
Jason Newcomb 9d47e0c8ce clippy_dev: remove the need for markers when bumping the version 2025-05-17 04:27:39 -04:00
llogiq 94cfebb397 Rewrite non_copy_const (#13207)
fixes #12979
fixes #12951
fixes #13233

Tests still need to be finished and the docs still need to be updated,
but this should otherwise ready.

changelog: Lint `declare_interior_mutable_const` and
`borrow_interior_mutable_const` more precisely
2025-05-16 15:05:36 +00:00
Samuel Tardieu feb70b51c4 match_same_arms, ifs_same_cond: lint once per same arm/condition (#14637)
A large fraction of the lints emitted in CI lintcheck come from [this
`match`](https://github.com/unicode-rs/unicode-normalization/blob/v0.1.23/src/tables.rs#L34289),
currently for `n` same arms `((n - 1) * n)/2` lints are emitted, with
this change it will be emitted as a single lint

Also fixes https://github.com/rust-lang/rust-clippy/issues/13835

changelog: none
2025-05-16 14:16:45 +00:00
Alex Macleod 39ab00a3a1 match_same_arms, ifs_same_cond: lint once per same arm/condition 2025-05-16 12:56:25 +00:00
Jason Newcomb 57782e0ff1 Rewrite non_copy_const 2025-05-16 06:08:35 -04:00
Philipp Krones 93bd4d8931 Merge commit '0450db33a5d8587f7c1d4b6d233dac963605766b' into clippy-subtree-update 2025-05-15 19:28:39 +02:00
Philipp Krones 367073195a Bump Clippy version -> 0.1.89 2025-05-15 19:19:46 +02:00
Philipp Krones 5be888c479 Bump nightly version -> 2025-05-14 2025-05-15 19:19:34 +02:00
Philipp Krones 0bb1b5bd3b Merge remote-tracking branch 'upstream/master' into rustup 2025-05-15 19:19:08 +02:00
Samuel Tardieu fe4b4e8329 mem::size_of_val is const-stable since Rust 1.85 2025-05-14 23:38:37 +02:00
Guillaume Gomez 0d25090d26 Improve code and apply suggestions 2025-05-14 19:05:05 +02:00
llogiq 7bac114c86 Add new lint: cloned_ref_to_slice_refs (#14284)
Added lint for catching `&[foo.clone()]` where foo is a reference and
suggests `std::slice::from_ref(foo)`.

changelog: new lint: [`cloned_ref_to_slice_refs`]
2025-05-13 05:32:33 +00:00
asdfish 40e1b0ed00 add lint cloned_ref_to_slice_refs
remove merge

removed false positive and improved tests

clarify known problems for `cloned_ref_to_slice_refs`
2025-05-12 21:12:58 -04:00
Guillaume Gomez 7b06d2b776 Move concat macro path into clippy_utils::paths 2025-05-12 14:14:45 +02:00
dswij f60807dfee Resolve through local re-exports in lookup_path (#14772)
Fixes https://github.com/rust-lang/rust-clippy/issues/14767

A long standing issue revealed by
https://github.com/rust-lang/rust-clippy/pull/14397

changelog: none
2025-05-10 16:55:19 +00:00
Samuel Tardieu bde939058b char::is_digit() is const-stable only since Rust 1.87
The `to_digit_is_some()` lint suggests using `char::is_digit()`. It
should not trigger in const contexts before Rust 1.87.
2025-05-10 00:20:55 +02:00
Alex Macleod e4d82aefd9 Resolve through local re-exports in lookup_path 2025-05-09 22:13:35 +00:00
Michael Goulet 303c4ecfdd Require T: TypeFoldable in Binder<T> visit 2025-05-07 16:00:21 +00:00
Alex Macleod 5aac708398 Replace Symbol::as_str usage in match expressions 2025-05-07 13:52:11 +00:00
Jason Newcomb 77157f5988 Actually check for a problematic line comment in with_leading_whitespace 2025-05-06 21:42:32 -04:00
Jason Newcomb a25c195101 Remove redundant work in trait_ref_of_method. 2025-05-06 21:42:04 -04:00