Commit Graph

207 Commits

Author SHA1 Message Date
Nick Drozd b71fe9254d Check structs and enums for use_self 2025-10-09 18:23:12 -05:00
Nick Drozd 5318883d75 Use expect for lint warnings 2025-10-06 20:17:12 -04:00
Jason Newcomb 6cc8f8dbaa Do not trigger inefficient_to_string after Rust 1.82 (#15729)
Starting with Rust version 1.82.0, the compiler generates similar code
with and without the `with_ref` cfg:

```rust
fn f(x: impl IntoIterator<Item = String>) {
    for y in x { println!("{y}"); }
}

fn main() {
    #[cfg(with_ref)]
    let a = ["foo", "bar"].iter().map(|&s| s.to_string());
    #[cfg(not(with_ref))]
    let a = ["foo", "bar"].iter().map(|s| s.to_string());
    f(a);
}
```

The generated code is strictly identical with `-O`, and identical modulo
some minor reordering without.

changelog: [`inefficient_to_string`]: do not trigger for Rust ≥ 1.82.0
2025-10-01 22:02:53 +00:00
Samuel Tardieu 951d35eeb6 Do not trigger inefficient_to_string after Rust 1.82
Starting with Rust version 1.82.0, the compiler generates similar code with
and without the `with_ref` cfg:

```rust
fn f(x: impl IntoIterator<Item = String>) {
    for y in x { println!("{y}"); }
}

fn main() {
    #[cfg(with_ref)]
    let a = ["foo", "bar"].iter().map(|&s| s.to_string());
    #[cfg(not(with_ref))]
    let a = ["foo", "bar"].iter().map(|s| s.to_string());
    f(a);
}
```

The generated code is strictly identical with `-O`, and identical modulo
some minor reordering without.
2025-10-01 23:13:33 +02:00
Alejandra González 0c7e0344cf Do not suggest using a if let chain if it is not supported (#15746)
This might be due to a low edition (< 2024) or too low a MSRV. In this
case, we will suggest only `match`.

Fixes rust-lang/rust-clippy#15744

changelog: [`unnecessary_unwrap`]: do not suggest using `if let` chains
if this is not supported with the current edition or MSRV
changelog:[`collapsible_if`]: Do not suggest using `if let` if this is
not supported with the current edition or MSRV
2025-10-01 16:08:15 +00:00
Samuel Tardieu f1079915b4 Do not suggest using a if let chain if it is not supported
This might be due to a low edition (< 2024) or too low a MSRV.
2025-10-01 07:41:49 +02:00
Jason Newcomb 5e02a4eecf rename unchecked_duration_subtraction to unchecked_time_subtraction and check for Duration - Duration (#13800)
fixes https://github.com/rust-lang/rust-clippy/issues/13734

This PR renames `unchecked_duration_subtraction` lint to
`unchecked_time_subtraction` and extends it to include `Duration -
Duration` operations. Previously, it was only `Instant - Duration`.
`Duration - Duration` is a common operation which may panic in the same
way.

Note: This is my first clippy PR, feedback is appreciated.

changelog: [`unchecked_time_subtraction`]: renamed from
`unchecked_duration_subtraction`, extend lint to include subtraction of
a `Duration` with a `Duration`
2025-09-27 08:28:58 +00:00
Ada Alakbarova 7449d63ab7 fix(or_fun_call): respect MSRV for Result::unwrap_or_default suggestion 2025-09-24 19:25:08 +02:00
Philipp Krones 6b14443a02 Bump Clippy version -> 0.1.92 2025-09-18 16:59:44 +02:00
Emmanuel Thompson 2972ae5e53 rename_lint: unchecked_duration_subtraction to unchecked_time_subtraction 2025-09-17 09:30:22 -04:00
Philipp Krones 9b0611ff7a Merge commit 'e9b70454e4c9584be3b22ddabd26b741aeb06c10' into clippy-subtree-update 2025-09-04 18:27:27 -04:00
Teodoro Freund fc3959044f Supress excessive_precision when constants are overly precise
Added const associated items matching and static

Added configurable threshold

Addressed comments

Renamed lint config field
2025-08-31 16:38:57 +01:00
yanglsh 54ced9fd1c doc_markdown: add InfiniBand and RoCE to whitelist 2025-08-26 06:13:26 +08:00
Philipp Krones 7dd11b8119 Check config options in test suite (#15397)
Check that all configuration options reference existing lints. This was
prompted by a discussion on a PR review in which a non-detected
discrepancy was introduced.

While adding and testing this test, references to two non-existing lints
were removed.

This test doesn't run as part of the rustc test suite.

changelog: none
2025-08-23 13:45:35 +00:00
Philipp Krones 71b79ab466 Merge commit '877967959ae8da9814df4f2614971f4d784bf53f' into clippy-subtree-update 2025-08-22 14:57:22 +02:00
Dave Rolsky 5c617b4867 Add "PowerPC" to the list of valid CamelCase strings in docs 2025-08-09 10:28:14 -05:00
Philipp Krones eb15cf0a30 Merge commit '334fb906aef13d20050987b13448f37391bb97a2' into clippy-subtree-update 2025-08-07 17:05:15 +02:00
Philipp Krones d5f9f7576c Bump Clippy version -> 0.1.91 2025-08-07 16:48:16 +02:00
Samuel Tardieu a7162e416e Remove references to two unknown lints in config
`option_map_unwrap_or` and `seek_rewind` are not current lints, and
cannot be referenced as having the `msrv` configuration option.
2025-08-03 00:04:55 +02:00
Samuel Tardieu 18a13b15fe Do not treat NixOS as a Pascal-cased identifier 2025-07-28 15:25:46 +02:00
Philipp Krones 4e614bf683 Merge commit 'cdbbf3afda0b1bf51568b368f629b1d828507f98' into clippy-subtree-update 2025-07-10 20:25:36 +02:00
Philipp Krones 074ccaf3c0 Merge commit 'c5dbd1de07e0407b9687619a868384d6de06253f' into clippy-subtree-update 2025-06-27 12:20:57 +02:00
Samuel Tardieu 9117cb0223 zero_ptr: lint in const context as well
The lint was extra restrictive, and didn't suggest using
`core::ptr::null` and `core::ptr::null_mut` in `const` contexts although
they have been const-stabilized since Rust 1.24.
2025-06-26 23:09:37 +02:00
Philipp Krones 32fcff8aa8 Bump Clippy version -> 0.1.90 2025-06-26 19:30:02 +02:00
Samuel Tardieu 19c1c70905 Add allow-invalid configuration option for disallowed_* to the documentation (#14845)
Close rust-lang/rust-clippy#14836

changelog: none
2025-06-17 09:05:05 +00:00
yanglsh fea8dd28a0 Lint more cases in collapsible_else_if 2025-06-13 22:54:59 +08:00
Philipp Krones 9f86a576e3 Merge commit '57cbadd68ac473bc50453f6b1320a02b68115f12' 2025-05-31 14:22:15 +02:00
Jason Newcomb 9fa448a119 Make trivial-copy-size-limit consistently the size of the target pointer (#13319)
Fixes
https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Ambiguous.20default.20value.20for.20.60trivial-copy-size-limit.60

The current situation is

| Target width | `trivial-copy-size-limit`|
|--------|--------|
| 8-bit | 2 |
| 16-bit | 4 |
| 32-bit | 8 |
| 64-bit | 8 |

~~Since practically speaking it's almost always 8, let's go with that as
the unconditional default to make it easier to understand~~

Now defaults to `target_pointer_width`

changelog: [`trivial-copy-size-limit`] now also defaults to the size of
a target pointer (unchanged for 64-bit targets)
2025-05-21 20:05:31 +00:00
Philipp Krones 7debaf6b44 Merge commit 'cadf98bb7d783e2ea3572446c3f80d3592ec5f86' into clippy-subtree-update 2025-05-21 15:15:38 +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
Alexey Semenyuk 0bac1ca2a7 Add allow-invalid configuration option for disallowed_* to the documentation 2025-05-20 09:22:37 +05:00
Jason Newcomb 9d47e0c8ce clippy_dev: remove the need for markers when bumping the version 2025-05-17 04:27:39 -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
Samuel Tardieu fe4b4e8329 mem::size_of_val is const-stable since Rust 1.85 2025-05-14 23:38:37 +02:00
SLUCHABLUB 488e4e53d2 Add the allow_exact_repetitions option to the module_name_repetitions lint. 2025-05-14 10:49:01 +02:00
llogiq 17f2a87c0c Add internal lint derive_deserialize_allowing_unknown (#14360)
Adds an internal lint to check for `#[derive(serde::Deserialize)]`
without
[`#[serde(deny_unknown_fields)]`](https://serde.rs/container-attrs.html#deny_unknown_fields).

Today, if you run Clippy with the following clippy.toml, Clippy will
produce a warning, but there will be no accompanying note:
```toml
# In the following configuration, "recommendation" should be "reason" or "replacement".
disallowed-macros = [
    { path = "std::panic", recommendation = "return a `std::result::Result::Error` instead" },
]
```
```sh
$ cargo clippy
    Checking a v0.1.0 (/home/smoelius/tmp/a)
warning: use of a disallowed macro `std::panic`
 --> src/lib.rs:2:5
  |
2 |     panic!();
  |     ^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_macros
  = note: `#[warn(clippy::disallowed_macros)]` on by default
```
The underlying problem is: the enum that derives `serde::Deserialize`
([`DisallowedPathEnum`](https://github.com/rust-lang/rust-clippy/blob/81643e297cf44ce3c7648b8443fc4d6592fa81eb/clippy_config/src/types.rs#L47))
does not have the attribute `#[serde(deny_unknown_fields)]`.

This lint identifies such problems by checking trait `impl`s. An
alternative I considered was to walk `clippy_config::conf::Conf`
directly. However, that would not catch the `DisallowedPathEnum` case
because it [is not used in `Conf`
directly](https://github.com/rust-lang/rust-clippy/blob/81643e297cf44ce3c7648b8443fc4d6592fa81eb/clippy_config/src/types.rs#L31).

Just to be clear, no one asked for this. So I hope the maintainers do
not mind.

changelog: none
2025-05-13 15:36:57 +00:00
Samuel Moelius 9f4ecea242 Add internal lint derive_deserialize_allowing_unknown 2025-05-13 10:48:41 -04: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
Samuel Tardieu 73dd05cc7a add allow_unused config to missing_docs_in_private_items (#14453)
fixes #14413
add allow_unused config to missing_docs_in_private_items for underscored
field

changelog: [`missing_docs_in_private_items`]: add allow_unused config to
missing_docs_in_private_items for underscored field

Explaination (quoted from the issue's author): When writing structures
that must adhere to a specific format (such as memory mapped I/O
structures) there are inevitably fields that are "reserved" by
specifications and thus need no documentation. In cases where private
docs are preferred but reserved fields need no explanation, having to
#[allow/expect] this lint removes the ability to check for otherwise
used fields' documentation.
2025-05-06 17:18:14 +00:00
Alex Macleod 737d3b3363 Remove some unused #![feature]s 2025-05-06 14:07:39 +00:00
Alex Macleod f23772ce8c Move lookup_path and similar into clippy_utils::paths 2025-05-04 17:13:02 +00:00
Alex Macleod b768fbe4bc Replace str path utils with new PathLookup type 2025-05-04 15:26:37 +00:00
Samuel Moelius 7b7a9a6ece Don't warn about unloaded crates
Fixes https://github.com/rust-lang/rust-clippy/pull/14397#issuecomment-2848328221
2025-05-04 09:22:29 -04:00
Quang Duong Nguyen 481abc1361 fix doc 2025-05-03 15:17:03 -07:00
Quang Duong Nguyen c468552097 add allow_unused config to missing_docs_in_private_items
add allow_unused config to missing_docs_in_private_items for underscored field
2025-05-03 15:17:03 -07:00
Philipp Krones ff428d91c2 Merge commit '0621446356e20fd2ead13a6763bb936c95eb0cfa' into clippy-subtree-update 2025-04-22 18:24:43 +02:00
Alejandra González 02764f611a Various fixes for manual_is_power_of_two (#14463)
Fix #14461:

- insert parentheses as required in suggestion
- check MSRV before suggesting fix in `const` context
- do not lint macro expansion result

Commits have been logically separated to facilitate review, and start
with a refactoring (and simplification) of the existing code.

changelog: [`manual_is_power_of_two`]: insert parentheses as required in
suggestion, check MSRV before suggesting fix in `const` context, do not
lint macro expansion results
2025-04-14 22:56:38 +00:00
Samuel Tardieu 4d343d56e1 Check MSRV before suggesting fix in const context 2025-04-14 22:05:44 +02:00
Samuel Tardieu e463309f4a add manual_abs_diff lint (#14482)
changelog: [`manual_abs_diff`]: Initial implementation

Hey, first time writing a new lint for clippy, hope I got it right. I
think it's pretty self-explanatory!
Added a few `fixme` test cases, where the lint can be improved to catch
more (probably rare) patterns, but opening a PR with this initial
implementation to make sure I'm on the right track, and that this lint
is acceptable at all.

😁
2025-04-09 10:29:48 +00:00