Commit graph

22107 commits

Author SHA1 Message Date
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
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
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
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
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
Heshan Padmasiri
5d7e55cc11 Mention about .fixed files 2025-03-17 17:55:26 +05:30
yanglsh
a3865b1a3d fix: option_if_let_else FP when value partially moved 2025-03-17 14:36:29 +08:00
Alejandra González
4800557857
question_mark: avoid incorrect suggestion when ref binding used (#14158)
changelog: [`question_mark`]: avoid incorrect suggestion when `ref`
binding used

Fixes #13417
2025-03-16 23:25:26 +00:00
Nicholas Nethercote
2b431f768b Fix is_relevant_impl.
It determines if a function should have any `inline` attributes checked.
For `ItemKind::Fn` it returns true or false depending on the details of
the function; for anything other item kind it returns *true*. This
latter case should instead be *false*. (In the nearby and similar
functions `is_relevant_impl` and `is_relevant_trait` the non-function
cases return false.)

The effect of this is that non-functions are no longer checked. But
rustc already disallows `inline` on any non-function items. So if
anything its a tiny performance win, because that was useless anyway.
2025-03-17 08:20:56 +11:00
tk
b23fcb0147 fix: bad indent in doc comments
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),///     \1,g'` and manually verified and fixed the relevant part of code that had bad indentation.
2025-03-16 19:36:09 +01:00
Michael Goulet
9eab078065 Suppress must_use in compiler and tools 2025-03-16 17:47:57 +00:00
Alex Macleod
775a5c2712
fix incorrect suggestions related to parentheses in needless_return (#14094)
close #12157

`needless_return` sometimes makes incorrect suggestions by omitting
necessary enclosing parentheses. This PR resolves the issue by using
`clippy_utils::sugg::Sugg`.

changelog: [`needless_return`]: now makes correct suggestions which
require enclosing parentheses
2025-03-16 15:03:14 +00:00
Fridtjof Stoldt
1617a2e519
Remove @xFrednet from docs 👋 (#14415)
Cleaning up the last few loose ends. To everyone reading this: I hope
you have a beautiful day!

changelog: none

r? @ghost
2025-03-16 14:52:51 +00:00
Fridtjof Stoldt
3c7dfacf44
new lint: doc_comment_double_space_linebreaks (#12876)
Fixes https://github.com/rust-lang/rust-clippy/issues/12163

I decided to initially make this a restriction lint because it felt a
bit niche and opinionated to be a warn-by-default style lint. It may be
appropriate as a style lint if the standard or convention *is* to use
`\` as doc comment linebreaks - not sure if they are!

The wording on the help message could be improved, as well as the name
of the lint itself since it's a bit wordy - suggestions welcome.

This lint works on both `///` and `//!` doc comments.

changelog: new lint: `doc_comment_double_space_linebreaks`
2025-03-16 14:44:02 +00:00
xFrednet
9845b100ec
Remove @xFrednet from docs 👋 2025-03-16 15:19:49 +01:00
Heshan Padmasiri
ae3216e702 Add comment annotations 2025-03-16 18:52:35 +05:30
Michael Howell
4e9caa3985 question_mark: suggest as_ref/as_mut if ref binding is used 2025-03-15 15:59:24 -07:00
bors
f3579934b1 Auto merge of #138464 - compiler-errors:less-type-ir, r=lcnr
Use `rustc_type_ir` directly less in the codebase

cc https://github.com/rust-lang/rust/issues/138449

This is a somewhat opinionated bundle of changes that will make working on https://github.com/rust-lang/rust/issues/138449 more easy, since it cuts out the bulk of the changes that would be necessitated by the lint. Namely:

1. Fold `rustc_middle::ty::fold` and `rustc_middle::ty::visit` into `rustc_middle::ty`. This is because we already reexport some parts of these modules into `rustc_middle::ty`, and there's really no benefit from namespacing away the rest of these modules's functionality given how important folding and visiting is to the type layer.
2. Rename `{Decodable,Encodable}_Generic` to `{Decodable,Encodable}_NoContext`[^why], change it to be "perfect derive" (`synstructure::AddBounds::Fields`), use it throughout `rustc_type_ir` instead of `TyEncodable`/`TyDecodable`.
3. Make `TyEncodable` and `TyDecodable` derives use `::rustc_middle::ty::codec::TyEncoder` (etc) for its generated paths, and move the `rustc_type_ir::codec` module back to `rustc_middle::ty::codec` 🎉.
4. Stop using `rustc_type_ir` in crates that aren't "fundamental" to the type system, namely middle/infer/trait-selection. This amounted mostly to changing imports from `use rustc_type_ir::...` to `use rustc_middle::ty::...`, but also this means that we can't glob import `TyKind::*` since the reexport into `rustc_middle::ty::TyKind` is a type alias. Instead, use the prefixed variants like `ty::Str` everywhere -- IMO this is a good change, since it makes it more regularized with most of the rest of the compiler.

[^why]: `_NoContext` is the name for derive macros with no additional generic bounds and which do "perfect derive" by generating bounds based on field types. See `HashStable_NoContext`.

I'm happy to cut out some of these changes into separate PRs to make landing it a bit easier, though I don't expect to have much trouble with bitrot.

r? lcnr
2025-03-15 08:36:38 +00:00
Michael Goulet
f96eb611f8 Fold visit into ty 2025-03-15 06:34:36 +00:00
Alex Macleod
5c031d1f6a
Fix from_over_into lint suggesting invalid code (#14409)
fixes [#112502](https://github.com/rust-lang/rust/issues/112502)

changelog: [`from_over_into`]: fix invalid code suggestion when self
parameter has type annotation
2025-03-15 01:31:30 +00:00
KonaeAkira
9c897a20ae Simplify implementation 2025-03-15 00:37:44 +01:00