Commit graph

10244 commits

Author SHA1 Message Date
bors
f54275f20f Auto merge of #11509 - mojave2:issue-11502, r=llogiq
fix FP of let_unit_value on async fn args

changelog: [`let_unit_value`]: fix the FalsePostive on async fn arguments

fix #11502
2023-09-16 10:22:33 +00:00
bors
3f9db9025d Auto merge of #11507 - J-ZhengLi:issue11485, r=dswij
trigger [`transmute_null_to_fn`] on chain of casts

fixes: #11485

changelog: trigger [`transmute_null_to_fn`] on chain of casts
2023-09-16 06:19:09 +00:00
bors
59636a2aa3 Auto merge of #11301 - y21:issue11300, r=dswij
[`useless_conversion`]: don't lint if type parameter has unsatisfiable bounds for `.into_iter()` receiver

Fixes #11300.

Before this PR, clippy assumed that if it sees a `f(x.into_iter())` call and the type at that argument position is generic over any `IntoIterator`, then the `.into_iter()` call must be useless because `x` already implements `IntoIterator`, *however* this assumption is not right if the generic parameter has more than just the `IntoIterator` bound (because other traits can be implemented for the IntoIterator target type but not the IntoIterator implementor, as can be seen in the linked issue: `<[i32; 3] as IntoIterator>::IntoIter` satisfies `ExactSizeIterator`, but `[i32; 3]` does not).

So, this PR makes it check that the type parameter only has a single `IntoIterator` bound. It *might* be possible to check if the type of `x` in `f(x.into_iter())` satisfies all the bounds on the generic type parameter as defined on the function (which would allow removing the `.into_iter()` call even with multiple bounds), however I'm not sure how to do that, and the current fix should always work.

**Edit:** This PR has been changed to check if any of the bounds don't hold for the type of the `.into_iter()` receiver, so we can still lint in some cases.

changelog: [`useless_conversion`]: don't lint `.into_iter()` if type parameter has multiple bounds
2023-09-16 06:04:59 +00:00
Jason Newcomb
fed036a57c Fix cycle detection in needless_borrow 2023-09-15 19:13:34 -04:00
y21
981e96008b new lint: path_ends_with_ext 2023-09-15 16:17:51 +02:00
bors
eaf640dcf0 Auto merge of #11506 - mojave2:issue-11503, r=giraffate
fix filter_map_bool_then with a bool reference

changelog: [`filter_map_bool_then`]: Fix the incorrect autofix when the `bool` in question is a reference.

fix #11503
2023-09-15 13:13:16 +00:00
bors
e609279b2c Auto merge of #11484 - mkrasnitski:fix-11302, r=Jarcho
[`extra_unused_type_parameters`]: Fix edge case FP for parameters in where bounds

Generic parameters can end up being used on the left side of where-bounds if they are not directly bound but instead appear nested in some concrete generic type. Therefore, we should walk the left side of where bounds, but only if the bounded type is *not* a generic param, in which case we still need to ignore the bound.

Fixes #11302

changelog: [`extra_unused_type_parameters`]: Fix edge case false positive for parameters in where bounds
2023-09-15 12:59:15 +00:00
bors
21216297e9 Auto merge of #115851 - Alexendoo:clippy-doc-hidden-headers, r=flip1995
Ignore `#[doc(hidden)]` functions in clippy doc lints

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

The implementation before #115689 had a check for unsugared doc comments that also happened to catch `#[doc(hidden)]`, this adds the check back in more explicitly

852bf4e51b/src/tools/clippy/clippy_lints/src/doc.rs (L526-L529)

r? `@flip1995`
2023-09-15 09:55:31 +00:00
bors
2c629cc137 Auto merge of #11504 - Alexendoo:type-lints-closures, r=xFrednet
Ignore closures for some type lints

Fixes #11417

`hir_ty_to_ty` is used in a couple of the `!is_local` lints, which doesn't play nicely inside bodies

changelog: none
2023-09-15 09:34:13 +00:00
mojave2
c81888eab3
fix FP of let_unit_value on async fn args 2023-09-15 15:05:43 +08:00
mojave2
c9b212d5ff
fix filter_map_bool_then with a bool reference 2023-09-15 14:23:58 +08:00
J-ZhengLi
1d76eede99 trigger [transmute_null_to_fn] on chain of casts 2023-09-15 12:24:45 +08:00
Alex Macleod
3c0fc15848 Truncate files when opening in metadata-collector 2023-09-14 22:17:51 +00:00
Alex Macleod
a2a31a0a2f Ignore closures for some type lints 2023-09-14 21:20:50 +00:00
Ralf Jung
1d49cb6118 move required_consts check to general post-mono-check function 2023-09-14 22:30:42 +02:00
bors
9756a13580 Auto merge of #115677 - matthewjasper:let-expr-recovery, r=b-naber
Improve invalid let expression handling

- Move all of the checks for valid let expression positions to parsing.
- Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location.
- Suppress some later errors and MIR construction for invalid let expressions.
- Fix a (drop) scope issue that was also responsible for #104172.

Fixes #104172
Fixes #104868
2023-09-14 19:56:55 +00:00
Alex Macleod
da4244e79c Ignore #[doc(hidden)] functions in clippy doc lints 2023-09-14 17:52:36 +00:00
bors
b27fc10aa8 Auto merge of #11444 - Alexendoo:find-format-args-lifetime-crimes, r=flip1995
Return a value from find_format_args instead of using a callback

