Commit graph

22127 commits

Author SHA1 Message Date
cerdelen
c7fbcf4c33 Test for Multiple return statements doesnt decrease cognitive complexity 2025-04-11 09:30:28 +02:00
cerdelen
da97004e72 Multiple return statements doesnt decrease cognitive complexity level multiple times 2025-03-24 20:48:49 +01:00
Alex Macleod
b27a2bbe26
Clarify example for unconditional_recursion (#14385)
Clarify example for unconditional_recursion

changelog: none
2025-03-23 13:49:21 +00:00
Philipp Krones
e9aed8764e
set concurrency for the deploy job (#14448)
In the current GitHub Actions CI/CD setup, the `deploy` job is not
triggered when a PR is enqueued in the merge queue but only when it is
merged. Since concurrency is not configured for this job, deployments
may fail for later PRs if multiple PRs are merged in quick succession.
(e.g. the deployment for [this
commit](c418714518)
was successful, but the deployment for [this
commit](0a141ab7b8)
that was pushed to `main` immediately afterward failed. (edit: the
latter deployment seems to be rerun))

changelog: none

r? flip1995
2025-03-23 12:15:07 +00:00
lapla-cogito
3786c07463
remove the notation of the deploy job 2025-03-23 21:09:28 +09:00
lapla-cogito
d8dff61275
set concurrency for the deploy job 2025-03-23 21:08:41 +09:00
Philipp Krones
07e7414fb1
fix: nonminimal_bool wrongly showed the macro definition (#14424)
Closes #14404

changelog: [`nonminimal_bool`]: fix macro definition wrongly showed in
suggestions.
2025-03-23 11:19:41 +00:00
Philipp Krones
cad9083d71
Lint more cases in collapsible_if (#14231)
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, allows opting out from this behavior.

If reviewed on GitHub, the second commit of this PR is best looked at
side by side, with whitespace differences turned off.

changelog: [`collapsible_if`]: lint more cases
2025-03-23 11:17:46 +00:00
alexey semenyuk
63e7815390 Fix example for unconditional_recursion 2025-03-23 13:28:36 +05:00
Alex Macleod
c033a4c741
Document and improve (a lot) lintcheck --perf (#14194)
In #14116 we added a benchmarking option for Lintcheck, this commit adds
a new chapter to the book AND improves that option into a more usable
state.

It's recommended to review one commit at a time.

- **Document how to benchmark with lintcheck --perf**
- **Several improvements on lintcheck perf (desc.)**

    - Now lintcheck perf deletes target directory after benchmarking,
benchmarking with a cache isn't very useful or telling of any
precise outcome.

    - Support for benchmarking several times without having to do
a cargo clean.

    - Compress perf.data

changelog: none
2025-03-23 00:01:53 +00:00
Alex Macleod
6166f60617
Add ignore_without_reason lint (#13931)
Closes #13066 (tests that are ignored with no reason message).

changelog: Add `ignore_without_reason` lint
2025-03-22 14:56:43 +00:00
Jason Newcomb
a65cc366f2
Add regression tests for suspicious_doc_comments (#14268)
Related to #14265 which was fixed automatically by the latest rustup.

changelog: none

*Edit: description, changelog, keep only tests*
2025-03-22 14:38:26 +00:00
Jason Newcomb
b41f2e4653
Emit collapsible_match at the right node (#14311)
Fixes https://github.com/rust-lang/rust-clippy/issues/14281

changelog: none
2025-03-22 14:35:24 +00:00
yanglsh
282b61b641 fix: nonminimal_bool wrongly showed the macro definition 2025-03-22 22:20:22 +08:00
Jason Newcomb
d9934328dd
set the applicability of op_ref to MachineApplicable (#14438)
#2597 appears to be already resolved, so the applicability of `op_ref`
can be set to `MachineApplicable`.

close #2597

changelog: [`op_ref`]: set the applicability to `MachineApplicable`
2025-03-22 14:16:52 +00: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
Philipp Krones
e8e0126c18
Add comment annotations (#14414)
Fix missing comment annotations in the clippy book

changelog: none
2025-03-22 13:32:51 +00:00
Philipp Krones
cdf2e7c73c
fix: borrow_deref_ref suggests wrongly when coerce to mut (#14403)
Closes #11346.
Partially fix #9905. The first case in this issue is a little tricky as
the coerce does not happen in the borrowing.

changelog: [`borrow_deref_ref`]: fix wrong suggestions when coerce to
mut
2025-03-22 13:19:42 +00:00
Philipp Krones
37e1b80447
fix: manual_find suggests wrongly when early return (#14405)
Closes #9521

changelog: [`manual_find`]: fix wrong suggestions when early return
2025-03-22 13:16:11 +00:00
Philipp Krones
d5a6688092
Use a lintcheck specific Clippy configuration file in the CI (#14233)
By default, lintcheck will use the `clippy.toml` file found at the
toplevel of the repository (`CARGO_MANIFEST_DIR`). This file is meant
for configuration of Clippy applied to Clippy sources.

This creates a new `lintcheck/ci-config/clippy.toml` file which is used
by the CI when running lintcheck. By default this uses the default
Clippy configuration.

changelog: none
2025-03-22 12:23:32 +00:00
Samuel Moelius
5b234c965d Change category to pedantic 2025-03-21 11:10:49 -04:00
dswij
0a141ab7b8
fix: redundant_clone FP on enum cast (#14395)
Closes #10074

changelog: [`redundant_clone`]: fix FP on enum cast
2025-03-21 14:23:52 +00:00
dswij
c418714518
expand neg_multiply to lint float numbers as well (#14447)
changelog: [`neg_multiply`]: lint float numbers as well
2025-03-21 14:22:17 +00:00
lapla-cogito
da4f5a58a9
expand neg_multiply to lint float numbers as well 2025-03-21 21:20:39 +09:00
Alejandra González
7a92626ec2
fix: filter_map_bool_then suggest wrongly when the closure cannot be decompose directly (#14370)
Closes #11617
Closes #14368

Clippy gives wrong suggestions when the filter and then cannot be put
into closure directly. Since trying to transform these can be too
complicated, Clippy will simply warn but don't try to fix.

changelog: [`filter_map_bool_then`]: fix wrong suggestions when the
closure cannot be decompose directly
2025-03-21 12:09:12 +00:00
Philipp Krones
90f5f559be
rename rust-toolchain to rust-toolchain.toml (#14442)
The configuration of the toolchain using `rust-toolchain` is only
retained for backward compatibility, and it is recommended to explicitly
specify the TOML format, as in `rust-toolchain.toml`.

r? flip1995

(This is because the change affects the sync process, and you are the
one responsible for sync (I believe).)

changelog: none
2025-03-21 10:20:59 +00:00
yanglsh
3f9ecbe341 fix: filter_map_bool_then: suggests wrongly when mut capture in then 2025-03-21 12:55:18 +08:00
yanglsh
721ac284de fix: filter_map_bool_then suggest wrongly when contain return 2025-03-21 12:55:18 +08:00
Samuel Moelius
475d10d3b0 Add test annotation 2025-03-20 21:02:35 -04:00
Samuel Moelius
aadda46752 Add ignore_without_reason lint 2025-03-20 21:02:33 -04:00
lapla-cogito
19c7c46d48
rename rust-toolchain to rust-toolchain.toml 2025-03-21 09:37:59 +09:00
Timo
1e5237f4a5
fix: missing_const_for_fn FP on unstable const traits (#14294)
Closes #14020
Closes #14290
Closes #14091

Add checks for unstable const traits.

changelog: [`missing_const_for_fn`] fix FP on unstable const traits
2025-03-20 20:00:15 +00:00
Philipp Krones
d1d0fee887
Rustup (#14445)
r? @ghost

changelog: none
2025-03-20 19:52:14 +00:00
Philipp Krones
a086879e21
Bump nightly version -> 2025-03-20 2025-03-20 20:47:10 +01:00
Philipp Krones
dc4c77608e
Merge remote-tracking branch 'upstream/master' into rustup 2025-03-20 20:46:36 +01:00
Timo
f2feb0f1a9
make never_loop applicability more flexible (#14203)
The applicability of `never_loop` is currently set to `Unspecified`, but
if the loop block does not contain `break` or `continue`, it can be
`MachineApplicable`.

changelog: [`never_loop`]: the applicability is now `MachineApplicable`
when the loop block contains neither `break` nor `continue`
2025-03-20 15:18:29 +00:00
Timo
221ae5f176
fix suggestion for assignments have enclosing parentheses under needless_late_init (#14169)
fixes #9895

changelog: [`needless_late_init`]: correct suggestion when assignments
have enclosing parentheses
2025-03-19 22:51:38 +00:00
Manish Goregaokar
48ce25ea0e
Add MSRV check for question_mark (#14436)
changelog: [`question_mark`]: Now respects the [`msrv`] configuration
2025-03-19 15:56:45 +00:00
Alejandra González
31497d68fb
fix: option_if_let_else FP when value partially moved (#14209)
fixes #13964

The lint `option_map_unwrap_or` used to have a similar issue in #10579,
so I borrowed its solution to fix this one.

changelog: [`option_if_let_else`]: fix FP when value partially moved
2025-03-19 15:34:53 +00:00
lapla-cogito
a463154bf0
set the applicability of op_ref to MachineApplicable 2025-03-19 21:37:42 +09:00
Jan Verbeek
d793c0abfa Add MSRV check for question_mark 2025-03-19 09:33:58 +01:00
Alex Macleod
a422d9e68c
fix: bad indent in doc comments (#14419)
TLDR
```diff
- ///    01234
+ ///     01234
     12345
```

Sometimes, in doc comments, there are 3 spaces + 1 instead of 4 spaces +
1.
To make it coherent with the rest of the clippy codebase, I `fd -t f -X
sed -E -i 's,///\s{4}(\S),/// \1,g'` and manually verified and fixed the
relevant part of code that had bad indentation.

### Example

```rs
/// fn a() {
///    01234
/// }
```
Becomes
```rs
/// fn a() {
///     01234
/// }
```

changelog: none
2025-03-18 13:59:53 +00:00
Alex Macleod
d443f38f73
Reinstate single_match/single_match_else lints with comments (#14420)
Commit efe3fe9b8c removed the ability for
`single_match` and `single_match_else` to trigger if comments were
present outside of the arms, as those comments would be lost while
rewriting the `match` expression.

This reinstates the lint, but prevents the suggestion from being applied
automatically in the presence of comments by using the `MaybeIncorrect`
applicability. Also, a note is added to the lint message to warn the
user about the need to preserve the comments if acting upon the
suggestion.

changelog: [`single_match`, `single_match_else`]: reinstate lint when
comments are inside the `match` but do not autofix the code

Fix #14418
2025-03-18 12:45:19 +00:00
Alejandra González
ea30a09fe1
Leave assignments for now (#14428)
I love this project but I (again) don't have the time nor energy at the
moment. Will go through my current assignments over time and still
review occasionally.

PS: sorry about the branch on upstream!
changelog: none
2025-03-18 12:29:56 +00:00
Philipp Krones
a07e887e24
Improve string_to_string lint in case it is in a map call (#14396)
Fixes https://github.com/rust-lang/rust-clippy/issues/14175.

There are two "big" cases to handle: `.map(|x| x.to_string())` and
`.map(String::to_string)`. If the closure has more than one expression,
we should not suggest `.cloned()`.

changelog: Improve `string_to_string` lint in case it is in a map call

r? @samueltardieu
2025-03-18 10:29:10 +00:00
Guillaume Gomez
269b913bfd Better handle blocks with just one expression 2025-03-18 11:09:20 +01:00
bors
9932e5e669 Auto merge of #138630 - matthiaskrgr:rollup-kk1gogr, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #138384 (Move `hir::Item::ident` into `hir::ItemKind`.)
 - #138508 (Clarify "owned data" in E0515.md)
 - #138531 (Store test diffs in job summaries and improve analysis formatting)
 - #138533 (Only use `DIST_TRY_BUILD` for try jobs that were not selected explicitly)
 - #138556 (Fix ICE: attempted to remap an already remapped filename)
 - #138608 (rustc_target: Add target feature constraints for LoongArch)
 - #138619 (Flatten `if`s in `rustc_codegen_ssa`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-18 05:58:46 +00:00
Catherine Flores
b057ba4622
Leave assignments for now
I love this project but I (again) don't have the time nor energy at the moment. Will go through my current assignments over time and still review occasionally.
2025-03-17 22:34:44 -05:00
Nicholas Nethercote
6222a735b0 Move hir::Item::ident into hir::ItemKind.
`hir::Item` has an `ident` field.

- It's always non-empty for these item kinds: `ExternCrate`, `Static`,
  `Const`, `Fn`, `Macro`, `Mod`, `TyAlias`, `Enum`, `Struct`, `Union`,
  Trait`, TraitAalis`.

- It's always empty for these item kinds: `ForeignMod`, `GlobalAsm`,
  `Impl`.

- For `Use`, it is non-empty for `UseKind::Single` and empty for
  `UseKind::{Glob,ListStem}`.

All of this is quite non-obvious; the only documentation is a single
comment saying "The name might be a dummy name in case of anonymous
items". Some sites that handle items check for an empty ident, some
don't. This is a very C-like way of doing things, but this is Rust, we
have sum types, we can do this properly and never forget to check for
the exceptional case and never YOLO possibly empty identifiers (or
possibly dummy spans) around and hope that things will work out.

The commit is large but it's mostly obvious plumbing work. Some notable
things.

- A similar transformation makes sense for `ast::Item`, but this is
  already a big change. That can be done later.

- Lots of assertions are added to item lowering to ensure that
  identifiers are empty/non-empty as expected. These will be removable
  when `ast::Item` is done later.

- `ItemKind::Use` doesn't get an `Ident`, but `UseKind::Single` does.

- `lower_use_tree` is significantly simpler. No more confusing `&mut
  Ident` to deal with.

- `ItemKind::ident` is a new method, it returns an `Option<Ident>`. It's
  used with `unwrap` in a few places; sometimes it's hard to tell
  exactly which item kinds might occur. None of these unwraps fail on
  the test suite. It's conceivable that some might fail on alternative
  input. We can deal with those if/when they happen.

- In `trait_path` the `find_map`/`if let` is replaced with a loop, and
  things end up much clearer that way.

- `named_span` no longer checks for an empty name; instead the call site
  now checks for a missing identifier if necessary.

- `maybe_inline_local` doesn't need the `glob` argument, it can be
  computed in-function from the `renamed` argument.

- `arbitrary_source_item_ordering::check_mod` had a big `if` statement
  that was just getting the ident from the item kinds that had one. It
  could be mostly replaced by a single call to the new `ItemKind::ident`
  method.

- `ItemKind` grows from 56 to 64 bytes, but `Item` stays the same size,
  and that's what matters, because `ItemKind` only occurs within `Item`.
2025-03-18 06:29:50 +11:00
Samuel Tardieu
a1bdc191ba Reinstate single_match/single_match_else lints with comments
Commit efe3fe9b8c removed the ability for
`single_match` and `single_match_else` to trigger if comments were
present outside of the arms, as those comments would be lost while
rewriting the `match` expression.

This reinstates the lint, but prevents the suggestion from being applied
automatically in the presence of comments by using the `MaybeIncorrect`
applicability. Also, a note is added to the lint message to warn the
user about the need to preserve the comments if acting upon the
suggestion.
2025-03-17 16:14:14 +01:00