Commit graph

18931 commits

Author SHA1 Message Date
bors
fdf819df9a Auto merge of #12227 - y21:issue12225, r=Manishearth
[`redundant_locals`]: take by-value closure captures into account

Fixes #12225

The same problem in the linked issue can happen to regular closures too, and conveniently async blocks are closures in the HIR so fixing closures will fix async blocks as well.

changelog: [`redundant_locals`]: avoid linting when redefined variable is captured by-value
2024-02-05 18:37:05 +00:00
bors
005b6c2424 Auto merge of #11919 - y21:manual_c_str_literals, r=xFrednet
new lint: `manual_c_str_literals`

With rust-lang/rust#117472 merged and `c""` syntax stabilized, I think it'd be nice to have a lint for using `CStr::from_ptr` (and similar constructors) with a string literal as an argument.
We can probably also lint `"foo\0".as_ptr()` and suggest `c"foo".as_ptr()`. I might add that to this PR tomorrow if I find the time.

The byte string literal to c string literal rewriting is ugly but oh well.

changelog: new lint: `manual_c_str_literals`
[#11919](https://github.com/rust-lang/rust-clippy/pull/11919)
2024-02-05 18:15:52 +00:00
y21
7f80b449f5 new lint: manual_c_str_literals 2024-02-05 18:51:49 +01:00
y21
6807977153 also check for coroutines 2024-02-05 15:41:59 +01:00
bors
8baeb26754 Auto merge of #12224 - xFrednet:chaneglog-1-76, r=Manishearth
Changelog for Clippy 1.76 🐈

Roses are red,
Violets are blue,
So many cute cats,
How to choose?

---

### The cat of this release is: *Cabrel* submitted by `@daniel-g-gagnon:`

<img height=500 src="https://github.com/rust-lang/rust-clippy/assets/17087237/41aea3dc-7935-4dfe-80ff-a6efd92f76ab" alt="The cats of this Clippy release" />

The cat for the next release can be voted on: [here](https://docs.google.com/forms/d/e/1FAIpQLSfERam31AEi3_5uVsugi1-JHGF9Po1oC7OIiLs8jglprZNy_g/viewform)

The cat for the next next release can be nominated in the comments and will be voted in the next changelog PR (Submission deadline is 2024-02-06 23:59CET)

---

changelog: none
2024-02-05 08:44:34 +00:00
y21
7c3908f86c [redundant_locals]: take by-value closure captures into account 2024-02-04 20:19:27 +01:00
bors
34e4c9fa4a Auto merge of #12087 - marcin-serwin:ref_as_ptr_cast, r=blyxyas
Add new lint: `ref_as_ptr`

Fixes #10130

Added new lint `ref_as_ptr` that checks for conversions from references to pointers and suggests using `std::ptr::from_{ref, mut}` instead.

The name is different than suggested in the issue (`as_ptr_cast`) since there were some other lints with similar names (`ptr_as_ptr`, `borrow_as_ptr`) and I wanted to follow the convention.

Note that this lint conflicts with the `borrow_as_ptr` lint in the sense that it recommends changing `&foo as *const _` to `std::ptr::from_ref(&foo)` instead of `std::ptr::addr_of!(foo)`. Personally, I think the former is more readable and, in contrast to `addr_of` macro, can be also applied to temporaries (cf. #9884).

---

changelog: New lint: [`ref_as_ptr`]
[#12087](https://github.com/rust-lang/rust-clippy/pull/12087)
2024-02-04 17:07:18 +00:00
Marcin Serwin
a3baebcb31
Add ref_as_ptr lint
Author:    Marcin Serwin <marcin.serwin0@protonmail.com>
2024-02-04 17:38:09 +01:00
xFrednet
aa1de4d556
Changelog for Clippy 1.76 🐈 2024-02-04 16:31:01 +01:00
xFrednet
be47e32e9e
Update version attributes for 1.76 lints 2024-02-04 16:18:45 +01:00
bors
9fb41079ca Auto merge of #12219 - sanxiyn:labeled-block, r=blyxyas
Avoid deleting labeled blocks

Fix #11575.

changelog: [`unnecessary_operation`]: skip labeled blocks
2024-02-03 22:48:46 +00:00
Seo Sanghyeon
abced206d7
Avoid deleting labeled blocks 2024-02-03 22:35:14 +01:00
bors
c82162eb71 Auto merge of #11979 - J-ZhengLi:issue11428, r=Alexendoo
add configuration for [`wildcard_imports`] to ignore certain imports

fixes: #11428

changelog: add configuration `ignored-wildcard-imports` for lint [`wildcard_imports`]
2024-02-02 21:28:49 +00:00
bors
9b6f86643f Auto merge of #12217 - PartiallyTyped:12208, r=blyxyas
Fixed FP in `unused_io_amount` for Ok(lit), unrachable! and unwrap de…

…sugar

Fixes fp caused by linting on Ok(_) for all cases outside binding.

We introduce the following rules for match exprs.
- `panic!` and `unreachable!` are treated as consumed.
- `Ok( )` patterns outside `DotDot` and `Wild` are treated as consuming.

changelog: FP [`unused_io_amount`] when matching Ok(literal) or unreachable

fixes #12208

r? `@blyxyas`
2024-02-02 19:43:01 +00:00
J-ZhengLi
46dd8263a0 rename conf option to allowed_wildcard_imports 2024-02-02 09:22:42 +08:00
Quinn Sinclair
fe8c2e24bd Fixed FP in unused_io_amount for Ok(lit), unrachable!
We introduce the following rules for match exprs.
- `panic!` and `unreachable!` are treated as consumption.
- guard expressions in any arm imply consumption.

For match exprs:
- Lint only if exacrtly 2 non-consuming arms exist
- Lint only if one arm is an `Ok(_)` and the other is `Err(_)`

Added additional requirement that for a block return expression
that is a match, the source must be `Normal`.

changelog: FP [`unused_io_amount`] when matching Ok(literal)
2024-02-01 17:05:12 +01:00
bors
b58b88c966 Auto merge of #11832 - Alexendoo:lint-groups-priority, r=flip1995
Add `lint_groups_priority` lint

Warns when a lint group in Cargo.toml's `[lints]` section shares the same priority as a lint. This is in the cargo section but is categorised as `correctness` so it's on by default, it doesn't call `cargo metadata` though and parses the `Cargo.toml` directly

The lint should be temporary until https://github.com/rust-lang/cargo/issues/12918 is resolved, but in the meanwhile this is an common issue to run into

- #11237
- #11751
- #11830

changelog: Add [`lint_groups_priority`] lint

r? `@flip1995`
2024-01-31 19:12:37 +00:00
Alex Macleod
6619e8c27d Add lint_groups_priority lint
Warns when a lint group in Cargo.toml's `[lints]` section shares the
same priority as a lint
2024-01-31 18:33:41 +00:00
J-ZhengLi
314bddee95 add more test cases & improve docs & replace Vec with FxHashSet for segments 2024-01-30 09:38:14 +08:00
J-ZhengLi
d02df12bd5 add configuration for [wildcard_imports] to ignore certain imports 2024-01-30 09:38:14 +08:00
bors
455c07b7cc Auto merge of #12210 - GuillaumeGomez:add-regression-test-2371, r=blyxyas
Add regression ui test for #2371

Fixes #2371.

#2371 seems to already be handled correctly in the lint. This PR adds a ui regression test so we can close it.

r? `@blyxyas`

changelog: Add regression ui test for #2371
2024-01-29 22:06:58 +00:00
bors
1156375e63 Auto merge of #12203 - daivinhtran:fix-clippy-driver-to-accept-param-file, r=flip1995
Makes clippy-driver check for --sysroot in arg files

Fixes https://github.com/rust-lang/rust-clippy/issues/12201

---

changelog: none

cc: `@UebelAndre` `@illicitonion`
2024-01-29 17:01:41 +00:00
Vinh Tran
73706e8358 Makes clippy-driver check for --sysroot in arg files
Fixes https://github.com/rust-lang/rust-clippy/issues/12201
2024-01-29 10:53:05 -05:00
bors
3cd713a9f8 Auto merge of #11370 - modelflat:suggest-relpath-in-redundant-closure-for-method-calls, r=blyxyas
[fix] [`redundant_closure_for_method_calls`] Suggest relative paths for local modules

Fixes #10854.

Currently, `redundant_closure_for_method_calls` suggest incorrect paths when a method defined on a struct within inline mod is referenced (see the description in the aforementioned issue for an example; also see [this playground link](https://play.rust-lang.org/?version=stable&mode=release&edition=2021&gist=f7d3c5b2663c9bd3ab7abdb0bd38ee43) for the current-version output for the test cases added in this PR). It will now try to construct a relative path path to the module and suggest it instead.

changelog: [`redundant_closure_for_method_calls`] Fix incorrect path suggestions for types within local modules
2024-01-29 14:53:54 +00:00
Guillaume Gomez
ce8b4b6ac0 Remove fixed FIXME 2024-01-29 14:54:28 +01:00
Guillaume Gomez
b2f2080942 Add regression test for #2371 2024-01-29 14:53:29 +01:00
modelflat
b3d53774e7 Make redundant_closure_for_method_calls suggest relative paths
Fixes #10854.

Co-authored-by: Alejandra González <blyxyas@gmail.com>
2024-01-29 12:34:59 +01:00
bors
e7a3cb7ab0 Auto merge of #12021 - PartiallyTyped:11982, r=flip1995
FP: `needless_return_with_question_mark` with implicit Error Conversion

Return with a question mark was triggered in situations where the `?` desuraging was performing error conversion via `Into`/`From`.

The desugared `?` produces a match over an expression with type `std::ops::ControlFlow<B,C>` with `B:Result<Infallible, E:Error>` and `C:Result<_, E':Error>`, and the arms perform the conversion. The patch adds another check in the lint that checks that `E == E'`. If `E == E'`, then the `?` is indeed unnecessary.

changelog: False Positive: [`needless_return_with_question_mark`] when implicit Error Conversion occurs.

fixes: #11982
2024-01-29 09:10:02 +00:00
Quinn Sinclair
3aa2c279c8 rewrote to match only Result::err cons 2024-01-28 22:43:40 +01:00
bors
8ccf6a61ee Auto merge of #12084 - yuxqiu:manual_retain, r=Alexendoo
fix: incorrect suggestions generated by `manual_retain` lint

fixes #10393, fixes #11457, fixes #12081

#10393: In the current implementation of `manual_retain`, if the argument to the closure is matched using tuple, they are all treated as the result of a call to `map.into_iter().filter(<f>)`. However, such tuple pattern matching can also occur in many different containers that stores tuples internally. The correct approach is to apply different lint policies depending on whether the receiver of `into_iter` is a map or not.

#11457 and #12081: In the current implementation of `manual_retain`, if the argument to the closure is `Binding`, the closure will be used directly in the `retain` method, which will result in incorrect suggestion because the first argument to the `retain` closure may be of a different type. In addition, if the argument to the closure is `Ref + Binding`, the lint will simply remove the `Ref` part and use the `Binding` part as the argument to the new closure, which will lead to bad suggestion for the same reason. The correct approach is to detect each of these cases and apply lint suggestions conservatively.

changelog: [`manual_retain`] refactor and add check for various patterns
2024-01-27 18:20:06 +00:00
bors
276ce3936b Auto merge of #12083 - cocodery:fix/issue11932, r=Alexendoo
Fix/Issue11932: assert* in multi-condition after unrolling will cause lint `nonminimal_bool` emit warning

fixes [Issue#11932](https://github.com/rust-lang/rust-clippy/issues/11932)

After `assert`, `assert_eq`, `assert_ne`, etc, assert family marcos unrolling in multi-condition expressions, lint `nonminimal_bool` will recognize whole expression as a entirety, analyze each simple condition expr of them, and check whether can simplify them.

But `assert` itself is a entirety to programmers, we don't need to lint on `assert`. This commit add check whether lint snippet contains `assert` when try to warning to an expression.

changelog: [`nonminimal_bool`] add check for condition expression
2024-01-27 17:44:24 +00:00
bors
18e1f25a9f Auto merge of #12206 - y21:issue12205, r=Alexendoo
[`never_loop`]: recognize desugared `try` blocks

Fixes #12205

The old code assumed that only blocks with an explicit label can be jumped to (using `break`). This is mostly correct except for `try` desugaring, where the `?` operator is rewritten to a `break` to that block, even without a label on the block. `Block::targeted_by_break` is a little more accurate than just checking if a block has a label in that regard, so we should just use that instead

changelog: [`never_loop`]: avoid linting when `?` is used inside of a try block
2024-01-27 17:27:38 +00:00
y21
ff5afac616 [never_loop]: recognize ? desugaring in try blocks 2024-01-27 17:07:10 +01:00
bors
85e08cd3b9 Auto merge of #12169 - GuillaumeGomez:unnecessary_result_map_or_else, r=llogiq
Add new `unnecessary_result_map_or_else` lint

Fixes https://github.com/rust-lang/rust-clippy/issues/7328.

r? `@llogiq`

changelog: Add new `unnecessary_result_map_or_else` lint
2024-01-27 12:42:18 +00:00
bors
79f10cf364 Auto merge of #12122 - andrewbanchich:tostring-impl, r=llogiq
add to_string_trait_impl lint

closes #12076

changelog: [`to_string_trait_impl`]: add lint for direct `ToString` implementations
2024-01-27 12:31:18 +00:00
bors
855aa08de5 Auto merge of #12178 - mdm:modulo-arithmetic-comparison-to-zero, r=llogiq
Don't warn about modulo arithmetic when comparing to zero

closes #12006

By default, don't warn about modulo arithmetic when comparing to zero. This behavior is configurable via `clippy.toml`.

See discussion [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/.E2.9C.94.20Is.20issue.20.2312006.20worth.20implementing.3F)

changelog: [`modulo_arithmetic`]: By default don't lint when comparing the result of a modulo operation to zero.
2024-01-27 12:22:48 +00:00
bors
8905f78832 Auto merge of #12082 - PartiallyTyped:1553, r=dswij
Fixed FP in `redundant_closure_call` when closures are passed to macros

There are cases where the closure call is needed in some macros, this in particular occurs when the closure has parameters. To handle this case, we allow the lint when there are no parameters in the closure, or the closure is outside a macro invocation.

fixes: #11274 #1553
changelog: FP: [`redundant_closure_call`] when closures with parameters are passed in macros.
2024-01-27 09:26:35 +00:00
Andrew Banchich
6d76d14565 add to_string_trait_impl lint 2024-01-26 19:28:54 -05:00
Quinn Sinclair
f58950de86 correct lint case 2024-01-26 23:48:47 +01:00
bors
8de9d8ce99 Auto merge of #12160 - GuillaumeGomez:incompatible-msrv, r=blyxyas
Warn if an item coming from more recent version than MSRV is used

Part of https://github.com/rust-lang/rust-clippy/issues/6324.

~~Currently, the lint is not working for the simple reason that the `stable` attribute is not kept in dependencies. I'll send a PR to rustc to see if they'd be okay with keeping it.~~

EDIT: There was actually a `lookup_stability` function providing this information, so all good now!

cc `@epage`

changelog: create new [`incompatible_msrv`] lint
2024-01-26 13:15:29 +00:00
Guillaume Gomez
14e15206ed Warn if an item coming from more recent version than MSRV is used 2024-01-26 14:13:02 +01:00
bors
ed74c22f33 Auto merge of #12202 - y21:issue12199, r=Jarcho
Avoid linting redundant closure when callee is marked `#[track_caller]`

Fixes #12199

Not sure if there's a nicer way to detect functions marked `#[track_caller]` other than by just looking at its attributes 🤔

changelog: [`redundant_closure`]: [`redundant_closure_for_method_calls`]: avoid linting closures where the function being called is marked `#[track_caller]`
2024-01-26 05:38:39 +00:00
y21
fd3e966bdd avoid linting on #[track_caller] functions in redundant_closure 2024-01-26 00:37:56 +01:00
bors
66c29b973b Auto merge of #12200 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2024-01-25 18:06:39 +00:00
Philipp Krones
c08c756e12
Bump nightly version -> 2024-01-25 2024-01-25 18:39:50 +01:00
Philipp Krones
1534e08250
Merge remote-tracking branch 'upstream/master' into rustup 2024-01-25 18:39:39 +01:00
bors
8a17125dd7 Auto merge of #12184 - michaelciraci:merge-deps, r=llogiq
Consolidating rustc Dependencies

changelog: none

For dependencies in rustc where there are multiple versions used, this moves the older dependency to the newer dependency. These are the updates to clippy as mentioned here: https://github.com/rust-lang/rust/pull/120177
2024-01-25 16:31:26 +00:00
Marc Dominik Migge
e456c28e11 Don't warn about modulo arithmetic when comparing to zero
Add lint configuration for `modulo_arithmetic`

Collect meta-data
2024-01-25 12:42:53 +01:00
bors
900a5aa036 Auto merge of #12180 - y21:conf_lev_distance, r=blyxyas
Suggest existing configuration option if one is found

While working on/testing #12179, I made the mistake of using underscores instead of dashes for the field name in the clippy.toml file and ended up being confused for a few minutes until I found out what's wrong. With this change, clippy will suggest an existing field if there's one that's similar.
```
1 | allow_mixed_uninlined_format_args = true
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: perhaps you meant: `allow-mixed-uninlined-format-args`
```
(in hindsight, the current behavior of printing all the config options makes it obvious in most cases but I still think a suggestion like this would be nice to have)

I had to play around with the value a bit. A max distance of 5 seemed a bit too strong since it'd suggest changing `foobar` to `msrv`, which seemed odd, and 4 seemed just good enough to detect a typo of five underscores.

changelog: when an invalid field in clippy.toml is found, suggest the closest existing one if one is found
2024-01-24 23:13:11 +00:00
y21
4780637cbc
suggest similar config option if one is found 2024-01-25 00:11:43 +01:00