r? `@flip1995`

changelog: none
2023-09-14 17:28:51 +00:00
Alex Macleod
c29de92d85 Return a value from find_format_args instead of using a callback 2023-09-14 15:53:32 +00:00
bors
eb545d7568 Auto merge of #115817 - fee1-dead-contrib:fix-codegen, r=oli-obk
treat host effect params as erased in codegen

This fixes the changes brought to codegen tests when effect params are added to libcore, by not attempting to monomorphize functions that get the host param by being `const fn`.

r? `@oli-obk`
2023-09-14 13:42:30 +00:00
Deadbeef
272df70b50 treat host effect params as erased generics in codegen
This fixes the changes brought to codegen tests when effect params are
added to libcore, by not attempting to monomorphize functions that get
the host param by being `const fn`.
2023-09-14 07:34:35 +00:00
mojave2
8d3bbb0964
handle the byref binding in the struct pattern 2023-09-14 14:57:05 +08:00
Ralf Jung
b2d5d68c58 cleanup op_to_const a bit; rename ConstValue::ByRef → Indirect 2023-09-14 07:27:30 +02:00
bors
2009b58df2 Auto merge of #11452 - y21:issue11165, r=Centri3
[`len_without_is_empty`]: follow type alias to find inherent `is_empty` method

Fixes #11165

