Commit graph

21895 commits

Author SHA1 Message Date
Alejandra González
b583568e72
Add unnecessary_debug_formatting lint (#13893)
Fixes #12674, i.e., adds a lint to flag `Path`s printed with `{:?}`.

Nits are welcome.

changelog: Add `unnecessary_debug_formatting` lint
2025-02-26 15:03:57 +00:00
Alex Macleod
b821f972b6
manual_strip: use existing identifier instead of placeholder (#14188)
When the manually stripped entity receives a name as the first use
through a simple `let` statement, this name can be used in the generated
`if let Some(…)` expression instead of a placeholder.

Fix #14183

changelog: [`manual_strip`]: reuse existing identifier in suggestion
when possible
2025-02-26 14:41:41 +00:00
Samuel Moelius
6af901c51e Add unnecessary_debug_formatting lint
Address review comments

Fix adjacent code

Required now that the lint is pedantic

Add inline formatting tests

Add note re formatting changes

Address `unnecessary_map_or` warnings

Address additional review comments

Typo

Update Clippy version
2025-02-26 14:25:58 +00:00
Alejandra González
162b0e8c4a
Add todo! & unimplemented! to format macros list (#14266)
For some reason, the `todo!` and `unimplemented!` macros were not
included in the list of format-supporting macros list. Since they seem
to behave exactly the same as all others like `write!` and `assert!`,
adding them now.

I wonder if we should delete the `FORMAT_MACRO_DIAG_ITEMS`, and instead
tag all macros with the `#[clippy::format_args]`?

changelog: all format-handling lints will now validate `todo!` and
`unimplemented!` macros.
2025-02-24 22:07:35 +00:00
Alejandra González
0fb004dd56
extend obfuscated_if_else to support {then(), then_some()}.unwrap_or_else() (#14165)
These method chains can be expressed concisely with `if`/`else`.

changelog: [`obfuscated_if_else`]: support `then().unwrap_or_else()` and
`then_some().unwrap_or_else()`
2025-02-24 19:27:56 +00:00
Jason Newcomb
0fa170621d
fix: too_long_first_doc_paragraph suggests wrongly when first line too long (#14276)
Fixes #14274

changelog: [`too_long_first_doc_paragraph`]: fix wrong suggestion when
first line too long
2025-02-24 10:04:01 +00: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
dswij
d92da0fb32
manual_slice_fill: do not initialize from the iterator (#14191)
```rust
let mut tmp = vec![1, 2, 3];
for b in &mut tmp {
    *b = !*b;
}
```

must not suggest the invalid `tmp.fill(!*b)`.

In addition, there is another commit which cleans up two function calls
with no effect.

Fix #14189

changelog: [`manual_slice_fill`]: ensure that the initialization
expression doesn't reference the iterator
2025-02-22 15:28:15 +00:00
Timo
d5488b3b63
useless_asref: add a check for Clone before suggesting the use of .clone() (#14174)
fixes #12357

changelog: [`useless_asref`]: don't suggest to use `.clone()` if the
target type doesn't implement the `Clone` trait
2025-02-22 14:04:57 +00:00
yanglsh
2ad3520d51 fix: too_long_first_doc_paragraph suggests wrongly when first line too long 2025-02-22 19:05:07 +08:00
Fridtjof Stoldt
e479a9ff95
add io_other_error lint (#14022)
fixes #12717.

r? @xFrednet

----

changelog: add [`io_other_error`] lint
2025-02-21 21:53:48 +00:00
Andre Bogus
6366cca439 add io_other_error lint 2025-02-21 22:08:31 +01:00
lapla-cogito
6c6ffd27a2
extend obfuscated_if_else to support then().unwrap_or_else() and then_some().unwrap_or_else() 2025-02-22 03:22:23 +09:00
Alejandra González
649cef0e81
rename MANUAL_DIV_CEIL MSRV alias and add missing conf info for manual_div_ceil (#14263)
- The name of an MSRV alias should describe its functionality, and it is
not appropriate for it to be the same as the name of the lint that uses
it.
- Additionally, while `manual_div_ceil` allows setting MSRV, this is not
correctly reflected in the configuration information.

changelog: none
2025-02-21 18:02:30 +00:00
Timo
1250c26613
Represent the capability instead of the lint name in msrv aliases (#14269)
`INTEGER_BITS` better represents the addition of the `BITS` value on the
primitive integer types.

Inspired by #14263

changelog: none
2025-02-21 08:55:45 +00:00
Samuel Tardieu
4ac7a5361b Represent the capability instead of the lint name in msrv aliases
`INTEGER_BITS` better represents the addition of the `BITS` value on the
primitive integer types.
2025-02-21 09:44:18 +01:00
Yuri Astrakhan
373f809c1d Add todo! & unimplemented! to format macros list
For some reason, the `todo!` and `unimplemented!` macros were not included in the list of format-supporting macros list. Since they seem to behave exactly the same as all others like `write!` and `assert!`, adding them now.
2025-02-20 22:59:05 -05:00
Manish Goregaokar
732e3290de
Remove obsolete comment and simplify code (#14264)
The `IoBufRead` diagnostic has been added during the latest rustup.

changelog: none
2025-02-20 21:38:27 +00:00
Samuel Tardieu
acfbbc65b5 Remove obsolete comment and simplify code
The `IoBufRead` diagnostic has been added during the latest rustup.
2025-02-20 18:03:40 +01:00
Philipp Krones
238edf273d
Rustup (#14262)
r? @ghost

changelog: none
2025-02-20 14:59:15 +00:00
Philipp Krones
e6be02eaf5
Rustup: fix 32bit tests 2025-02-20 15:54:12 +01:00
Timo
bbf65f008d
add owned_cow lint (#13948)
Closes #13697.

---

changelog: add [`owned_cow`] lint
2025-02-20 14:53:45 +00:00
Fridtjof Stoldt
7c889ac449
Changelog for Clippy 1.85 🦜 (#14229)
Roses are red,
Biolets are blue,
A typo happened,
too late now

You might be asking,
what are Biolets now?
And to be honest,
I have no clue

---

The cat of this release is `Vera` nominated by @and-reas-se

<img height=500
src="https://github.com/user-attachments/assets/82e6fccc-1f6d-4d29-b6bb-0bd4f3584593"
alt="The cats of this Clippy release" />

Cats for the next release can be nominated in the comments :D

---

changelog: none
2025-02-20 14:32:01 +00:00
Philipp Krones
934471ce30
Bump nightly version -> 2025-02-20 2025-02-20 15:27:19 +01:00
lapla-cogito
55f32d9259
add missing MSRV configuration information for manual_div_ceil 2025-02-20 23:27:15 +09:00
Philipp Krones
8844a969ca
Bump Clippy version -> 0.1.87 2025-02-20 15:26:51 +01:00
lapla-cogito
3c9a0ab38c
rename the MSRV alias MANUAL_DIV_CEIL to DIV_CEIL 2025-02-20 23:26:51 +09:00
Philipp Krones
12025085b9
Merge remote-tracking branch 'upstream/master' into rustup 2025-02-20 15:26:07 +01:00
Andre Bogus
83f5cbad18 add owned_cow lint 2025-02-19 23:12:46 +01:00
Catherine Flores
d8ecde0e43
fix: map_entry FP on struct member (#14151)
fixes #13934

I modified the part for checking if the map is used so that it can check
field and index exprs.

changelog: [`map_entry`]: fix FP on struct member
2025-02-19 09:07:34 +00:00
Catherine Flores
975a813c5a
.last() to .next_back() requires a mutable receiver (#14140)
In the case where `iter` is a `DoubleEndedIterator`, replacing a call to
`iter.last()` (which consumes `iter`) by `iter.next_back()` (which
requires a mutable reference to `iter`) cannot be done when `iter` is a
non-mutable binding which is not a mutable reference. When possible, a
local immutable binding is made into a mutable one.

Also, the applicability is switched to `MaybeIncorrect` and a note is
added to the output when the element types have a significant drop,
because the drop order will potentially be modified because
`.next_back()` does not consume the iterator nor the elements before the
last one.

Fix #14139

changelog: [`double_ended_iterator_last`]: do not trigger on
non-reference immutable receiver, and warn about possible drop order
change
2025-02-19 09:05:46 +00:00
Philipp Krones
6872e94f11
update rustfix link in docs (#14248)
Since `rustfix` was moved to `@rust-lang/cargo`, the old link may be
confusing for readers.

changelog: none

r? flip1995
2025-02-19 09:02:00 +00:00
Samuel Tardieu
dcd643a652 double_ended_iterator_last: note when drop order is changed
`iter.last()` will drop all elements of `iter` in order, while
`iter.next_back()` will drop the non-last elements of `iter` when
`iter` goes out of scope since `.next_back()` does not consume its
argument.

When the transformation proposed by `double_ended_iterator_last` would
concern an iterator whose element type has a significant drop, a note is
added to warn about the possible drop order change, and the suggestion
is switched from `MachineApplicable` to `MaybeIncorrect`.
2025-02-19 09:26:39 +01:00
yanglsh
e2cdfed0ea fix: map_entry FP on struct member 2025-02-19 16:25:18 +08:00
Alejandra González
48fffe7db3
add a preferred fix for cast_possible_wrap description (#14225)
close #9250

changelog: none
2025-02-18 23:47:57 +00:00
lapla-cogito
939429a8b9
update rustfix link 2025-02-19 05:50:45 +09:00
Alejandra González
f49b4bc165
remove an unneeded #![feature] (#14245)
It seems as if `#![feature(binary_heap_into_iter_sorted)]` is not
required anymore.

changelog: none
2025-02-18 15:02:26 +00:00
Samuel Tardieu
45f7a60d31 .last() to .next_back() requires a mutable receiver
In the case where `iter` is a `DoubleEndedIterator`, replacing a call to
`iter.last()` (which consumes `iter`) by `iter.next_back()` (which
requires a mutable reference to `iter`) cannot be done when `iter`
Is not a mutable binding or a mutable reference.

When `iter` is a local binding, it can be made mutable by fixing its
definition site.
2025-02-18 13:51:01 +01:00
cyrgani
758ec1d332 remove an unneeded #![feature] 2025-02-18 11:04:53 +01:00
Alejandra González
e2d9b9a32a
fix: needless_option_as_deref FP in trait (#14210)
fixes #14148

Another case of #13077 and #8646

changelog: [`needless_option_as_deref`]: fix FP in trait
2025-02-17 23:33:46 +00:00
Nicholas Nethercote
835e6a694b Move methods from Map to TyCtxt, part 2.
Continuing the work started in #136466.

Every method gains a `hir_` prefix, though for the ones that already
have a `par_` or `try_par_` prefix I added the `hir_` after that.
2025-02-18 10:17:44 +11:00
Manish Goregaokar
437014b951
Update mention of ref_to_mut to invalid_reference_casting (#14241)
This lint was renamed in 50da77521e.

While I'm here convert the list of separate lints into a proper list for
ease of use.

changelog: none
2025-02-17 18:11:42 +00:00
Manish Goregaokar
5e4d1660cd
manual_ok_err: blockify the replacement of an else if … (#14240)
If the part being replaced is an `if` expression following an `else`,
the replacement expression must be blockified.

Fix #14239

changelog: [`manual_ok_err`]: fix replacement expression if it follows
an `else`
2025-02-17 18:11:35 +00:00
Tamir Duberstein
01085cb16a
Update mention of ref_to_mut to invalid_reference_casting
This lint was renamed in 50da77521e.

While I'm here convert the list of separate lints into a proper list for
ease of use and clarify which lints are in clippy and which are in rustc.
2025-02-17 10:45:27 -05:00
Samuel Tardieu
66d19d84ae manual_ok_err: blockify the replacement of an else if …
If the part being replaced is an `if` expression following an `else`,
the replacement expression must be blockified.
2025-02-17 15:49:44 +01:00
Fridtjof Stoldt
822e45b186
"Typo Catch Check" passed by @flip1995
This was *totally* intentional to check if this would get caught :P

Co-authored-by: Philipp Krones <hello@philkrones.com>
2025-02-17 11:55:44 +01:00
Philipp Krones
735bed7aa5
Add cargo dev setup toolchain --standalone (#14230)
Allows creating a toolchain that's independent of the local build, for
example to make two separate toolchains with slight differences without
requiring two checkouts of clippy

changelog: none
2025-02-17 10:18:16 +00:00
Philipp Krones
1750411084
Add --allow-no-vcs to cargo dev dogfood --fix (#14227)
Some developers might prefer to use alternate VCS, such as Jujutsu,
which are not detected by `cargo fix`. This forwards the
`--allow-no-vcs` command line argument to `cargo fix`.

changelog: none
2025-02-17 10:13:25 +00:00
Matthias Krüger
42114c9633 Rollup merge of #137101 - GrigorenkoPV:str-inherent-lint, r=Urgau
`invalid_from_utf8[_unchecked]`: also lint inherent methods

Addressing https://github.com/rust-lang/rust/issues/131114#issuecomment-2646663535

Also corrected a typo: "_an_ invalid literal", not "_a_ invalid literal".
2025-02-17 06:37:38 +01:00
Nicholas Nethercote
91481e3bcf Overhaul the intravisit::Map trait.
First of all, note that `Map` has three different relevant meanings.
- The `intravisit::Map` trait.
- The `map::Map` struct.
- The `NestedFilter::Map` associated type.

The `intravisit::Map` trait is impl'd twice.
- For `!`, where the methods are all unreachable.
- For `map::Map`, which gets HIR stuff from the `TyCtxt`.

As part of getting rid of `map::Map`, this commit changes `impl
intravisit::Map for map::Map` to `impl intravisit::Map for TyCtxt`. It's
fairly straightforward except various things are renamed, because the
existing names would no longer have made sense.

- `trait intravisit::Map` becomes `trait intravisit::HirTyCtxt`, so named
  because it gets some HIR stuff from a `TyCtxt`.
- `NestedFilter::Map` assoc type becomes `NestedFilter::MaybeTyCtxt`,
  because it's always `!` or `TyCtxt`.
- `Visitor::nested_visit_map` becomes `Visitor::maybe_tcx`.

I deliberately made the new trait and associated type names different to
avoid the old `type Map: Map` situation, which I found confusing. We now
have `type MaybeTyCtxt: HirTyCtxt`.
2025-02-17 13:21:35 +11:00