Commit Graph

5963 Commits

Author SHA1 Message Date
Oli Scherer
5bd97ac17a Update tests 2023-06-26 14:13:07 +00:00
bors
78e36d9f53 Auto merge of #10996 - Centri3:mem_forget, r=xFrednet
Lint `mem_forget` if any fields are `Drop`

Closes #9298
I think this way of doing it (`needs_drop`) should be fine.

---

changelog: Enhancement: [`mem_forget`]: Now lints on types with fields that implement `Drop`
[#10996](https://github.com/rust-lang/rust-clippy/pull/10996)
2023-06-25 09:40:13 +00:00
Catherine
a5ae9044fb make note less verbose 2023-06-25 04:28:40 -05:00
Renato Lochetti
f0eb40c981
Avoid linting on procedural macros 2023-06-24 19:45:16 -03:00
bors
1b4c423f30 Auto merge of #11021 - y21:issue9493, r=llogiq
[`format_push_string`]: look through `match` and `if` expressions

Closes #9493.

changelog: [`format_push_string`]: look through `match` and `if` expressions
2023-06-24 18:59:58 +00:00
y21
fe856d383f [format_push_string]: look through match, if, if-let 2023-06-24 19:54:12 +02:00
Catherine
db4efe3f6d Don't lint ptr_arg when return type uses Cow's lifetime 2023-06-24 03:26:40 -05:00
bors
ce0a48a9b6 Auto merge of #10994 - y21:issue8772, r=giraffate
[`type_repetition_in_bounds`]: respect MSRV for combining bounds

Fixes #8772.

changelog: [`type_repetition_in_bounds`]: respect msrv for combining `?Sized` bound
2023-06-23 00:31:04 +00:00
bors
6ec23880f2 Auto merge of #10979 - y21:issue9909, r=giraffate
[`get_unwrap`]: include a borrow in the suggestion if argument is not an integer literal

Fixes #9909

I have to say, I don't really understand what the previous logic was trying to do, but this fixes the linked bug.
It was checking if the argument passed to `.get()` can be parsed as a usize (i.e. if it's an integer literal, probably?), and if not, it wouldn't include a borrow? I don't know how we came to that conclusion, but that logic doesn't work:
```rs
let slice = &[1, 2];
let _r: &i32 = slice.get({ 1 }).unwrap();
// previous suggestion: slice[{ 1 }]
// the suggestion should be: &slice[{ 1 }]
```
Here the argument passed to it isn't an integer literal, but it should still include a borrow, because it would otherwise change the type from `&i32` to `i32`.

The exception is that if the parent of the `get().unwrap()` expr is a dereference or a method call or the like, we don't need an explicit borrow because it's automatically inserted by the compiler

changelog: [`get_unwrap`]: include a borrow in the suggestion if argument is not an integer literal
2023-06-21 23:57:02 +00:00
bors
9fa4089410 Auto merge of #10993 - Centri3:iter_nth_zero, r=Manishearth
Don't lint [`iter_nth_zero`] in `next`

Closes #9820
This also *slightlyy* modifies the output of `iter_nth`, as I noticed the types' names weren't in backticks

changelog: [`iter_nth_zero`]: No longer lints in implementations of `Iterator::next`
2023-06-21 22:06:12 +00:00
Centri3
242807a9c1 Don't lint iter_nth_zero in next 2023-06-21 15:58:52 -05:00
Catherine
b6f194b48c move to drop_forget_ref 2023-06-21 15:56:24 -05:00
bors
b3fd7b8120 Auto merge of #10948 - Centri3:borrow_as_ptr, r=dswij
[`borrow_as_ptr`]: Ignore temporaries

Fixes #9884

changelog: [`borrow_as_ptr`]: Ignore temporaries
2023-06-21 17:07:52 +00:00
y21
3122e3d78f use let chains, move assignments out of block, add tests 2023-06-21 09:04:40 +02:00
Catherine
3b89984b56 add WebAssembly to test 2023-06-20 21:19:58 -05:00
Catherine
d8d59965f1 Lint mem_forget if fields are Drop 2023-06-20 13:37:03 -05:00
y21
87c28b9463 [type_repetition_in_bounds]: respect msrv for combining maybe bounds 2023-06-20 17:24:46 +02:00
bors
62972ae2dd Auto merge of #10952 - Centri3:excessive_precision, r=dswij
Don't lint `excessive_precision` on inf

Fixes #9910

changelog: [`excessive_precision`]: No longer lints overflowing literals
2023-06-20 14:56:21 +00:00
bors
5da6174318 Auto merge of #10990 - y21:issue8634-partial, r=blyxyas,xFrednet
[`single_match`]: don't lint if block contains comments

Fixes #8634

It now ignores matches with a comment in the "else" arm

changelog: [`single_match`]: don't lint if block contains comments
2023-06-20 13:57:19 +00:00
bors
1919dff4ee Auto merge of #10989 - ericmarkmartin:use-placeref-abstraction, r=Manishearth
Use placeref abstraction

rust-lang/rust#80647 suggests refactoring certain patterns with MIR places to use higher-level abstractions provided by the [`Place`](https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/mir/struct.Place.html)/[`PlaceRef`](https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/mir/struct.PlaceRef.html). While working on that issue, I found a couple candidates for such refactoring in clippy.

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: none
2023-06-20 04:43:38 +00:00
bors
5b60388e5a Auto merge of #10930 - y21:issue9956, r=blyxyas,xFrednet
[`redundant_closure_call`]: handle nested closures

Fixes #9956.

This ended up being a much larger change than I'd thought, and I ended up having to pretty much rewrite it as a late lint pass, because it needs access to certain things that I don't think are available in early lint passes (e.g. getting the parent expr). I think this'll be required to fi-x #10922 anyway, so this is probably fine.
(edit: had to write "fi-x" because "fix" makes github think that this PR fixes it, which it doesn't 😅 )

Previously, it would suggest changing `(|| || 42)()()` to `|| 42()`, which is a type error (it needs parens: `(|| 42)()`). In my opinion, though, the suggested fix should have really been `42`, so that's what this PR changes.

changelog: [`redundant_closure_call`]: handle nested closures and rewrite as a late lint pass
2023-06-19 20:30:35 +00:00
bors
c8c03ea606 Auto merge of #10793 - c410-f3r:bbbbbbbbbbb, r=xFrednet
[`arithmetic_side_effects`] Fix #10792

Fix #10792

```
changelog: [`arithmetic_side_effects`]: Retrieve field values of structures that are in constant environments
```
2023-06-19 19:51:49 +00:00
y21
2e856fa99b add test for block comment and add note to description 2023-06-19 20:07:31 +02:00
bors
ebcbba93ad Auto merge of #10980 - Alexendoo:format-args-incremental-spans, r=dswij
Fix `find_format_arg_expr` when incremental compilation is enabled

Fixes #10969

[`lower_span`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast_lowering/struct.LoweringContext.html#method.lower_span) gives AST spans a [parent](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.SpanData.html#structfield.parent) when lowering to the HIR. That meant the `==` span comparison would return false even though the spans are pointing to the same thing. We now ignore the parent when comparing the spans

Debugging this was quite the puzzle, because the parent is not included in the debug output of `Span`s or `SpanData` 😬

changelog: none
2023-06-19 17:54:57 +00:00
y21
d7e723441e [single_match]: don't lint if block contains comments 2023-06-19 17:18:27 +02:00
Eric Mark Martin
9bc6e114e0 add non-test-case for suggesting const on functions accessing union fields 2023-06-19 03:44:34 -04:00
Centri3
2cd4a9182a Ignore functions annotated with #[test] 2023-06-18 19:32:38 -05:00
Centri3
a8605269bd add test for closures 2023-06-17 20:01:15 -05:00
Centri3
07dbcbda12 new lint single_call_fn 2023-06-17 20:01:06 -05:00
Alex Macleod
26e78e72bc Fix find_format_arg_expr when incremental compilation is enabled 2023-06-17 20:55:30 +00:00
Caio
0e1caa765e Fix #10792 2023-06-17 17:03:31 -03:00
y21
6331c943ff include a ref if argument is not just a numeric literal 2023-06-17 20:48:56 +02:00
bors
8c8ff5f31d Auto merge of #10976 - dswij:issue-10966, r=Alexendoo
Make [`missing_panics_doc`]  not lint for `todo!()`

closes #10966

changelog: [`missing_panics_doc`] now does not lint for `todo!()`
2023-06-17 16:40:39 +00:00
dswij
a6346d7c9d missing_panics_in_doc bless test and add additional macro testcase 2023-06-17 23:21:09 +08:00
Renato Lochetti
e2e6a02445
Addressing reviewer comments 2023-06-17 09:36:38 -03:00
Renato Lochetti
520228b377
Adding configuration to allow safety comment above stmt containing unsafe block 2023-06-17 09:36:36 -03:00
bors
3217f8aeaa Auto merge of #10942 - Centri3:unnecessary_cast, r=llogiq
Ignore more type aliases in `unnecessary_cast`

This is potentially the worst code I've ever written, and even if not, it's very close to being on par with starb. This will ignore `call() as i32` and `local_obtained_from_call as i32` now.

This should fix every reasonable way to reproduce #10555, but likely not entirely.

changelog: Ignore more type aliases in `unnecessary_cast`
2023-06-16 19:24:11 +00:00
bors
43ecf8ea7d Auto merge of #10953 - KisaragiEffective:missing_panics_doc_trigger_on_expect, r=dswij
[`missing_panics_doc`]: pickup expect method

close #10240

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: [`missing_panics_doc`]: pickup expect method
2023-06-16 09:12:46 +00:00
bors
87b5f89497 Auto merge of #10925 - Centri3:needless_clone_impl2, r=xFrednet
add lint [`incorrect_clone_impl_on_copy_type`]

Split off from #10788.

Closes #10700

----

changelog: new lint [`incorrect_clone_impl_on_copy_type`]
[#10925](https://github.com/rust-lang/rust-clippy/pull/10925)
2023-06-16 08:09:18 +00:00
Kisaragi Marine
73cd2cde8b
merge test 2023-06-16 16:37:19 +09:00
bors
ee67c79598 Auto merge of #10835 - y21:drain-collect, r=dswij
new lint: `drain_collect`

Closes #10818.

This adds a new lint that looks for `.drain(..).collect()` and suggests replacing it with `mem::take`.

changelog: [`drain_collect`]: new lint
2023-06-16 04:53:35 +00:00
y21
3fe2478ecf don't unnecessarily walk more in visitor and add more tests 2023-06-15 22:04:25 +02:00
bors
cda13a8b26 Auto merge of #10946 - Centri3:match_same_arms, r=blyxyas,xFrednet
[`match_same_arms`]: don't lint if `non_exhaustive_omitted_patterns`

Fixes #10327

changelog: [`match_same_arms`]: Don't lint if `non_exhaustive_omitted_patterns` is `warn` or `deny`
2023-06-15 18:40:49 +00:00
y21
5821fbbc30 add test case for not whole length, move sugg into variable 2023-06-15 20:23:12 +02:00
y21
d2a6ec2d4d take into account reborrowing when inserting &mut in sugg 2023-06-15 20:23:12 +02:00
y21
2748ab9565 new lint: drain_collect 2023-06-15 20:23:11 +02:00
Centri3
10cc1684ce rename lint and disallow clone_from 2023-06-15 07:04:47 -05:00
Centri3
67d5e6ec39 add lint [needless_clone_impl]
Update needless_impls.rs
2023-06-15 07:04:36 -05:00
Centri3
a899034927 Don't lint excessive_precision on inf 2023-06-15 06:16:04 -05:00
bors
eee3112dc3 Auto merge of #10840 - Alexendoo:from-over-into-expanded-path, r=dswij
from_over_into: Show suggestions for non-Self expanded paths

changelog: [`from_over_into`]: Show suggestions when the body contains macros not expanding to `Self`

Currently any path in a macro expansion causes the suggestion to be hidden, meaning most macro calls cause it to be hidden

Now it's only hidden if the expansion contains `Self`
2023-06-15 07:14:40 +00:00