Commit Graph

18458 Commits

Author SHA1 Message Date
Martin Nordholts
512f302fd2 needless_borrows_for_generic_args: Handle when field operand impl Drop
Before this fix, the lint had a false positive, namely when a reference
was taken to a field when the field operand implements a custom Drop.
The compiler will refuse to partially move a type that implements Drop,
because that would put the operand in a weird state. See added
regression test.
2023-12-01 09:14:56 +01:00
bors
57397a5190 Auto merge of #11363 - KisaragiEffective:fix_redundant_closure_call_on_closure_returns_async_block, r=llogiq
[`redundant_closure_call`]: avoid duplicated `async` keyword when triggering on closure that returns `async` block

close #11357

----

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

changelog: [`redundant_closure_call`]: avoid duplicated `async` keyword when triggering on closure that returns `async` block
2023-11-28 20:27:48 +00:00
bors
91c5653a47 Auto merge of #11892 - y21:actually_rename_doc_for_real_this_time, r=Manishearth
rename `DocMarkdown` pass to `Documentation`

Followup of #11801

This was discussed in todays meeting: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Meeting.202023-11-28/near/404667082

Decided to go with `Documentation`, because this would also make it consistent with how `Attributes` is named in `attrs.rs` (and it also sounds good).

changelog: none
2023-11-28 18:59:25 +00:00
y21
0565267f37 rename DocMarkdown to Documentation 2023-11-28 19:14:37 +01:00
bors
e6f33905e8 Auto merge of #11836 - lukaslueg:issue11831, r=Alexendoo
Don't suggest `a.mul_add(b, c)` if parameters are not float

clippy::suboptimal_flops used to not check if the second parameter to f32/f64.mul_add() was float. Since the method is only defined to take `Self` as parameters, the suggestion was wrong.

Fixes #11831

changelog: [`suboptimal_float`]: Don't suggest `a.mul_add(b, c)` if parameters are not f32/f64
2023-11-27 20:37:34 +00:00
bors
003e910760 Auto merge of #11817 - y21:ptr_arg_mut_ref, r=Alexendoo
[`ptr_arg`]: recognize methods that also exist on slices

Fixes #11816

Not a new lint, just a very small improvement to the existing `ptr_arg` lint which would have caught the linked issue.

The problem was that the lint checks if a `Vec`-specific method was called, that is, if the receiver is `Vec<_>`.
This is the case for `len` and `is_empty`, however these methods also exist on slices so we can still lint there.
This logic exists in a different lint, so we can just reuse that here.

Interestingly, there was even a comment up top that explained what it should have been doing, but the logic for it just wasn't there?

changelog: [`ptr_arg`]: recognize methods that also exist on slices

<sub>Also, this is my 100th PR to clippy 🎉 </sub>
2023-11-27 20:26:31 +00:00
bors
caa73941f8 Auto merge of #11879 - samueltardieu:issue-11876, r=Alexendoo
`manual_try_fold`: check that `fold` is really `Iterator::fold`

Fix #11876

changelog: [`manual_try_fold`]: suggest using `try_fold` only for `Iterator::fold` uses
2023-11-27 20:18:40 +00:00
Kisaragi Marine
0426913ca9
fix dogfood 2023-11-28 00:40:13 +09:00
Kisaragi Marine
33182495ac
don't add paren on occurrences that is in call args 2023-11-28 00:27:51 +09:00
Kisaragi Marine
40b6aa0e86
cargo uibless 2023-11-27 23:53:07 +09:00
Kisaragi Marine
1acd8068bd
remove double-paren on test case 2023-11-27 23:50:08 +09:00
Kisaragi Marine
1661e7ee76
re-implement fix for rust-lang#11357 2023-11-27 23:43:39 +09:00
bors
5ba6480f02 Auto merge of #11877 - samueltardieu:doc-fix, r=flip1995
`TypeckResults::node_type()` can be used inside of bodies

Doc fix.

changelog: none
2023-11-27 09:09:17 +00:00
bors
f30a859ae3 Auto merge of #11867 - y21:implied_bounds_in_impls_complexity, r=Jarcho
Move `implied_bounds_in_impls` back to complexity

This lint was originally in the complexity category when I PR'd it. It was then moved to nursery by me due to a number of issues (a false positive, an invalid suggestion and an ICE), but that was probably an overreaction and all of the issues were fixed quickly after.
This is a useful lint imo and there hasn't been any issues with it in a few months, so I say we should give it another try and move it back to complexity.

I did a lintcheck run on the top 400 crates and all of them are legitimate, with 18 warnings. Most of them are from anstyle having a `impl Display + Copy + Clone` return type, or the bitvec crate with a return type like `impl Iterator + DoubleEndedIterator`.

