Commit graph

8034 commits

Author SHA1 Message Date
Fridtjof Stoldt
f50266a423
Split needless_lifetime '_ suggestions into elidable_lifetime_names (#13960)
Fixes https://github.com/rust-lang/rust-clippy/issues/13514

changelog: Added [`elidable_lifetime_names`] to `pedantic` (Split off
from [`needless_lifetime`] for suggestions with `'_`)
[#13960](https://github.com/rust-lang/rust-clippy/pull/13960)

changelog: Enhancement: [`needless_lifetime`] No longer lints for
elidable lifetimes `'_`, use [`elidable_lifetime_names`] to lint these.
[#13960](https://github.com/rust-lang/rust-clippy/pull/13960)
2025-02-27 09:21:50 +00:00
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
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
Alex Macleod
efcf1f5730 Split needless_lifetime '_ suggestions into elidable_lifetime_names 2025-02-24 14:23:33 +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
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
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
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
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
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
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
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
Nicholas Nethercote
8cf9eea5b3 Move some Map methods onto TyCtxt.
The end goal is to eliminate `Map` altogether.

I added a `hir_` prefix to all of them, that seemed simplest. The
exceptions are `module_items` which became `hir_module_free_items` because
there was already a `hir_module_items`, and `items` which became
`hir_free_items` for consistency with `hir_module_free_items`.
2025-02-17 13:21:02 +11:00
Alex Macleod
0f20a12ad4
ui_test annotation cleanup (#14232)
Cleans up some changes from
https://github.com/rust-lang/rust-clippy/pull/11421

I searched for any `.stderr` files where the number of errors changed
and reverted + manually added the annotations for them

Also fixes `tests/ui/asm_syntax_not_x86.rs`

r? @flip1995

changelog: none
2025-02-16 17:00:23 +00:00
Alex Macleod
d03ae8ba6b ui_test annotation cleanup 2025-02-16 16:51:35 +00:00
lapla-cogito
fd17bfe57d
add manual_contains lint 2025-02-16 06:21:57 +09:00
lapla-cogito
91548d0fe3
prevent useless_asref from suggesting .clone() on types without the Clone trait 2025-02-16 05:59:53 +09:00
Samuel Tardieu
01d7a324dc manual_strip: use existing identifier instead of placeholder
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.
2025-02-15 16:03:11 +01:00
Samuel Tardieu
44aa75fd2a manual_slice_fill: initializer must not reference the iterator
```rust
let mut tmp = vec![1, 2, 3];
for b in &mut tmp {
    *b = !*b;
}
```

must not suggest the invalid `tmp.fill(!*b)`.
2025-02-15 15:56:41 +01:00
Guillaume Gomez
847bd6707d f 2025-02-15 15:41:30 +01:00
Guillaume Gomez
2c0c661e56 Better handle 32bit/64bit-specific ui tests 2025-02-15 15:40:12 +01:00
Guillaume Gomez
8ae4e7f76d Fix tests/ui/transmute_32bit.rs annotations 2025-02-15 15:03:54 +01:00
Samuel Tardieu
0fcc2dba92 Fix 32 bits tests 2025-02-15 14:51:48 +01:00
Guillaume Gomez
cc915cced8 Add missing ui annotations to new ui tests 2025-02-15 13:44:26 +01:00
Guillaume Gomez
a2c890fa0f Make fmt (weirdly) happy 2025-02-15 13:38:43 +01:00
Guillaume Gomez
1f94d55a18 Fix new tests updates 2025-02-15 13:38:42 +01:00
Guillaume Gomez
8a2dae63c3 Make if_let_mutex test pass on both 2021 and 2024 editions 2025-02-15 13:38:18 +01:00
Guillaume Gomez
d5ebe50505 Add manual annotations 2025-02-15 13:38:18 +01:00
Guillaume Gomez
0a990758fb Handle compilation error in builtin_type_shadow.rs 2025-02-15 13:38:18 +01:00
Guillaume Gomez
10184ecbe1 Allowed clippy::tests/ui/attrs.2.fixed in tests/ui/attr.rs because when adding annotations, it doesn't work anymore 2025-02-15 13:38:18 +01:00
Guillaume Gomez
f666fd6417 Update UI tests 2025-02-15 13:38:16 +01:00
Jason Newcomb
0dd5c4ddeb
Fix used_underscore_items lint uses of foreign functions (#14205)
Fixed #14156

changelog: none
2025-02-15 02:46:49 +00:00
Jason Newcomb
4e899e16f9
unnecessary_map_or: do not consume the comparison value if it does not implement Copy (#14207)
Fix #14201

changelog: [`unnecessary_map_or`]: do not consume the comparison value
if it does not implement `Copy`
2025-02-15 02:45:59 +00:00
Catherine Flores
50ecb6e846
doc_link_code: add check for links with code spans that render weird (#14121)
This is the lint described at
https://github.com/rust-lang/rust/pull/136308#issuecomment-2625485331
that recommends using HTML to nest links inside code.

changelog: [`doc_link_code`]: warn when a link with code and a code span
are back-to-back
2025-02-14 13:55:33 +00:00
Michael Goulet
fc532c5b32 Trim suggestion parts to the subset that is purely additive 2025-02-14 00:44:10 -08:00
Timo
b83762c578
Fix literal_string_with_formatting_args lint emitted when it should not (#13953)
Fixes #13885.
Fixes https://github.com/rust-lang/rust-clippy/issues/14007.

Problem was that I forgot to check whether or not the `span` was a
"real" one. Because if not, then it starts pointing to pretty much only
wrong content, hence the problems we saw with clippy linting on
`clippy.toml`.

changelog: Fix `literal_string_with_formatting_args` lint emitted when
it should not

r? @samueltardieu
2025-02-13 16:18:44 +00:00
Samuel Tardieu
f826193aec unnecessary_map_or: do not consume the non-Copy comparison value 2025-02-13 12:00:38 +01:00
yanglsh
c47746ca67 fix: needless_option_as_deref FP in trait 2025-02-13 15:26:11 +08:00