Commit graph

478 commits

Author SHA1 Message Date
Samuel Tardieu
6c7fa3b2cb
Do not lint for wildcard_imports in external macro 2025-08-05 11:29:18 +02:00
Philipp Krones
c98e60a56e
Merge remote-tracking branch 'upstream/master' into rustup 2025-07-25 15:04:01 +02:00
Timo
c8e333c8c0
Fixed issue #15192 (#15241)
Fixes rust-lang/rust-clippy#15192 by adding checks for no_std while
giving out Box recommendation

```
changelog: [`large_enum_variant`]: Dont suggest `Box` in `no_std` mode
```
2025-07-20 10:37:58 +00:00
lakshay bhatia
b738d96325 Improve Help Message in large_enum_variant to satisfy #[no_std]
- Updated the `help:` text to include a more general suggestion
- Ensures compatibility with `#[no_std]` environments where boxing is
  still possible via `alloc`.
2025-07-20 13:51:45 +05:30
Jason Newcomb
c0dc3b616d
Various improvements to the incompatible_msrv lint (#14433)
This PR supersedes #14328 following the [2025-03-18 Clippy meeting
discussion](https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/Meeting.202025-03-18/with/506527762).
It uses a simpler approach than what was proposed initially in #14328
and does not add new options.

First, it documents how `cfg_attr` can be used to change the MSRV
considered by Clippy to trigger the lint. This allows the MSRV to be
feature gated, or to be raised in tests.

Also, the lint stops warning about items which have been explicitly
allowed through a rustc feature. This works even if the feature has been
stabilized since. It allows using an older compiler with some features
turned on, as is done in Rust for Linux. This fixes #14425.

Then, if the lint triggers, and it looks like the code is located below
a `cfg` or `cfg_attr` attribute, an additional note is issued, once, to
indicate that the `clippy::msrv` attribute can be controlled by an
attribute.

Finally, the lint is extended to cover any path, not just method and
function calls. For example, enumeration variants, or constants, were
not MSRV checked. This required replacing two `u32::MAX` by
`u32::max_value()` in MSRV-limited tests.

An extra commit adds a TODO for checking the const stability also, as
this is not done right now.

@Centri3 I'll assign this to you because you were assigned #14328 and
you were the one who nominated the issue for discussion (thanks!), but
of course feel free to reroll!

r? @Centri3

