Commit graph

17963 commits

Author SHA1 Message Date
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
bors
daadab515a Auto merge of #11483 - y21:path_ends_with, r=Alexendoo
new lint: `path_ends_with_ext`

Closes #11479

Not sure if it needs more test cases. I couldn't come up with any other ones, but it is a pretty simple lint logic wise with not too many checks

changelog: new lint: [`path_ends_with_ext`]
2023-09-15 15:38:55 +00: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
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
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
bors
6734e96ba4 Auto merge of #11505 - Alexendoo:metadata-collector-truncate, r=Manishearth
Truncate files when opening in metadata-collector

Fixes the issue seen here https://github.com/rust-lang/rust-clippy/pull/11483#discussion_r1324687136 and in a couple other PRs

The changelog file was opened without truncating it, so if the new version is shorter than the old one stray contents would remain at the end of the file

The other two files first removed the file so didn't have this problem, but in all cases we now use `fs::write`/`File::create` which is write + create + truncate

changelog: none
2023-09-14 23:05:24 +00: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
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
0273ed3afd Auto merge of #11497 - Alexendoo:remove-derive-new, r=dswij
Remove `derive_new` test dependency

It is the last thing depending on syn 1.0 in clippy

changelog: none
2023-09-14 04:55:09 +00: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
Alex Macleod
0c7dcba28a Remove derive_new test dependency
It is the last thing depending on syn 1.0 in clippy
2023-09-13 18:58:47 +00:00
bors
b788addfcc Auto merge of #11473 - Alexendoo:format-args-span-parents, r=dswij
Ignore span's parents in `collect_ast_format_args`/`find_format_args`

Fixes #11470, covers some cases missed by #10980

Can't have a test yet because of #11126 but it works locally

changelog: none

r? `@dswij`
2023-09-12 16:43:14 +00:00
bors
cb057019d4 Auto merge of #11413 - jonboh:master, r=Alexendoo
new unnecessary_map_on_constructor lint

changelog: [`unnecessary_map_on_constructor`]: adds lint for cases in which map is not necessary. `Some(4).map(myfunction)` => `Some(myfunction(4))`

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

Note that the case mentioned in the issue `Some(..).and_then(|..| Some(..))` is fixed by a chain of lint changes. This PR completes the last part of that chain.

By `bind_instead_of_map`[lint](https://rust-lang.github.io/rust-clippy/master/index.html#/bind_instead_of_map):
`Some(4).and_then(|x| Some(foo(4)))` => `Some(4).map(|x| foo)`

By `redundant_closure` [lint](https://rust-lang.github.io/rust-clippy/master/index.html#/redundant_closure):
`Some(4).map(|x| foo)` => `Some(4).map(fun)`

Finally by this PR `unnecessary_map_on_constructor`:
`Some(4).map(fun)` => `Some(fun(4))`

I'm not sure this is the desired behavior for clippy and if it should be addressed in another issue/PR. I'd be up to give it a try if that's the case.
2023-09-12 16:09:06 +00:00
jonboh
f136e1634a new unnecessary_map_on_constructor lint 2023-09-12 17:32:11 +02: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
bors
98363cbf6a Auto merge of #11477 - samueltardieu:11474, r=xFrednet
Auto deref does not apply on union field

changelog: [`explicit_auto_deref`]: do not suggest propose to auto-dereference an union field

Fix #11474
2023-09-11 19:42:10 +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
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
Alex Macleod
cc8c0e0099 Ignore span's parents in collect_ast_format_args/find_format_args 2023-09-08 12:40:21 +00:00
bors
253f1c410b Auto merge of #11469 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2023-09-07 20:39:49 +00:00
Philipp Krones
184c9712b2
Fix 32bit tests 2023-09-07 22:39:11 +02:00
Philipp Krones
25e8639676
Fix clippy driver stderr test 2023-09-07 22:12:40 +02:00
Philipp Krones
d780573bec
Bump nightly version -> 2023-09-07 2023-09-07 21:43:45 +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
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
69fcbfdac0 Auto merge of #11466 - Alexendoo:ci-32bit, r=flip1995
Fix `i686-unknown-linux-gnu` CI job

When testing https://github.com/oli-obk/ui_test/pull/161 I gave `--ignored` a try, I was surprised to see many of the 32bit tests passing even though I'm on a 64bit target

Turns out the `.stderr`s were incorrect, and our `i686-unknown-linux-gnu` job has been running `x86_64-unknown-linux-gnu` so it didn't get picked up

changelog: none
2023-09-06 15:15:32 +00:00
Alex Macleod
60ffff08e6 Fix i686-unknown-linux-gnu CI job 2023-09-06 14:59:54 +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
bors
953901e35c Auto merge of #115507 - cjgillot:relative-source-file, r=oli-obk
Use relative positions inside a SourceFile.

This allows to remove the normalization of start positions for hashing, and simplify allocation of global address space.

cc `@Zoxc`
2023-09-05 21:03:56 +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
Samuel Tardieu
822c7df545 Add ui_test error annotations in existing tests 2023-09-04 17:05:03 +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
Urgau
a86e758228 Adjust clippy tests with new rustc help suggestion for lints 2023-09-04 14:22:02 +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