Commit graph

616 commits

Author SHA1 Message Date
Timo
e8185ec091
Extend implicit_clone to handle to_string calls (#14177)
Put another way, merge `string_to_string` into `implicit_clone`, as
suggested here:
https://github.com/rust-lang/rust-clippy/issues/14173#issuecomment-2645846915

Note: [I
wrote](b8913894a1)
this comment:
6cdb7f68c3/clippy_lints/src/methods/implicit_clone.rs (L43-L45)

Here is the context for why I wrote it:
https://github.com/rust-lang/rust-clippy/pull/7978#discussion_r769128853

Regardless, it's probably time for the comment to go away. Extending
`implicit_clone` to handle `to_string` calls yields many hits within
Clippy's codebase.

changelog: extend `implicit_clone` to handle `to_string` calls
2025-08-02 11:41:00 +00:00
Samuel Tardieu
ba8da7a8e8
useless_conversion: move all the impl to the same lint pass (#15274)
Needed to split the lints crate.

changelog: none
2025-07-14 22:33:14 +00:00
Jason Newcomb
7796773d3e useless_conversion: move all the impl to the same lint pass 2025-07-14 12:05:07 -04:00
Jason Newcomb
d9acd919ad
fix false negative of expect_used (#15253)
Fixes: rust-lang/rust-clippy#15247

changelog: Fix the false negative of [`expect_used`] when metting
`Option::ok().expect`.
2025-07-14 07:52:48 +00:00
Krishna Ketan Rai
b4fc33ae8b Lint: Improve manual_is_variant_and to support equality comparison
- Add equality pattern support to manual_is_variant_and
- Update documentation and Clippy manual
2025-07-13 19:51:45 +05:30
relaxcn
1d1b97d514 fix false negative of expect_used 2025-07-12 01:44:55 +08:00
nekename
982abc48b3
docs: make unbuffered_bytes docs more consistent 2025-06-08 18:37:39 +01:00
llogiq
6ef2a2d177
add new lint: ip_constant (#14878)
Closes: rust-lang/rust-clippy#14819

changelog: new lint: [`ip_constant`]
2025-06-05 19:36:33 +00:00
relaxcn
8d8b3f16d7 Add new lint: ip_consant 2025-06-03 09:11:20 +00:00
Ethan Brierley
e34368b48d
Improve wording of manual_contains docs
This is mainly to avoid the phrase "more fast" since that is not idiomatic English
2025-05-29 22:15:01 +01:00
Guillaume Gomez
763a7bd148 Extend manual_is_variant_and lint to check for boolean map comparisons 2025-05-27 12:15:44 +02:00
Samuel Moelius
8c6eea85a1 Extend implicit_clone to handle to_string calls 2025-05-19 19:29:04 -04:00
Samuel Tardieu
e16801e68c
Use symbols instead of &str when possible 2025-05-19 22:47:57 +02:00
Philipp Krones
2ce5451850
Changelog for Clippy 1.87 🦡 (#14748)
Violets are red,
Roses are blue,
It’s wrong on purpose —
We don’t break tradition.

<hr>

This is cat-penguin of this release [nominated
by](https://github.com/rust-lang/rust-clippy/pull/12224#issuecomment-1927555104)
@xFrednet some time ago:

![image](https://github.com/user-attachments/assets/49bd7783-9d56-4a15-b026-1c7e799ea7ba)

Cats for the next release can be traditionally nominated in the comments
:D
Please be more active and cat-minded 😻

<hr>

changelog: none

r? flip1995
2025-05-12 10:00:01 +00:00
Alexey Semenyuk
55b5c835c5 Changelog for Clippy 1.87 2025-05-12 14:50:27 +05:00
Jason Newcomb
ca78fb4031
unwrap_used, expect_used: accept macro result as receiver (#14575)
changelog: [`unwrap_used`, `expect_used`]: lint even when the receiver
is a macro expansion result

This also paves the way for expanding more method call lints to expanded
receivers or arguments.

Fixes rust-lang/rust-clippy#13455
2025-05-07 08:09:47 +00:00
Samuel Tardieu
999db5cdc6 unwrap_used, expect_used: accept macro result as receiver 2025-05-07 10:04:52 +02:00
Alex Macleod
736be8bbb1 Consistently refer to the ? operator 2025-04-24 13:40:57 +00:00
Timo
ac88357f83
New lint: swap_with_temporary (#14046)
This lint detects inefficient or useless `{std,core}::mem::swap()` calls
such as:

```rust
    // Should be `a = temp();`
    swap(&mut a, &mut temp());
    // Should be `*b = temp();`
    swap(b, &mut temp());
    // Should be `temp1(); temp2();` if we want to keep the side effects
    swap(&mut temp1(), &mut temp2());
```

It also takes care of using a form appropriate for a `()` context if
`swap()` is part of a larger expression (don't ask me why this wouldn't
happen, I have no idea), by suggesting `{ x = y; }` (statement in block)
or `{std,core}::mem::drop((temp1(), temp2())`.

changelog: [`swap_with_temporary`]: new lint

Close #1968
2025-04-17 12:42:46 +00:00
Samuel Tardieu
05448bd9c7 New lint: swap_with_temporary 2025-04-17 13:17:43 +02:00
Philipp Krones
a23e8d3537
Update versions of 1.86 lints 2025-04-03 22:20:33 +02:00
Samuel Tardieu
d28d2344d0
correct version attribute for io_other_error (#14282)
r? flip1995

changelog: none
2025-03-31 23:30:39 +00:00
Manish Goregaokar
1e78abca67
expand obfuscated_if_else to support {then(), then_some()}.unwrap_or_default() (#14431)
These method chains can be expressed concisely with `if` / `else`.

changelog: [`obfuscated_if_else`]: support `then().unwrap_or_default()`
and `then_some().unwrap_or_default()`
2025-03-31 16:40:32 +00: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
79c69112dc Apply collapsible_if to Clippy itself
Since Clippy uses the `let_chains` feature, there are many occasions to
collapse `if` and `if let` statements.
2025-03-27 14:40:44 +01:00
dswij
764c1b6d16
remove obsolete "Known Problems" in ok_expect (#14458)
It looks like `ok_expect` already
[checks](b27a2bbe26/clippy_lints/src/methods/ok_expect.rs (L16))
for the presence of the `Debug`.

changelog: none
2025-03-27 06:08:16 +00:00
Samuel Tardieu
9d78426b0d
suggest is_some_and instead of map_or in case_sensitive_file_extension_comparions (#14358)
close #14357

changelog: [`case_sensitive_file_extension_comparisons`]: suggest
`is_some_and` to suppress other lint warnings
2025-03-25 14:47:56 +00:00
lapla-cogito
e78216c4a1
suggest is_some_and instead of map_or in case_sensitive_file_extension_comparions 2025-03-25 21:26:35 +09:00
lapla-cogito
e8c06a71cf
remove obsolete "Known Problems" in ok_expect 2025-03-24 22:27:44 +09:00
Philipp Krones
dc4c77608e
Merge remote-tracking branch 'upstream/master' into rustup 2025-03-20 20:46:36 +01:00
lapla-cogito
22be689b44
extend obfuscated_if_else to support .then().unwrap_or_default() and .then_some().unwrap_or_default() 2025-03-19 16:37:09 +09: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
Nicholas Nethercote
650b7d957b Move methods from Map to TyCtxt, part 4.
Continuing the work from #137350.

Removes the unused methods: `expect_variant`, `expect_field`,
`expect_foreign_item`.

Every method gains a `hir_` prefix.
2025-03-12 08:55:37 +11:00
Philipp Krones
fe01c44995 Merge commit '9f9a822509' into clippy-subtree-update 2025-02-28 23:27:09 +01:00
Alex Macleod
5b0004c45f Migrate clippy_lints to new MSRV API 2025-02-28 18:15:11 +00:00
Philipp Krones
02e812af4d Merge remote-tracking branch 'upstream/master' into rustup 2025-02-27 21:51:42 +01: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
lapla-cogito
f04bfae764
correct version attribute for io_other_error 2025-02-23 11:57:16 +09: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
Nicholas Nethercote
c2d75cff47 Move methods from Map to TyCtxt, part 3.
Continuing the work from #137162.

Every method gains a `hir_` prefix.
2025-02-21 14:31:09 +11:00
Philipp Krones
12025085b9
Merge remote-tracking branch 'upstream/master' into rustup 2025-02-20 15:26:07 +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
lapla-cogito
fd17bfe57d
add manual_contains lint 2025-02-16 06:21:57 +09:00
jonathan
8b6de49ef7
New lint: unbuffered_bytes 2025-02-12 14:57:07 +01:00
Samuel Tardieu
da6a05977d {expect,unwrap}_used: add options to lint at compilation time
By default, do not lint `.unwrap()` and `.expect(…)` in always const
contexts, as a failure would be detected at compile time anyway.

New options `allow_expect_in_consts` and `allow_unwrap_in_consts`,
defaulting to `true`, can be turned unset to still lint in always const
contexts.
2025-02-11 22:14:52 +01:00
Jubilee Young
b18bb0a483 clippy: directly use rustc_abi instead of reexports 2025-02-07 11:21:53 -08:00
dswij
4e5d00a0a7
Deprecate redundant lint option_map_or_err_ok and take manual_ok_or out of pedantic (#14027)
While extending the `option_map_or_err_ok` lint (warn by default,
"style") to recognize η-expanded forms of `Ok`, as in

```rust
    // Should suggest `opt.ok_or("foobar")`
   let _ = opt.map_or(Err("foobar"), |x| Ok(x));
```

I discovered that the `manual_ok_or` lint (allow by default, "pedantic")
already covered exactly the cases handled by `option_map_or_err_ok`,
including the one I was adding. Apparently, `option_map_or_err_ok` was
added without realizing that the lint already existed under the
`manual_ok_or` name. As a matter of fact, artifacts of this second lint
were even present in the first lint `stderr` file and went unnoticed for
more than a year.

This PR:
- deprecates `option_map_or_err_ok` with a message saying to use
`manual_ok_or`
- moves `manual_ok_or` from "pedantic" to "style" (the category in which
`option_map_or_err_ok` was)

In addition, I think that this lint, which is short, machine applicable,
and leads to shorter and clearer code with less arguments (`Ok`
disappears) and the removal of one level of call (`Err(x)` is replaced
by `x`), is a reason by itself to be in "style".

changelog: [`option_map_or_err_ok` and `manual_ok_or`]: move
`manual_ok_or` from "pedantic" to "style", and deprecate the redundant
style lint `option_map_or_err_ok`.
2025-02-07 17:34:21 +00:00
Philipp Krones
5aa9d7ae7f Merge commit '3e3715c312' into clippy-subtree-update 2025-02-06 15:00:24 +01:00
Philipp Krones
f549562b81
Merge remote-tracking branch 'upstream/master' into rustup 2025-02-06 14:31:01 +01:00