changelog: [`incompatible_msrv`]: better documentation, honor the
`features` attribute, and lint non-function entities as well
2025-07-16 16:24:01 +00:00
The Miri Cronjob Bot
461572aea3 Merge from rustc 2025-07-14 05:07:40 +00:00
Camille GILLOT
8510965e6b Retire hir::*ItemRef. 2025-07-13 13:50:01 +00:00
Philipp Krones
4e614bf683 Merge commit 'cdbbf3afda' into clippy-subtree-update 2025-07-10 20:25:36 +02:00
Philipp Krones
9e0f749e08
Merge remote-tracking branch 'upstream/master' into rustup 2025-07-10 20:01:08 +02:00
blyxyas
e0e881f873 Propagate accept-comment-above-attributes to statements
Turns out that things like `#[attr]return unsafe { func(); }` didn't work
because we weren't checking above attributes on statements, only on blocks!
2025-07-06 02:23:50 +02:00
Guillaume Gomez
4793fd1c46 Update clippy source code to make use of TyCtxt::def_descr instead of ItemKind::descr 2025-07-01 17:27:48 +02:00
Philipp Krones
074ccaf3c0 Merge commit 'c5dbd1de07' into clippy-subtree-update 2025-06-27 12:20:57 +02:00
Samuel Tardieu
506411d9d1
Fix collapsible_else_if FP on conditionally compiled stmt (#14906)
Closes rust-lang/rust-clippy#14799

changelog: [`collapsible_else_if`] fix FP on conditionally compiled stmt
2025-06-13 15:45:00 +00:00
yanglsh
fea8dd28a0 Lint more cases in collapsible_else_if 2025-06-13 22:54:59 +08:00
Philipp Krones
cbd683fe31 Merge commit '4ef75291b5' into clippy-subtree-update 2025-06-13 11:24:45 +02:00
relaxcn
8d8b3f16d7 Add new lint: ip_consant 2025-06-03 09:11:20 +00:00
Samuel Tardieu
e236bfc8d7
Add a note to incompatible_msrv to suggest feature gating the MSRV
The first non-MSRV-compatible item located under a `#[cfg(…)]` or
`#[cfg_attr(…)]` attribute will get an additional note suggesting
changing `#[clippy::msrv]` locally.
2025-05-21 17:17:30 +02:00
Philipp Krones
7debaf6b44 Merge commit 'cadf98bb7d' into clippy-subtree-update 2025-05-21 15:15:38 +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
Samuel Tardieu
dcd8bb6d7e
Skip inner ordering checking in presence of #[repr(…)] (#14610)
A representation attribute `#[repr(…)]` might indicate that the ordering
of the fields or the variants is dictated by the API the code is
interfacing with. Better not lint with `arbitrary_source_item_ordering`
in this case.

changelog: [`arbitrary_source_item_ordering`]: do not lint inside items
with `#[repr]` attribute
2025-05-16 19:34:32 +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
Philipp Krones
93bd4d8931 Merge commit '0450db33a5' into clippy-subtree-update 2025-05-15 19:28:39 +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
llogiq
83248e57e9
Fix messages for type_repetition_in_bounds (#14752)
changelog: [`type_repetition_in_bounds`]: include all generic bounds in
suggestion, clearer message which now includes the repeated type name

Fixes rust-lang/rust-clippy#14744
2025-05-12 16:37:11 +00:00
Samuel Tardieu
c6a23f8fbd
Include all bounds in bounds consolidation
Also, include the type name in the lint message, and simplify the span
computation.
2025-05-12 18:32:17 +02:00
Alex Macleod
e4d82aefd9 Resolve through local re-exports in lookup_path 2025-05-09 22:13:35 +00:00
Jason Newcomb
77157f5988 Actually check for a problematic line comment in with_leading_whitespace 2025-05-06 21:42:32 -04: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
Samuel Tardieu
50e0bf1b71
Gate collapsible_if let_chains lints on edition 2024 and MSRV (#14723)
The MSRV being for crates targeting 1.85-1.87 on edition 2024

This enables the lint for regular nightly users without the feature gate
enabled

r? @samueltardieu

Fixes https://github.com/rust-lang/rust-clippy/issues/14678

changelog: none
2025-05-06 05:40:37 +00:00
Alex Macleod
8c93668a71 Gate collapsible_if let_chains lints on edition 2024 and MSRV 2025-05-06 02:23:28 +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
Kaido Aethermai
64880cad75 add test 3, fmt and lint 2025-05-03 15:17:03 -07: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 '0621446356' into clippy-subtree-update 2025-04-22 18:24:43 +02:00
Samuel Tardieu
b3d401ecb1 Add unsafe markers to accomodate edition 2024 rules
- Add `unsafe` blocks inside `unsafe fn` using unsafe constructs
- Add `unsafe` qualifier to `extern` blocks
- Add `unsafe` qualifier to `no_mangle` attributes
2025-04-15 20:33:01 +02:00
Samuel Tardieu
d39600e601 Skip inner ordering checking in presence of #[repr(…)]
A representation attribute `#[repr(…)]` might indicate that the ordering
of the fields or the variants is dictated by the API the code is
interfacing with. Better not lint with `arbitrary_source_item_ordering`
in this case.
2025-04-14 20:24:13 +02:00
Alexey Semenyuk
e1bd4e4b6c arbitrary_source_item_ordering should ignore test modules 2025-04-11 13:42:21 +05:00
Samuel Moelius
dc7d9ec35c Validate paths in disallowed_* configurations 2025-04-01 14:53:48 -04:00
y21
ffaecd008d manually fulfill lint expectations for all unsafe blocks with metavars 2025-03-29 17:55:30 +01:00
Philipp Krones
c2922d1213
Make collapsible_if recognize the let_chains feature (#14481)
Until `if let` chains are stabilized, we do not collapse them together
or with other `if` expressions unless the `let_chains` feature is
enabled. This is the case for example in Clippy sources.

This was made possible by converting the `collapsible_if` to a late lint
to get access to the set of enabled features. This allows this PR to
supersede #14455 and no longer require an additional configuration
option.

The three commits are, in order:
- a conversion of the existing early lint to a late lint, with no new
feature or tests changes
- the addition of the `let_chains` feature detection and action, and
tests
- the application of the enhanced lint to Clippy sources (136 files
modified)

changelog: [`collapsible_if`]: recognize the rust compiler `let_chains`
feature

r? @flip1995
2025-03-28 09:17:24 +00:00
Samuel Tardieu
cd70152470 Make collapsible_if recognize the let_chains feature
Until `if let` chains are stabilized, we do not collapse them together
or with other `if` expressions unless the `let_chains` feature is
enabled. This is the case for example in Clippy sources.
2025-03-27 14:40:44 +01:00
Samuel Tardieu
9b1945d9fb Prevent including preceeding whitespaces if line contains non blanks
This extra condition prevents a problem when removing the '}' in:
```rust
  ( // There was an opening bracket after the parenthesis, which has been removed
    // This is a comment
   })
```
Removing the whitespaces, including the linefeed, before the '}', would put the
closing parenthesis at the end of the `// This is a comment` line, which would
make it part of the comment as well. In this case, it is best to keep the span
on the '}' alone.
2025-03-26 21:10:09 +01:00
Yuri Astrakhan
8e50cfacdf make tests consistent 2025-03-25 10:37:04 -04:00
Yuri Astrakhan
d063e09d10 Move uninlined_format_args to style
This lint was downgraded to `pedantic` in part because rust-analyzer was not fully supporting it at the time per #10087. The support has been added over [a year ago](https://github.com/rust-lang/rust-analyzer/issues/11260), so seems like this should be back to style.

Another source of the initial frustration was fixed since then as well - this lint does not trigger by default in case only some arguments can be inlined.
2025-03-25 10:27:20 -04: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