Commit graph

173 commits

Author SHA1 Message Date
Dave Rolsky
5c617b4867
Add "PowerPC" to the list of valid CamelCase strings in docs 2025-08-09 10:28:14 -05:00
Philipp Krones
d5f9f7576c
Bump Clippy version -> 0.1.91 2025-08-07 16:48:16 +02:00
Samuel Tardieu
18a13b15fe
Do not treat NixOS as a Pascal-cased identifier 2025-07-28 15:25:46 +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
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
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
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`](81643e297c/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](81643e297c/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
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
Philipp Krones
c97bd7463c
Bump Clippy version -> 0.1.88 2025-04-03 21:32:37 +02:00
Alex Macleod
ae0e3b7e38 Default trivial_copy_size_limit to the width of a target pointer 2025-04-03 12:18:45 +00:00
Yotam Ofek
52a3082056 add manual_abs_diff lint 2025-04-02 19:40:14 +00:00
Samuel Moelius
dc7d9ec35c Validate paths in disallowed_* configurations 2025-04-01 14:53:48 -04:00
Jason Newcomb
bb0d09b220
Make visit_map happy path more evident (#14376)
This is a small refactor of `ConfVisitor`'s `visit_map` method.

It adds comments and reduces `match` nesting by adding `continue`
statements.

IMHO, the code is easier to read in this form. No one asked for this, so
I hope the maintainers agree it is an improvement.

changelog: none
2025-03-31 10:18:56 +00:00
Timo
d88818d1e7
Rename inconsistent_struct_constructor configuration; don't suggest deprecated configurations (#14280)
This PR does two things:
- It renames `inconsistent_struct_constructor`'s configuration from
`lint-inconsistent-struct-field-initializers` to
`check-inconsistent-struct-field-initializers`. (I should have suggested
`check-...` in
[#13737](https://github.com/rust-lang/rust-clippy/pull/13737#discussion_r1875118516).)
- It causes Clippy to no longer suggest deprecated configurations.
(Previously, Clippy would suggest `cyclomatic-complexity-threshold`, for
example.)

r? @y21

changelog: Rename `lint-inconsistent-struct-field-initializers` to
`check-inconsistent-struct-field-initializers`
changelog: No longer suggest deprecated configurations
2025-03-25 11:56:47 +00:00
Timo
9c6cb5150f
wildcard_imports: lint on pub use if asked to (#14182)
`warn_on_all_wildcard_imports` should warn on all wildcard imports,
including the reexported ones.

Fix #13660

changelog: [`warn_on_all_wildcard_imports`]: when asked to warn on all
wildcard imports, include the reexported ones
2025-03-25 00:08:45 +00:00
Samuel Tardieu
809c931804 wildcard_imports: lint on pub use if asked to
`warn_on_all_wildcard_imports` should warn on all wildcard imports,
including the reexported ones.
2025-03-24 15:49:29 +01:00
Samuel Moelius
315e9aa79f Don't check deprecated configs in configs_are_tested test 2025-03-24 09:06:13 -04:00
Samuel Moelius
969b5ad65c Don't suggests deprecated congurations 2025-03-23 15:25:27 -04:00
Samuel Moelius
88b590bf46 lint-inconsistent-... -> check-inconsistent-... 2025-03-23 15:22:37 -04:00
Samuel Tardieu
82381608c9 Lint more cases in collapsible_if
Replace the use of `Sugg::ast()` which prevented combining `if`
together when they contained comments by span manipulation.

A new configuration option `lint_commented_code`, which is `true` by
default, opts out from this behavior.
2025-03-22 15:12:42 +01:00
Jan Verbeek
d793c0abfa Add MSRV check for question_mark 2025-03-19 09:33:58 +01:00
Samuel Moelius
0af04455f1 Make visit_map happy path more evident 2025-03-09 18:26:27 -04:00
decryphe
5df68878bf Make alphabetic ordering in module item groups configurable (new default: off)
From feedback to this lint after its inclusion in clippy 1.82, this has
turned out to be the most requested improvement. With this improvement,
it is possible to make the lint check certain top-level structural
checks on modules (e.g. use statements and module inclusions at the top),
but still leaving everything else up to the developer.
2025-03-04 09:50:47 +01:00
decryphe
9f0d819ced Create helper function to suggest a candidate in case of a typo 2025-03-04 09:50:47 +01:00
Alex Macleod
0972c3b565 Check for MSRV attributes in late passes using the HIR 2025-02-28 18:09:44 +00:00
Timo
2cdb90d961
New lint: manual_midpoint (#13851)
changelog: [`manual_midpoint`]: new lint

Closes #13849
2025-02-28 16:27:34 +00:00
Alejandra González
e1c1ac1592
configuration option to lint incompatible_msrv in test code (#14279)
fixes #14277

changelog: [`incompatible_msrv`]: add config option
[`check-incompatible-msrv-in-tests`] to enable in `#[test]` and
`#[cfg(test)]` code.
2025-02-28 12:41:46 +00:00
Samuel Tardieu
baadee8fd3 New lint: manual_midpoint 2025-02-27 22:12:16 +01:00
Bryce Berger
325bfef88d
configuration option to lint incompatible_msrv in test code 2025-02-25 19:54:05 -05:00
Manish Goregaokar
35d5ee0e41
add MSRV check for repeat_vec_with_capacity (#14126)
changelog: [`repeat_vec_with_capacity`]: add MSRV check
2025-02-23 15:50:44 +00:00
Andre Bogus
6366cca439 add io_other_error lint 2025-02-21 22:08:31 +01:00