Commit Graph

20751 Commits

Author SHA1 Message Date
xFrednet
90c19635fd
Make restriction lint's use span_lint_and_then (n -> p) 2024-07-26 09:41:38 +02:00
bors
95ee06c749 Auto merge of #128193 - flip1995:clippy-subtree-update, r=matthiaskrgr
Clippy subtree update

r? `@Manishearth`

Updates Cargo.lock due to the Clippy version update and the ui_test bump to v0.24
2024-07-26 03:36:34 +00:00
bors
533c377950 Auto merge of #12473 - Kobzol:assigning-clones-deref, r=Alexendoo
Fix handling of `Deref` in `assigning_clones`

The `assigning_clones` lint had a special case for producing a bit nicer code for mutable references:
```rust
fn clone_function_lhs_mut_ref(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) {
    *mut_thing = Clone::clone(ref_thing);
}
//v
fn clone_function_lhs_mut_ref(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) {
    Clone::clone_from(mut_thing, ref_thing);
}
```
However, this could [break](https://github.com/rust-lang/rust-clippy/issues/12437) when combined with `Deref`.

This PR removes the special case, so that the generated code should work more generally. Later we can improve the detection of `Deref` and put the special case back in a way that does not break code.

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

r? `@blyxyas`

changelog: [`assigning_clones`]: change applicability to `Unspecified` and fix a problem with `Deref`.
2024-07-25 20:31:29 +00:00
Jakub Beránek
e9852cc7c9
Only apply dereference-removing special case for actual references 2024-07-25 22:20:59 +02:00
bors
062b66d45c Auto merge of #12892 - meithecatte:needless-borrows-mutrefs, r=xFrednet
needless_borrows_for_generic_args: Fix for &mut

This commit fixes a bug introduced in #12706, where the behavior of the lint has been changed, to avoid suggestions that introduce a move. The motivation in the commit message is quite poor (if the detection for significant drops is not sufficient because it's not transitive, the proper fix would be to make it transitive). However, #12454, the linked issue, provides a good reason for the change — if the value being borrowed is bound to a variable, then moving it will only introduce friction into future refactorings.

Thus #12706 changes the logic so that the lint triggers if the value being borrowed is Copy, or is the result of a function call, simplifying the logic to the point where analysing "is this the only use of this value" isn't necessary.

However, said PR also introduces an undocumented carveout, where referents that themselves are mutable references are treated as Copy, to catch some cases that we do want to lint against. However, that is not sound — it's possible to consume a mutable reference by moving it.

To avoid emitting false suggestions, this PR reintroduces the referent_used_exactly_once logic and runs that check for referents that are themselves mutable references.

Thinking about the code shape of &mut x, where x: &mut T, raises the point that while removing the &mut outright won't work, the extra indirection is still undesirable, and perhaps instead we should suggest reborrowing: &mut *x. That, however, is left as possible future work.

Fixes #12856

changelog: none
2024-07-25 18:48:27 +00:00
Bryanskiy
dc49aa3884 Support ?Trait bounds in supertraits and dyn Trait under a feature gate 2024-07-25 20:53:33 +03:00
bors
c7cfe7f5e2 Auto merge of #13156 - y21:for_each_expr_visitor_refactor, r=xFrednet
Remove unnecessary `res` field in `for_each_expr` visitors

Small refactor in the `for_each_expr*` visitors. This should not change anything functionally.

Instead of storing the final value `Option<B>` in the visitor and setting it to `Some` when we get a `ControlFlow::Break(B)` from the closure, we can just directly return it from the visitor itself now that visitors support that.

cc #12829 and https://github.com/rust-lang/rust-clippy/pull/12830#discussion_r1627882827

changelog: none
2024-07-25 17:51:02 +00:00
Lzu Tao
0bc9f003a3 Check for 'static lifetime in return type 2024-07-26 00:27:40 +07:00
Lzu Tao
e53182a2b4 Factor out check_closure function
Also get the receiver T in `T.method(|| f())`.
2024-07-26 00:27:38 +07:00
Lzu Tao
32dc02a6ec Add regression test for issue 13073 2024-07-26 00:23:11 +07:00
Philipp Krones
4e6851e50b Merge commit '37f4fbb92913586b73a35772efd00eccd1cbbe13' into clippy-subtree-update 2024-07-25 18:29:17 +02:00
bors
37f4fbb929 Auto merge of #13157 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2024-07-25 16:25:19 +00:00
Philipp Krones
71b0f0fcac
Bump Clippy version -> 0.1.82 2024-07-25 18:23:37 +02:00
Philipp Krones
09419e44e9
Bump nightly version -> 2024-07-25 2024-07-25 18:23:33 +02:00
Philipp Krones
9f53fc32cf
Merge remote-tracking branch 'upstream/master' into rustup 2024-07-25 18:23:27 +02:00
Matthias Krüger
36214e9838 Rollup merge of #121364 - Urgau:unary_precedence, r=compiler-errors
Implement lint against ambiguous negative literals

This PR implements a lint against ambiguous negative literals with a literal and method calls right after it.

## `ambiguous_negative_literals`

(deny-by-default)

The `ambiguous_negative_literals` lint checks for cases that are confusing between a negative literal and a negation that's not part of the literal.

### Example

```rust,compile_fail
-1i32.abs(); // equals -1, while `(-1i32).abs()` equals 1
```

### Explanation

Method calls take precedence over unary precedence. Setting the precedence explicitly makes the code clearer and avoid potential bugs.

<details>
<summary>Old proposed lint</summary>

## `ambiguous_unary_precedence`

(deny-by-default)

The `ambiguous_unary_precedence` lint checks for use the negative unary operator with a literal and method calls.

### Example

```rust
-1i32.abs(); // equals -1, while `(-1i32).abs()` equals 1
```

### Explanation

Unary operations take precedence on binary operations and method calls take precedence over unary precedence. Setting the precedence explicitly makes the code clearer and avoid potential bugs.

</details>

-----

Note: This is a strip down version of https://github.com/rust-lang/rust/pull/117161, without the binary op precedence.

Fixes https://github.com/rust-lang/rust/issues/117155
`@rustbot` labels +I-lang-nominated
cc `@scottmcm`
r? compiler
2024-07-25 16:48:17 +02:00
y21
de1e163779 get rid of unnecessary res field in for_each_expr visitors 2024-07-25 15:02:31 +02:00
bors
df0cb6c51e Auto merge of #13125 - xFrednet:changelog-1-80, r=dswij
Changelog for Clippy 1.80 🌞

Roses are red,
Violets are blue,
Summer is fun,
So much sun

---

### The cat of this release is *Maunzer* submitted by `@llogiq:`

<img height=500 src="https://github.com/rust-lang/rust-clippy/assets/4200835/a1da6948-446d-4ccf-95a7-c816a8afdc3f" alt="The cats of this Clippy release" />

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

---

changelog: none

I wish everyone reading this a beautiful and happy day =^.^=
2024-07-25 12:48:54 +00:00
bors
be8234098b Auto merge of #13139 - xFrednet:lintcheck-limit-summery-output, r=Alexendoo
Lintcheck: Rework and limit diff output for GH's CI

### Background

While working on https://github.com/rust-lang/rust-clippy/pull/13136 I found an amazing limitation of GH's CI. The summary can at most have be 1MB of text. Here is the warning message:

> $GITHUB_STEP_SUMMARY upload aborted, supports content up to a size of 1024k, got 46731k. For more information see: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-markdown-summary

[The PR](https://github.com/rust-lang/rust-clippy/pull/13136) produced a *casual* 61808 changes. Guess that's why those lints are not *warn-by-default* :P.

### Changes:

This PR limits the lintcheck diff output in two ways.

1. The diff is limited to 200 messages per lint per section. Hidden messages are indicated by a message at the end of the section.
2. The output is first written to a file and only the first 1MB is written to ` >> $GITHUB_STEP_SUMMARY`. The entire file is also written to the normal CI log. This helps for cases where several lints change and the total size exceeds the 1MB limit.

An example of these changes can be seen here: https://github.com/xFrednet/rust-clippy/actions/runs/10028799118?pr=4

---

changelog: none

r? `@Alexendoo`

Sorry for bombarding you with so many PR's lately 😅 Feel free to pass some of you reviews to me.
2024-07-25 12:11:35 +00:00
bors
5e6540f049 Auto merge of #13146 - Alexendoo:cast-lossless-128, r=y21
Lint casts to `u128` in `cast_lossless`

Reverts #12496 per https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Should.20.60as.20u128.60.20trigger.20cast_lossless

Also changes the lint messages and refactors the suggestion production - Fixes #12695

changelog: [`cast_lossless`]: lint casts to `u128`
2024-07-24 21:00:05 +00:00
xFrednet
bdf3e585a3
Lintcheck: Review comments <3 2024-07-24 22:45:41 +02:00
Maja Kądziołka
e63061d75b
Apply review suggestion
Co-authored-by: Fridtjof Stoldt <xFrednet@gmail.com>
2024-07-24 22:29:35 +02:00
Alex Macleod
6d28e1a954 Lint casts to u128 in cast_lossless 2024-07-24 14:32:41 +00:00
bors
16953cef82 Auto merge of #12830 - blyxyas:more-controlflow, r=y21,xFredNet
Use ControlFlow in more places

Now, instead of manually using variables in visitors to signify that a visit is "done" and that the visitor should stop traversing. We use the trait type "Result" to signify this (in relevant places).

I'll schedule a perf run, I don't think it will be much of a difference, but every bit of performance is welcomed :)

changelog: Improve performance, less memory use in visitors

Fixes #12829
r? `@y21`
2024-07-24 09:48:19 +00:00
bors
6d674685ae Auto merge of #127524 - oli-obk:feed_item_attrs2, r=petrochenkov
Make ast `MutVisitor` have the same method name and style as `Visitor`

It doesn't map 100% because some `MutVisitor` methods can filter or even expand to multiple items, but consistency seems nicer.

tracking issue: https://github.com/rust-lang/rust/issues/127615
2024-07-24 09:36:57 +00:00
bors
959477ea36 Auto merge of #13153 - Alexendoo:bind-instead-of-map-struct, r=Manishearth
Make `BindInsteadOfMap` a struct

Makes it codegen once instead of three times

changelog: none
2024-07-24 00:44:30 +00:00
blyxyas
b21a91ae3a Replace local variables signifying "done" or "loop break", use ControlFlow #12830 2024-07-24 01:40:58 +02:00
bors
615284aa5a Auto merge of #13151 - Alexendoo:nextest, r=Jarcho
Fix running compile-test under cargo nextest

`ui_test` itself has `cargo nextest` support which we now use - https://github.com/oli-obk/ui_test/pull/161

It prints `ui_test` as its test name whereas we printed `compile_test`, this ended up being treated as a test name filter causing all the tests to be filtered out

changelog: none
2024-07-23 22:30:02 +00:00
bors
760a278a1f Auto merge of #13154 - blyxyas:focus-on-contribs, r=blyxyas
Temporarily remove myself from reviewer rotation

I'm going to focus on the project goal and my own contributions, this + medical stuff leaves me not enough time to review.

I'll still review any performance related PR, and you can still request from me a benchmark for a PR, and will finish the PRs that I'm still assign to.

changelog: none
2024-07-23 22:21:39 +00:00
blyxyas
5ea7044d72 Temporarily remove myself from reviewer rotation 2024-07-23 23:52:26 +02:00
bors
e91d82eabb Auto merge of #13143 - Alexendoo:transmute-ptr-to-ptr-suggestions, r=y21
Suggest `.cast`/`.cast_const`/`.cast_mut` in `transmute_ptr_as_ptr`

Essentially pre-applies `ptr_as_ptr` - https://github.com/rust-lang/rust-clippy/issues/6372#issuecomment-1830438907

changelog: none
2024-07-23 21:48:07 +00:00
Alex Macleod
493498b65f Make BindInsteadOfMap a struct
Makes it codegen once instead of three times
2024-07-23 20:57:35 +00:00
Alex Macleod
af6d49d97c Fix running compile-test under cargo nextest 2024-07-23 16:15:54 +00:00
bors
bd1224d8aa Auto merge of #13148 - xFrednet:lintcheck-link-correction-again, r=Alexendoo
Lintcheck: Support underscores replacement in URL crate names

The generated URLs use `{krate}` for the crate name. This works well for the first part of the docs.rs domain, but the second part is actually the root module, which requires a replacement of all dashes with underscores. This PR adds `{krate_}` for the root module name.

Diff:

```diff
 Removed `clippy::needless_borrows_for_generic_args` in `rustls-pemfile` at
-https://docs.rs/rustls-pemfile/2.1.2/src/rustls-pemfile/pemfile.rs.html#194
+https://docs.rs/rustls-pemfile/2.1.2/src/rustls_pemfile/pemfile.rs.html#194
```

> Example before: https://github.com/xFrednet/rust-clippy/actions/runs/10054236377?pr=4
> Example after: https://github.com/xFrednet/rust-clippy/actions/runs/10054878594?pr=4

---

changelog: none

r? `@Alexendoo`
2024-07-23 11:51:53 +00:00
Alex Macleod
7010d3c67e Don't suggest .cast_mut/.cast_const for types with erased lifetimes 2024-07-23 11:12:26 +00:00
jusexton
0cdf6e172c Fix while_let_on_iterator dropping loop label when applying fix. 2024-07-23 02:55:58 -05:00
xFrednet
04693a4eca
Lintcheck: Support underscores replacement in URL crate names 2024-07-23 09:46:59 +02:00
bors
df1baedfde Auto merge of #13050 - Jarcho:misc_small, r=xFrednet
Misc refactorings

Various small re-orderings to check the HIR tree or AST before doing other checks. Also includes a small bug fix for `arc_with_small_send_sync` not actually checking for `Arc::new`.

changelog: none
2024-07-22 20:25:05 +00:00
Michael Goulet
e2a7000b6b Get rid of infer_ctxt_ext 2024-07-22 16:15:52 -04:00
bors
f9c240720a Auto merge of #13072 - Jarcho:misc_small5, r=xFrednet
Misc refactorings part 5

`toplevel_ref_arg` gets a small fix so it can be allowed on function arguments. Otherwise just some rearrangements.

changelog: none
2024-07-22 19:58:25 +00:00
bors
637d39fab8 Auto merge of #13065 - Jarcho:misc_small2, r=xFrednet
Misc refactorings part 2

A couple of theses are a bit more involved. No behaviour changes included in this set.

changelog: none
2024-07-22 19:40:50 +00:00
xFrednet
d17f113474
Make restriction lint's use span_lint_and_then (m -> m) 2024-07-22 19:47:34 +02:00
xFrednet
bc8fc6b1d8
Make restriction lint's use span_lint_and_then (i -> l) 2024-07-22 19:47:29 +02:00
Alex Macleod
afe811ad30 Suggest .cast/.cast_const/.cast_mut in transmute_ptr_as_ptr 2024-07-22 17:31:45 +00:00
xFrednet
23b231a5d6
Lintcheck: Fix Errors, because of course 2024-07-22 18:19:37 +02:00
xFrednet
10bf729e3f
Lintcheck: Include truncated diff in CI artifacts 2024-07-22 18:10:03 +02:00
xFrednet
1f879fc0cf
Lintcheck: Minor cleanup and function moves 2024-07-22 18:02:39 +02:00
xFrednet
4fea5199e4
Lintcheck: Order summary by lint and truncate messages 2024-07-22 17:59:26 +02:00
xFrednet
4798383c33
Lintcheck: Limit summary size to 1024k and copy to logs 2024-07-22 17:59:09 +02:00
Oli Scherer
221ac86e09 Always pass the visitor as the first argument to walk* functions 2024-07-22 14:01:24 +00:00