changelog: Move [`implied_bounds_in_impls`] to `complexity` (Now warn-by-default)
[#11867](https://github.com/rust-lang/rust-clippy/pull/11867)
2023-11-26 22:28:13 +00:00
bors
2c56b4f800 Auto merge of #11875 - samueltardieu:fix-11868, r=Jarcho
Fix `box_default` behaviour with empty `vec![]` coming from macro arg

Fix #11868

changelog: [`box_default`]: do not warn on `Box::new(vec![])` if the `vec![]` comes from a macro argument
2023-11-26 22:00:02 +00:00
Samuel Tardieu
0d09cb0a6b manual_try_fold: check that fold is really Iterator::fold 2023-11-26 22:46:13 +01:00
Samuel Tardieu
a7c59aba20 TypeckResults::node_type() can be used inside of bodies 2023-11-26 22:30:16 +01:00
Samuel Tardieu
23d533264f Fix box_default behaviour with empty vec![] coming from macro arg 2023-11-26 18:40:50 +01:00
bors
7af811b6c4 Auto merge of #11870 - Alexendoo:declare-clippy-lint-absolute-path, r=Jarcho
Use absolute path for `declare_tool_lint` in `declare_clippy_lint`

A minor change to hide that implementation detail

changelog: none
2023-11-26 10:21:12 +00:00
Alex Macleod
7093444bfa Use absolute path for declare_tool_lint in declare_clippy_lint 2023-11-25 17:45:27 +00:00
y21
5689a86fb8 move implied_bounds_in_impls to complexity 2023-11-25 13:54:37 +01:00
bors
3664d6328d Auto merge of #11864 - GuillaumeGomez:option_map_or_err_ok, r=flip1995
Create new lint `option_map_or_err_ok`

Fixes #10045.

For the following code:

```rust
let opt = Some(1);
opt.map_or(Err("error"), Ok);
```

It suggests to instead write:

```rust
let opt = Some(1);
opt.ok_or("error");
```

r? `@flip1995`

changelog: Create new lint `option_map_or_err_ok`
2023-11-25 11:35:46 +00:00
bors
fbf13cea16 Auto merge of #11866 - GuillaumeGomez:simplify-code-result_map_or_else_none, r=flip1995
Simplify code for `result_map_or_else_none`

As mentioned in https://github.com/rust-lang/rust-clippy/pull/11864.

r? `@flip1995`

changelog: Simplify code for `result_map_or_else_none`
2023-11-25 11:24:17 +00:00
Guillaume Gomez
148cd04140 Simplify code for result_map_or_else_none 2023-11-25 11:07:59 +01:00
bors
6cfbe57075 Auto merge of #11862 - christophbeberweil:7125-single-element-loop-over-range, r=llogiq
suggest alternatives to iterate an array of ranges

works towards #7125
changelog: [`single_element_loop`]: suggest better syntax when iterating over an array of a single range

`@thinkerdreamer` and myself worked on this issue during a workshop by `@llogiq` at the RustLab 2023 conference. It is our first contribution to clippy.

When iterating over an array of only one element, _which is a range_, our change suggests to replace the array with the contained range itself. Additionally, a hint is printed stating that the user probably intended to iterate over the range and not the array. If the single element in the array is not a range, the previous suggestion in the form of `let {pat_snip} = {prefix}{arg_snip};{block_str}`is used.

This change lints the array with the single range directly, so any prefixes or suffixes are covered as well.
2023-11-24 17:15:33 +00:00
Guillaume Gomez
ef38969e06 Update changelog to add new option_map_or_err_ok lint 2023-11-24 18:14:34 +01:00
Guillaume Gomez
3a3773fa30 Add test for option_map_or_err_ok lint 2023-11-24 18:14:34 +01:00
Guillaume Gomez
ea733172e6 Create new lint option_map_or_err_ok 2023-11-24 18:14:34 +01:00
Christoph Beberweil
f9c6335a0f feat: 7125 code snippets are wrapped in backticks 2023-11-24 17:47:31 +01:00
Christoph Beberweil
bce869f0c0 fix: 7125 lint message should start with a small letter 2023-11-24 17:29:03 +01:00
bors
3e7a63b8d1 Auto merge of #11863 - smoelius:patch-1, r=dswij
Nit re `matches!` formatting

I think formatting `matches!` with `if` guards is [still unsupported](https://github.com/rust-lang/rustfmt/issues/5547), which is probably why this was missed.

changelog: none
2023-11-24 14:58:07 +00:00
bors
e075823e2c Auto merge of #11850 - Nilstrieb:tbd, r=dswij
[`deprecated_semver`]: Allow `#[deprecated(since = "TBD")]`

"TBD" is allowed by rustdoc, saying that it will be deprecated in a future version. rustc will also not actually warn on it.
I found this while checking the rust-lang/rust with clippy.

changelog: [`deprecated_semver`]: allow using `since = "TBD"`
2023-11-24 14:46:50 +00:00
bors
96eab0655f Auto merge of #11859 - y21:issue11856, r=blyxyas
[`missing_asserts_for_indexing`]: work with bodies instead of blocks separately

Fixes #11856

Before this change, this lint would check blocks independently of each other, which means that it misses `assert!()`s from parent blocks.
```rs
// check_block
assert!(x.len() > 1);

{
  // check_block
  // no assert here
  let _ = x[0] + x[1];
}
```

This PR changes it to work with bodies rather than individual blocks. That means that a function will be checked in one go and we can remember if an `assert!` occurred anywhere.

Eventually it would be nice to have a more control flow-aware analysis, possibly by rewriting it as a MIR lint, but that's more complicated and I wanted this fixed first.

changelog: [`missing_asserts_for_indexing`]: accept `assert!`s from parent blocks
2023-11-24 12:18:11 +00:00
Samuel Moelius
4937fba456
Nit re matches! formatting 2023-11-24 07:10:28 -05:00
Christoph Beberweil
2512341fe4 feat: 7125 shorten lint text 2023-11-24 10:38:45 +01:00
Christoph Beberweil
c58d692e1f fix: 7125 update lint applicability to Unspecified 2023-11-24 10:30:19 +01:00
Christoph Beberweil
447edf92b4 suggest alternatives to iterate an array of ranges
Co-authored-by: ThinkerDreamer <74881094+ThinkerDreamer@users.noreply.github.com>
2023-11-23 23:07:36 +01:00
bors
c3243f9942 Auto merge of #11860 - GuillaumeGomez:improve-error-messages, r=flip1995
Improve error messages format

Following review in https://github.com/rust-lang/rust-clippy/pull/11845, since there is already suggestions, no need to add the second part of the sentence every time.

r? `@flip1995`

changelog: Improve some error messages
2023-11-23 21:51:57 +00:00
Guillaume Gomez
6c84b96886 Improve error messages format 2023-11-23 13:32:41 +01:00
bors
840e227bb6 Auto merge of #11845 - GuillaumeGomez:result_map_or_into_option-extension, r=flip1995
Extend `result_map_or_into_option` lint to handle `Result::map_or_else(|_| None, Some)`

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

As indicated in the title, it extends the `result_map_or_into_option` lint to handle `Result::map_or_else(|_| None, Some)`.

changelog: extension of the `result_map_or_into_option` lint to handle `Result::map_or_else(|_| None, Some)`

r? `@blyxyas`
2023-11-23 10:00:06 +00:00
Guillaume Gomez
5d330d08fb Add new test for result_map_or_into_option extension 2023-11-23 10:57:37 +01:00
Guillaume Gomez
2817c5fc14 Extend result_map_or_into_option lint to handle Result::map_or_else(|_| None, Some) 2023-11-23 10:57:37 +01:00
bors
30c743f8a0 Auto merge of #11857 - matthri:add-collect-metadata-note, r=flip1995
Add documentation update hint using `cargo collect-metadata`

This adds a little reminder to update the documentation in the book using `cargo collect-metadata` after changing the lint configuration since this can easily be missed (been there done that 🙈).

> Yeah a note would be good, would be good for us to see if we can make it automatic also

_Originally posted by `@Alexendoo` in https://github.com/rust-lang/rust-clippy/issues/11757#issuecomment-1823474156_

Regarding the automation Im not sure whats the best option here. I thought about a kind of a "semi-automated" way, e.g. a `cargo dev` command which runs the "is the documentation updated" check (and maybe other useful checks) locally and reminds the user of updating the documentation so this gets caught before pushing.

changelog: none
2023-11-23 09:04:46 +00:00
y21
553857bb2b check on a per-body level instead of blocks independently 2023-11-23 09:31:49 +01:00
Matthias Richter
c18e6abdca Add documentation update hint
This adds a hint to update the documentation in the book after changing the lint configuration
2023-11-23 01:38:56 +01:00
bors
c24784ed81 Auto merge of #11757 - matthri:iter-kv-map-msrv-fix, r=Alexendoo
Fix iter_kv_map false positive into_keys and into_values suggestion

fixes: #11752

changelog: [`iter_kv_map`]: fix false positive: Don't suggest `into_keys()` and `into_values()` if the MSRV is to low
2023-11-22 20:39:44 +00:00
Matthias Richter
a20f61b194 add iter_kv_map to msrv config 2023-11-22 15:19:18 +01:00
bors
a72730e9a1 Auto merge of #11844 - GuillaumeGomez:manual_non_exhaustive-rm-underscore-check, r=flip1995
Remove underscore check for `manual_non_exhaustive` lint

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

As indicated in https://github.com/rust-lang/rust-clippy/pull/10559, the underscore check should be removed.

changelog: remove underscore check for `manual_non_exhaustive` lint

r? `@blyxyas`
2023-11-22 13:37:31 +00:00
Guillaume Gomez
91fc4b3001 Remove underscore check for manual_non_exhaustive lint 2023-11-22 13:42:13 +01:00
bors
b21c9d4d31 Auto merge of #11849 - GuillaumeGomez:add-more-transmute_ref_to_ref-tests, r=blyxyas
Add tests for issues #10285, #10286, #10289, #10287

Fixes #10285.
Fixes #10286.
Fixes #10289.
Fixes #10287.

This PR simply adds tests for the listed issues as they're already implemented so we can close them.

r? `@blyxyas`

changelog:none
2023-11-22 11:29:13 +00:00