When we see an `impl B` and `B` is a type alias to some type `A`, then we need to follow the type alias to look for an `is_empty` method on the aliased type `A`. Before this PR, it'd get the inherent impls of `B`, which there aren't any and so it would warn that there isn't an `is_empty` method even if there was one.
Passing the type alias `DefId` to `TyCtxt::type_of` gives us the aliased `DefId` (or simply return the type itself if it wasn't a type alias) so we can just use that

changelog: [`len_without_is_empty`]: follow type alias to find inherent `is_empty` method
2023-09-13 23:46:27 +00:00
bors
0698591527 Auto merge of #115790 - flip1995:clippyup, r=Manishearth
Update Clippy

r? `@Manishearth`
2023-09-13 20:28:02 +00:00
Guillaume Gomez
e3267b1fe7 Fix mutaby used async function argument in closure for needless_pass_by_ref_mut 2023-09-13 15:14:27 +02:00
Ralf Jung
5cd391c4ad make the set of methods between our two Const types more consistent 2023-09-13 07:29:34 +02:00
mojave2
7f870201d3
add byref checking for the guard's local 2023-09-13 11:13:51 +08:00
Philipp Krones
471469d30f Merge commit '98363cbf6a7c3f8b571a7d92a3c645bb4376e4a6' into clippyup 2023-09-12 18:44:06 +02:00
jonboh
f136e1634a new unnecessary_map_on_constructor lint 2023-09-12 17:32:11 +02:00
bors
b643f20f46 Auto merge of #115689 - Alexendoo:clippy-doc-comments, r=notriddle,Manishearth,flip1995
Reuse rustdoc's doc comment handling in Clippy

Moves `source_span_for_markdown_range` and `span_of_attrs` (renamed to `span_of_fragments`) to `rustc_resolve::rustdoc` so it can be used in Clippy

Fixes https://github.com/rust-lang/rust-clippy/issues/10277
Fixes https://github.com/rust-lang/rust-clippy/issues/5593
Fixes https://github.com/rust-lang/rust-clippy/issues/10263
Fixes https://github.com/rust-lang/rust-clippy/issues/2581
2023-09-12 01:45:24 +00:00
Michael Krasnitski
f598bb75d4 Walk the left side of where bounds if the bounded type is not a generic parameter 2023-09-11 21:43:27 -04:00
Matthew Jasper
ab08a3d7b2 Update tools and fulldeps tests 2023-09-11 15:51:19 +00:00
Samuel Tardieu
c548d11041 Auto deref does not apply on union field 2023-09-10 18:15:18 +02:00
bors
8c48b936cc Auto merge of #11459 - y21:issue11435, r=blyxyas
[`implied_bounds_in_impls`]: include (previously omitted) associated types in suggestion

Fixes #11435

It now includes associated types from the implied bound that were omitted in the second bound. Example:
```rs
fn f() -> impl Iterator<Item = u8> + ExactSizeIterator> {..}
```
Suggestion before this change:
```diff
- pub fn my_iter() -> impl Iterator<Item = u32> + ExactSizeIterator {
+ pub fn my_iter() -> impl ExactSizeIterator {
```
It didn't include `<Item = u32>` on `ExactSizeIterator`. Now, with this change, it does.
```diff
- pub fn my_iter() -> impl Iterator<Item = u32> + ExactSizeIterator {
+ pub fn my_iter() -> impl ExactSizeIterator<Item = u32> {
```

We also now extend the span to include not just possible `+` ahead of it, but also behind it (an example for this is in the linked issue as well).
**Note:** The overall diff is a bit noisy, because building up the suggestion involves quite a bit more logic now and I decided to extract that into its own function. For that reason, I split this PR up into two commits. The first commit contains the actual "logic" changes. Second commit just moves code around.

changelog: [`implied_bounds_in_impls`]: include (previously omitted) associated types in suggestion
changelog: [`implied_bounds_in_impls`]: include the `+` behind bound if it's the last bound
2023-09-09 22:51:42 +00:00
bors
ec6f1bd4bf Auto merge of #11358 - Alexendoo:incorrect-to-manual-impls, r=Jarcho
Rename incorrect_impls to non_canonical_impls, move them to warn by default

The wording/category of these feel too strong to me, I would expect most of the time it's linting the implementations aren't going to be *incorrect*, just unnecessary

changelog: rename `incorrect_clone_impl_on_copy_type` to [`non_canonical_clone_impl`]
changelog: rename `incorrect_partial_ord_impl_on_ord_type` to [`non_canonical_partial_ord_impl`]
changelog: Move [`non_canonical_clone_impl`], [`non_canonical_partial_ord_impl`] to suspicious
2023-09-09 11:44:51 +00:00
Alex Macleod
e88a556124 Reuse rustdoc's doc comment handling in Clippy 2023-09-08 23:42:57 +00:00
bors
27165acadf Auto merge of #11456 - tom-anders:std_instead_of_core_suggestion, r=Manishearth
Add suggestions for std_instead_of_core

```
changelog: [`std_instead_of_core`]: add suggestions
```

Fixes #11446
2023-09-08 15:59:00 +00:00
Alex Macleod
b99921a5e8 Rename incorrect_impls to non_canonical_impls, move them to warn by default 2023-09-08 13:15:51 +00:00
John Kåre Alsaker
b5941a2fd5 Partially outline code inside the panic! macro 2023-09-08 14:05:57 +02:00
Philipp Krones
d2b08432db
Merge remote-tracking branch 'upstream/master' into rustup 2023-09-07 21:43:06 +02:00
bors
6150bf5b92 Auto merge of #11462 - Alexendoo:manual-range-patterns-preserve-literals, r=blyxyas
Preserve literals and range kinds in `manual_range_patterns`

Fixes #11461

Also enables linting when there are 3 or fewer alternatives if one of them is already a range pattern

changelog: none
2023-09-07 13:50:16 +00:00
John Kåre Alsaker
0f74faf158 Use Freeze for SourceFile.lines 2023-09-07 13:05:05 +02:00
bors
415ba21c3b Auto merge of #11451 - y21:issue11408, r=xFrednet
[`slow_vector_initialization`]: use the source span of vec![] macro and fix another FP

Fixes #11408

<details>
<summary>Also fixes a FP when the vec initializer comes from a macro other than `vec![]`</summary>

```rs
macro_rules! x {
  () => { vec![] }
}
fn f() {
  let mut v = x!();
  v.resize(10, 0);
}
```
This shouldn't warn. The `x!` macro might be doing other things, so just replacing `x!()` with `vec![0; 10]` is not always an option.
</details>

I added some test cases for macro expansions, however I don't think there's a way to write a test for that specific warning that appeared in the linked issue. As far as I understand, that happens when the rust-src rustup component isn't installed (so the stdlib source is unavailable) and the span points to the `vec![]` *expansion*, instead of the `vec![]` that the user wrote.

changelog: [`slow_vector_initialization`]: use the source span of `vec![]` macro
changelog: [`slow_vector_initialization`]: only warn on `vec![]` expansions and allow other macros
2023-09-07 11:03:01 +00:00
bors
0d36d57c41 Auto merge of #11439 - Alexendoo:disallowed-macros-bins-attrs, r=xFrednet
Check binary operators and attributes in disallowed_macros

changelog: none
2023-09-06 11:36:28 +00:00
y21
30846b16a0 add comments in code to clarify and fix typo 2023-09-05 21:55:08 +02:00
y21
18f36897ef use the correct node args for substitution 2023-09-05 19:08:34 +02:00
Alex Macleod
bbf67c3424 Preserve literals and range kinds in manual_range_patterns 2023-09-05 13:20:37 +00:00
bors
eb0df1d4f4 Auto merge of #11454 - samueltardieu:issue-11403, r=Centri3
Ignore wildcards in function arguments and local bindings

Fix #11403

changelog: none
2023-09-05 12:01:31 +00:00
Samuel Tardieu
2f5c445c0b Ignore wildcards in function arguments and local bindings 2023-09-04 17:18:33 +02:00
y21
cf10690ad4 check that the receiver type satisfies bounds 2023-09-04 16:34:57 +02:00
y21
e34e49f7ff useless_conversion: don't lint if ty param has multiple bounds 2023-09-04 16:20:38 +02:00
bors
bcf856bfb3 Auto merge of #11375 - J-ZhengLi:issue11246, r=Centri3
fix fp when [`undocumented_unsafe_blocks`] not able to detect comment on globally defined const/static variables

fixes: #11246

changelog: fix detection on global variables for [`undocumented_unsafe_blocks`]
2023-09-04 09:47:45 +00:00
bors
da882f0a5a Auto merge of #11455 - digama0:never_loop3, r=Centri3,dswij
skip `todo!()` in  `never_loop`

As promised in #11450, here is an implementation which skips occurrences of the `todo!()` macro.

changelog: [`never_loop`]: skip loops containing `todo!()`
2023-09-04 05:51:47 +00:00
Mario Carneiro
4e0a3465d1 fix vec.rs test, comment 2023-09-04 06:35:51 +02:00
bors
f13e1f429a Auto merge of #11259 - Jarcho:ice_10253, r=dswij
Don't pass extra generic arguments in `needless_borrow`

fixes #10253

Also switches to using `implements_trait` which does ICE when clippy's debug assertions are enabled.

changelog: None
2023-09-04 03:17:50 +00:00
y21
32e25118a6 extract lint emitting into separate fn 2023-09-03 22:53:37 +02:00
y21
7262145964 [implied_bounds_in_impl]: fix suggestion for assoc types 2023-09-03 22:21:03 +02:00
bors
3de0f19c41 Auto merge of #11437 - y21:issue-11422, r=xFrednet
[`implied_bounds_in_impls`]: don't ICE on default generic parameter and move to nursery

Fixes #11422

This fixes two ICEs ([1](https://github.com/rust-lang/rust-clippy/issues/11422#issue-1872351763), [2](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=2901e6febb479d3bd2a74f8a5b8a9305)), and moves it to nursery for now, because this lint needs some improvements in its suggestion (see #11435, for one such example).

changelog: Moved [`implied_bounds_in_impls`] to nursery (Now allow-by-default)
[#11437](https://github.com/rust-lang/rust-clippy/pull/11437)
changelog: [`implied_bounds_in_impls`]: don't ICE on default generic parameter in supertrait clause

r? `@xFrednet` (since you reviewed my PR that added this lint, I figured it might make sense to have you review this as well since you have seen this code before. If you don't want to review this, sorry! Feel free to reroll then)

--------

As for the ICE, it's pretty complicated and very confusing imo, so I'm going to try to explain the idea here (partly for myself, too, because I've confused myself several times writing- and fixing this):
<details>
<summary>Expand</summary>

The general idea behind the lint is that, if we have this function:
```rs
fn f() -> impl PartialEq<i32> + PartialOrd<i32> { 0 }
```
We want to lint the `PartialEq` bound because it's unnecessary. That exact bound is already specified in `PartialOrd<i32>`'s supertrait clause:
```rs
trait PartialOrd<Rhs>: PartialEq<Rhs> {}
//    PartialOrd<i32>: PartialEq<i32>
```

 The way it does this is in two steps:
- Go through all of the bounds in the `impl Trait` return type and collect each of the trait's supertrait bounds into a vec. We also store the generic arguments for later.
  - `PartialEq` has no supertraits, nothing to add.
  - `PartialOrd` is defined as `trait PartialOrd: PartialEq`, so add `PartialEq` to the list, as well as the generic argument(s) `<i32>`

Once we are done, we have these entries in the vec: `[(PartialEq, [i32])]`

- Go through all the bounds again, and looking for those bounds that have their trait `DefId` in the implied bounds vec.
  - `PartialEq` is in that vec. However, that is not enough, because the trait is generic. If the user wrote `impl PartialEq<String> + PartialOrd<i32>`, then `PartialOrd` clearly doesn't imply `PartialEq`. Which means, we also need to check that the generic parameters match. This is why we also collected the generic arguments in `PartialOrd<i32>`. This process of checking generic arguments is pretty complicated and is also where the two ICEs happened.

The way it checks that the generic arguments match is by comparing the generic parameters in the super trait clause:
```rs
trait PartialOrd<Rhs>: PartialEq<Rhs> {}
//                     ^^^^^^^^^^^^^^
```
...this needs to match...
```rs
fn f() -> impl PartialEq<i32> + ...
//             ^^^^^^^^^^^^^^
```
In the compiler, the `Rhs` generic parameter is its own type and we cannot just compare it to `i32`. We need to "substitute" it.
Internally, `Rhs` is represented as `Rhs#1` (the number next to # represents the type parameter index. They start at 0, but 0 is "reserved" for the implicit `Self` generic parameter).

How do we go from `Rhs#1` to `i32`? Well, we know that all the generic parameters had to be substituted in the `impl ... + PartialOrd<i32>` type. So we subtract 1 from the type parameter index, giving us 0 (`Self` is not specified in that list of arguments). We use that as the index into the generic argument list `<i32>`. That's `i32`. Now we know that the supertrait clause looks like `: PartialEq<i32>`.

Then, we can compare that to what the user actually wrote on the bound that we think is being implied: `impl PartialEq<i32> + ...`.

Now to the actual bug: this whole logic doesn't take into account *default* generic parameters. Actually, `PartialOrd` is defined like this:
```rs
trait PartialOrd<Rhs = Self>: PartialEq<Rhs> {}
```
If we now have a function like this:
```rs
fn f() -> impl PartialOrd + PartialEq {}
```
that logic breaks apart... We look at the supertrait predicate `: PartialEq<Rhs>` (`Rhs` is `Rhs#1`), then take the first argument in the generic argument list `PartialEq<..>` to resolve the `Rhs`, but at this point we crash because there *is no* generic argument.
The index 0 is out of bounds. If this happens (and we even get to linting here, which could only happen if it passes typeck), it must mean that that generic parameter has a default type that is not required to be specified.

This PR changes the logic such that if we have a type parameter index that is out of bounds, it looks at the definition of the trait and check that there exists a default type that we can use instead.
So, we see `<Rhs = Self>`, and use `Self` for substitution, and end up with this predicate: `: PartialEq<Self>`. No crash this time.

</details>
2023-09-03 16:09:40 +00:00
Mario Carneiro
1317378b9e fix todo item check, remove unimplemented 2023-09-03 17:16:06 +02:00
Camille GILLOT
d5f0f443b9 Fix clippy. 2023-09-03 15:02:47 +00:00
Camille GILLOT
c3170771f3 Use relative positions inside a SourceFile. 2023-09-03 12:56:10 +00:00
tom-anders
e0014afa2d Add suggestions for std_instead_of_core
Fixes #11446
2023-09-03 14:34:40 +02:00
Mario Carneiro
61a2f972b3 skip todo / unimplemented in never_loop 2023-09-03 01:54:28 -04:00
y21
26c0f97579 [len_without_is_empty]: follow type alias 2023-09-02 22:55:32 +02:00
y21
51206323a1 [slow_vector_initialization]: only warn on vec![] expn 2023-09-02 16:31:17 +02:00
y21
78983d9e3f [slow_vector_initialization]: use the source span of vec![] macro 2023-09-02 15:46:15 +02:00
bors
b9906aca5a Auto merge of #11450 - digama0:never_loop2, r=llogiq
`never_loop` catches `loop { panic!() }`

* Depends on: #11447

This is an outgrowth of #11447 which I felt would best be done as a separate PR because it yields significant new results.

This uses typecheck results to determine divergence, meaning we can now detect cases like `loop { std::process::abort() }` or `loop { panic!() }`. A downside is that `loop { unimplemented!() }` is also being linted, which is arguably a false positive. I'm not really sure how to check this from HIR though, and it seems best to leave this epicycle for a later PR.

changelog: [`never_loop`]: Now lints on `loop { panic!() }` and similar constructs
2023-09-02 12:34:47 +00:00
Mario Carneiro
b3980d8497 catch never loops through diverging functions 2023-09-02 07:51:34 -04:00
Mario Carneiro
39b316db61 an empty match diverges 2023-09-02 07:32:38 -04:00
Ralf Jung
79e31cb80e DefaultUnionRepresentation: explain why we only warn about unions with at least 2 non-ZST fields 2023-09-02 11:36:34 +02:00
Mario Carneiro
68011893d8 Rewrite never_loop as a strict reachability pass
fixes #11004
2023-09-02 03:14:19 -04:00
bors
a8b5245ea3 Auto merge of #11416 - Alexendoo:raw-strings-multipart, r=xFrednet
Use multipart suggestions for raw string lints

Should make it slightly easier to see the suggested edit

Before/after for `needless_raw_string_hashes`:

| Before| After |
|--------|--------|
| ![before](https://github.com/rust-lang/rust-clippy/assets/1830331/da52a436-d890-4594-9191-819c1af946c7) | ![after](https://github.com/rust-lang/rust-clippy/assets/1830331/9731d790-8efa-42a2-b2e9-0ec51398f8f3) |

changelog: none
2023-09-01 22:19:57 +00:00
Alex Macleod
f595f1e0ff Use multipart suggestions for raw string lints 2023-09-01 21:18:51 +00:00
Caio
b3136a874d [clippy] Use symbols intended for arithmetic_side_effects 2023-09-01 10:28:55 +02:00
bors
c1f8ae3a4a Auto merge of #11430 - TDecking:vec-fmt, r=giraffate
Correctly format `vec!` invocations

The [Rust Style Guide](https://doc.rust-lang.org/nightly/style-guide/expressions.html?highlight=vec#array-literals) says that `vec!` should alwys be used with square brackets, not parenthesis. Within the lint documentation, that rule was violated twice.

changelog: none
2023-09-01 00:03:26 +00:00
y21
790922c5d6 update ui tests and some minor cleanups 2023-08-31 18:42:27 +02:00
y21
b54bac9f14 new lint: missing_assert_for_indexing 2023-08-31 17:44:19 +02:00
Alex Macleod
299fbceb96 Check binary operators and attributes in disallowed_macros 2023-08-31 13:14:44 +00:00
bors
77e395e87c Auto merge of #11376 - Jarcho:issue_11366, r=llogiq
Fix span when linting `explicit_auto_deref` immediately after `needless_borrow`

fixes #11366

changelog: `explicit_auto_deref`: Fix span when linting immediately after `needless_borrow`
2023-08-31 11:30:37 +00:00
bors
c50d86fc6a Auto merge of #11418 - Benjscho:explicit_iter_loop_config, r=llogiq
Add config flag for reborrows in explicit_iter_loop

This PR adds a config flag for enforcing explicit into iter lint for reborrowed values. The config flag, `enforce_iter_loop_reborrow`, can be added to clippy.toml files to enable the linting behaviour. By default the reborrow lint is disabled.

fixes: #11074

changelog: [`explicit_iter_loop`]: add config flag `enforce_iter_loop_reborrow` to disable reborrow linting by default
2023-08-31 11:19:04 +00:00
y21
563abf9651 [implied_bounds_in_impls]: move to nursery and fix ICEs 2023-08-30 22:08:05 +02:00
bors
3da21b089f Auto merge of #11396 - y21:issue11345, r=Jarcho
new lint: `iter_out_of_bounds`

Closes #11345

The original idea in the linked issue seemed to be just about arrays afaict, but I extended this to catch some other iterator sources such as `iter::once` or `iter::empty`.

I'm not entirely sure if this name makes a lot of sense now that it's not just about arrays anymore (specifically, not sure if you can call `.take(1)` on an `iter::Empty` to be "out of bounds"?).

changelog: [`iter_out_of_bounds`]: new lint
2023-08-30 19:51:32 +00:00
Tobias Decking
1f8b204775
Second instance of vec! with parenthesis. 2023-08-30 14:02:44 +02:00
Tobias Decking
6eb7a46b88
Documentation Formatting 2023-08-30 13:36:37 +02:00
bors
b97eaab558 Auto merge of #11387 - y21:issue11371, r=blyxyas
[`unnecessary_unwrap`]: lint on `.as_ref().unwrap()`

Closes #11371

This turned out to be a little more code than I originally thought, because the lint also makes sure to not lint if the user tries to mutate the option:
```rs
if option.is_some() {
  option = None;
  option.unwrap(); // don't lint here
}
```
... which means that even if we taught this lint to recognize `.as_mut()`, it would *still* not lint because that would count as a mutation. So we need to allow `.as_mut()` calls but reject other kinds of mutations.
Unfortunately it doesn't look like this is possible with `is_potentially_mutated` (seeing what kind of mutation happened).
This replaces it with a custom little visitor that does basically what it did before, but also allows `.as_mut()`.

changelog: [`unnecessary_unwrap`]: lint on `.as_ref().unwrap()`
2023-08-28 20:29:42 +00:00
bors
5cc5f27899 Auto merge of #11385 - markhuang1212:master, r=blyxyas
skip float_cmp check if lhs is a custom type

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

changelog: [`float_cmp`]: allow float eq comparison when lhs is a custom type that implements PartialEq<f32/f64>

If the lhs of a comparison is not float, it means there is a user implemented PartialEq, and the caller is invoking that custom version of `==`, instead of the default floating point equal comparison.

People may wrap f32 with a struct (say `MyF32`) and implement its PartialEq that will do the `is_close()` check, so that `MyF32` can be compared with either f32 or `MyF32`.
2023-08-28 18:27:53 +00:00
bors
4118738998 Auto merge of #11401 - y21:issue11394, r=xFrednet
[`if_then_some_else_none`]: look into local initializers for early returns

Fixes #11394

As the PR title says, problem was that it only looked for early returns in semi statements. Local variables don't count as such, so it didn't count `let _v = x?;` (or even just `let _ = return;`) as a possible early return and didn't realize that it can't lint then.

Imo the `stmts_contains_early_return` function that was used before is redundant. `contains_return` could already do that if we just made the parameter a bit more generic, just like `for_each_expr`, which can already accept `&[Stmt]`

changelog: [`if_then_some_else_none`]: look into local initializers for early returns
2023-08-28 08:48:35 +00:00
Ben Schofield
be55a96d80 Add config flag for reborrows in explicit_iter_loop
This commit adds a config flag for enforcing explicit into iter lint
for reborrowed values. The config flag, enforce_iter_loop_reborrow, can be
added to clippy.toml files to enable the linting behaviour. By default
the lint is not enabled.
2023-08-27 21:45:14 -06:00
Alex Macleod
1c77b0b267 Move needless_raw_string_hashes to pedantic 2023-08-27 11:43:45 +00:00
bors
8c20739e4d Auto merge of #11411 - smoelius:patch-1, r=Alexendoo
Typo

changelog: none
2023-08-26 11:14:10 +00:00
bors
4736908ff7 Auto merge of #11404 - mojave2:issue-11368, r=matthiaskrgr
fix "derivable_impls: attributes are ignored"

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

changelog: [`derivable_impls`]: allow the lint when the trait-impl methods has any attribute.
2023-08-26 10:19:21 +00:00
Samuel Moelius
7ff87163e0
Typo 2023-08-25 19:50:51 -04:00
y21
f80c55deb5 add a test for statics and doc comments 2023-08-26 01:10:32 +02:00
Meng Huang
e43c234168
allow float_cmp when lhs is a custom type 2023-08-25 19:48:25 +08:00
mojave2
90fcc67d32
fix "derivable_impls: attributes are ignored" 2023-08-25 19:15:44 +08:00
J-ZhengLi
6eec4a3720 remove unecessary code
and narrow search span when const/static items are in a mod block
2023-08-25 15:01:31 +08:00
bors
706c48b62a Auto merge of #11395 - c410-f3r:let-chain, r=Manishearth
[`arithmetic_side_effects`] Fix #11393

Fix #11393

```
changelog: [`arithmetic_side_effects`]: Detect division by zero for `Wrapping` and `Saturating`
```
2023-08-25 01:05:38 +00:00
y21
11072b51fa lint vecs, version bump, more tests 2023-08-25 01:13:35 +02:00
y21
dba7763128 [if_then_some_else_none]: look into local initializers 2023-08-24 23:44:17 +02:00
bors
d65c4595ee Auto merge of #11360 - lengyijun:any_all, r=blyxyas
[`iter_overeager_cloned`]: detect .cloned().all() and .cloned().any()

changelog: [`iter_overeager_cloned`]

r? `@blyxyas`
2023-08-24 19:54:05 +00:00
Philipp Krones
cc61aeea54 Merge commit '080b587854a73f2a8cbaecff1884860a78e2ff37' into clippyup 2023-08-24 21:32:12 +02:00
Philipp Krones
da06825124
Bump Clippy version -> 0.1.74 2023-08-24 21:06:31 +02:00
Philipp Krones
e1ec41b217
Fix dogfood issues 2023-08-24 21:06:18 +02:00
Philipp Krones
ef4d64f1bd
Merge remote-tracking branch 'upstream/master' into rustup 2023-08-24 21:04:57 +02:00
y21
86b6644379 new lint: iter_out_of_bounds 2023-08-24 20:21:55 +02:00
Caio
d802ab28de Dogfood 2023-08-24 13:34:36 -03:00
Caio
2faa43c8b4 [arithmetic_side_effects] Fix #11393 2023-08-24 13:22:27 -03:00
lengyijun
fb6fad20c8 [iter_overeager_cloned]: detect .cloned().all() and .cloned().any() 2023-08-24 08:44:25 +08:00
y21
42c6492ebc [unnecessary_unwrap]: lint on .as_ref().unwrap() 2023-08-23 21:02:01 +02:00
y21
12275713d5 support inherent impls and trait impls 2023-08-23 17:06:55 +02:00
y21
09506f49c1 rename lint, docs, improve diagnostics 2023-08-23 17:06:55 +02:00
y21
2ebff58969 make generics work
fix compile error in doc example
2023-08-23 17:05:55 +02:00
y21
42bd6d7af3 new lint: implied_bounds_in_impl 2023-08-23 17:05:55 +02:00
bors
4932d05733 Auto merge of #11373 - Red-Rapious:master, r=blyxyas,y21
Added new lint: `reserve_after_initialization`

Closes https://github.com/rust-lang/rust-clippy/issues/11330.

A new lint that informs the user about a more concise way to create a vector with a known capacity.
Example:
```rust
let mut v: Vec<usize> = vec![];
v.reserve(10);
```

Produces the following help:
```rust
  |
2 | /     let mut v: Vec<usize> = vec![];
3 | |     v.reserve(10);
  | |__________________^ help: consider using `Vec::with_capacity(space_hint)`: `let v: Vec<usize> = Vec::with_capacity(10);`
  |
```

And can be rewritten as:
```rust
let v: Vec<usize> = Vec::with_capacity(10);
```

changelog: new lint [`reserve_after_initialization`]
2023-08-23 12:06:41 +00:00
Red Rapious
f3c5877302 Put is_from_proc_macro last 2023-08-23 13:46:12 +02:00
Red Rapious
e9a222beb5 Minor changes 2023-08-22 23:41:06 +02:00
Red Rapious
7977d209b2 Do not lint inside macros 2023-08-22 19:36:58 +02:00
Red Rapious
df8bb47f17 Improved snippets and added tests 2023-08-22 18:46:16 +02:00
Igor Aleksanov
e35eb91a33 Fix tuple_array_conversions lint on nightly 2023-08-22 13:15:05 +04:00
Jason Newcomb
82f2e52469 Fix span when linting explicit_auto_deref immediately after needless_borrow 2023-08-21 22:34:32 -04:00
J-ZhengLi
77215672e9 fix [undocumented_unsafe_blocks] not able to detect comment for global vars 2023-08-22 10:27:16 +08:00
Red Rapious
b0bd6219c8 Simplified code and added tests 2023-08-21 23:36:15 +02:00
Red Rapious
a1bf23f0a3 Added more use cases 2023-08-21 22:22:48 +02:00
Red Rapious
073149a7ef Changed documentation example and removed comments 2023-08-21 19:21:02 +02:00
Red Rapious
e33a17e33c Changed Box 2023-08-21 19:05:59 +02:00
Red Rapious
7fbf808a50 Added new lint: reserve_after_initialization 2023-08-21 18:50:53 +02:00
bors
fc1152abf6 Auto merge of #11359 - Alexendoo:unwrap-or-default-check-suggestion, r=dswij
Check that the suggested method exists in unwrap_or_default

Fixes #11355

changelog: none
2023-08-20 15:26:33 +00:00
Alex Macleod
8f2d47ea72 Check that the suggested method exists in unwrap_or_default 2023-08-19 20:22:45 +00:00
lengyijun
e440065a0f [iter_overeager_cloned]: detect .cloned().map() and .cloned().for_each()
key idea:
for `f` in `.map(f)` and `.for_each(f)`:
1. `f` must be a closure with one parameter
2. don't lint if mutable paramter in clsure `f`: `|mut x| ...`
3. don't lint if parameter is moved
2023-08-19 21:18:14 +08:00
y21
e52bd6f850 new lint: should_panic_without_expect 2023-08-18 18:57:14 +02:00
xFrednet
41570c1ee7
Update version attribute for 1.72 lints 2023-08-18 18:27:10 +02:00
bors
1698ce0ba1 Auto merge of #11280 - samueltardieu:issue-11267, r=Centri3
[new_without_default]: include `where` clause in suggestions, make applicable

changelog: [`new_without_default`]: include `where` clause in suggestions
2023-08-18 15:55:40 +00:00
bors
5638860ff8 Auto merge of #11314 - GuillaumeGomez:needless_ref_mut_async_block, r=Centri3
Correctly handle async blocks for NEEDLESS_PASS_BY_REF_MUT

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

The problem was that the `async block`s are popping a closure which we didn't go into, making it miss the mutable access to the variables.

cc `@Centri3`

changelog: none
2023-08-17 18:06:36 +02:00
bors
d068043891 Auto merge of #11070 - y21:issue11065, r=flip1995
[`useless_conversion`]: only lint on paths to fn items and fix FP in macro

Fixes #11065 (which is actually two issues: an ICE and a false positive)

It now makes sure that the function call path points to a function-like item (and not e.g. a `const` like in the linked issue), so that calling `TyCtxt::fn_sig` later in the lint does not ICE (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616836099).
It *also* makes sure that the expression is not part of a macro call (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616919639). ~~I'm not sure if there's a better way to check this other than to walk the parent expr chain and see if any of them are expansions.~~ (edit: it doesn't do this anymore)

changelog: [`useless_conversion`]: fix ICE when call receiver is a non-fn item
changelog: [`useless_conversion`]: don't lint if argument is a macro argument (fixes a FP)

r? `@llogiq` (reviewed #10814, which introduced these issues)
2023-08-17 18:06:36 +02:00
bors
d5298bea7f Auto merge of #11314 - GuillaumeGomez:needless_ref_mut_async_block, r=Centri3
Correctly handle async blocks for NEEDLESS_PASS_BY_REF_MUT

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

The problem was that the `async block`s are popping a closure which we didn't go into, making it miss the mutable access to the variables.

cc `@Centri3`

changelog: none
2023-08-17 15:55:23 +00:00
Guillaume Gomez
5875bd2b5f Use HirId from PlaceWithHirId rather than using the one provided to the function 2023-08-17 17:45:17 +02:00
bors
701e77c87f Auto merge of #11070 - y21:issue11065, r=flip1995
[`useless_conversion`]: only lint on paths to fn items and fix FP in macro

Fixes #11065 (which is actually two issues: an ICE and a false positive)

It now makes sure that the function call path points to a function-like item (and not e.g. a `const` like in the linked issue), so that calling `TyCtxt::fn_sig` later in the lint does not ICE (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616836099).
It *also* makes sure that the expression is not part of a macro call (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616919639). ~~I'm not sure if there's a better way to check this other than to walk the parent expr chain and see if any of them are expansions.~~ (edit: it doesn't do this anymore)

changelog: [`useless_conversion`]: fix ICE when call receiver is a non-fn item
changelog: [`useless_conversion`]: don't lint if argument is a macro argument (fixes a FP)

r? `@llogiq` (reviewed #10814, which introduced these issues)
2023-08-17 14:41:46 +00:00
J-ZhengLi
aa8995e589 allow calling to_owned with borrowed value for [implicit_clone] 2023-08-15 09:41:15 +08:00
Esteban Küber
89fdc3e383 Move scrutinee HirId into MatchSource::TryDesugar 2023-08-14 21:43:56 +00:00
y21
f47165c703 find expansions more efficiently 2023-08-14 16:50:31 +02:00
y21
2820d980cb [useless_conversion]: fix FP in macro and add test 2023-08-14 16:28:04 +02:00
y21
34348f72f4 [useless_conversion]: make sure path points to fn-like item 2023-08-14 16:28:04 +02:00
lengyijun
fc061890d6 [iter_overeager_cloned]: detect .cloned().filter() and .cloned().find()
Key idea:
```
// before
iter.cloned().filter(|x| unimplemented!() )
// after
iter.filter(|&x| unimplemented!() ).cloned()

// before
iter.cloned().filter( foo )
// after
iter.filter(|&x| foo(x) ).cloned()
```
2023-08-14 09:13:01 +08:00
unvalley
d5dbee4aa0 feat: update manual_retain to lint binary_heap_retain
refactor: rename variable

chore: reorder

test: update naming for msrv
2023-08-13 17:09:39 +09:00
Samuel Tardieu
f9b22e7b84 [new_without_default]: make the suggestion machine-applicable
Now that generics and lifetimes are output as expected, the lint
should be applicable.
2023-08-11 21:16:56 +02:00
Samuel Tardieu
621e76d252 [new_without_default]: include where clauses in suggestion
Fix #11267
2023-08-11 21:10:18 +02:00
Philipp Krones
f730a2655a Merge commit '1e8fdf492808a25d78a97e1242b835ace9924e4d' into clippyup 2023-08-11 14:05:13 +02:00
bors
1e8fdf4928 Auto merge of #11320 - max-niederman:redundant_locals_shadow_mutated, r=Alexendoo
redundant_locals: fix FPs on mutated shadows

Fixes #11290.

When a mutable binding is shadowed by
a mutable binding of the same name in a different scope, mutations in that scope have different meaning.
This PR fixes spurious `redundant_locals` emissions on such locals.

cc `@Centri3,` `@flip1995`

changelog: [`redundant_locals`]: fix false positives on mutated shadows
2023-08-11 10:58:13 +00:00
bors
8703661a9a Auto merge of #11316 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

cc `@max-niederman` With the latest sync, I'm getting a lot of FP in the `redundant_locals` lint you recently added. Any ideas where this could come from?

changelog: none
2023-08-11 08:54:35 +00:00