Commit graph

154 commits

Author SHA1 Message Date
Philipp Krones
d2b08432db
Merge remote-tracking branch 'upstream/master' into rustup 2023-09-07 21:43:06 +02:00
Urgau
a86e758228 Adjust clippy tests with new rustc help suggestion for lints 2023-09-04 14:22:02 +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
44f64acb7e never_loop catches loop { panic!() } 2023-09-02 08:18:53 -04:00
y21
563abf9651 [implied_bounds_in_impls]: move to nursery and fix ICEs 2023-08-30 22:08:05 +02:00
bors
19eaafb920 Auto merge of #11338 - y21:issue11337, r=Centri3
allow trait alias DefIds in `implements_trait_with_env_from_iter`

Fixes #11337

changelog: none
2023-08-24 22:28:29 +00:00
Philipp Krones
cc61aeea54 Merge commit '080b587854a73f2a8cbaecff1884860a78e2ff37' into clippyup 2023-08-24 21:32:12 +02:00
Guillaume Gomez
a05d3a4137 Automatic generation of error annotations for ui tests 2023-08-22 17:18:11 +02:00
Guillaume Gomez
9c96605b20 Manually add annotations for ui tests 2023-08-22 17:14:08 +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
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
y21
f746e19169 allow trait alias DefIds in implements_trait_with_env_from_iter 2023-08-14 19:10:33 +02:00
Alex Macleod
77d10ac63d Use ui_test's Windows path backslash heuristic 2023-08-14 15:59:00 +00:00
y21
2820d980cb [useless_conversion]: fix FP in macro and add test 2023-08-14 16:28:04 +02:00
Oli Scherer
00919a4f92 Update ui test crate to auto-detect aux build crate kind 2023-08-11 14:02:35 +00:00
Oli Scherer
3d88fae050 Update ui test crate 2023-08-11 14:02:28 +00:00
Philipp Krones
d6d530fd0b Merge commit 'd9c24d1b1ee61f276e550b967409c9f155eac4e3' into clippyup 2023-07-17 10:22:32 +02:00
Mahdi Dibaiee
fdb2e363d3 refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
Philipp Krones
cb3ecf7b79 Merge commit '37f4c1725d3fd7e9c3ffd8783246bc5589debc53' into clippyup 2023-07-02 14:59:02 +02:00
Oli Scherer
7bd8ab77e5 Make simd_shuffle_indices use valtrees 2023-06-26 09:34:52 +00:00
yukang
23d7a07e86 Do not offer any of the suggestions in emit_coerce_suggestions for expr from destructuring assignment desugaring 2023-06-25 09:26:17 +08:00
Urgau
edb3266b91 Drop uplifted clippy:cmp_nan 2023-06-10 11:13:01 +02:00
Philipp Krones
e6dc0efc00 Merge commit '30448e8cf98d4754350db0c959644564f317bc0f' into clippyup 2023-06-02 11:41:57 +02:00
Philipp Krones
7e9abb311d Merge commit '371120bdbf58a331db5dcfb2d9cddc040f486de8' into clippyup 2023-05-05 17:45:49 +02:00
Philipp Krones
a1b75c5108 Merge commit 'a3ed905928a03b6e433d0b429190bf3a847128b3' into clippyup 2023-04-23 13:28:56 +02:00
Matthias Krüger
1dfc231b10 clippy: add test for https://github.com/rust-lang/rust-clippy/issues/10645 2023-04-18 18:46:41 +00:00
Esteban Küber
4680aa2fd0 Special-case item attributes in the suggestion output 2023-04-12 22:50:10 +00:00
Esteban Küber
7a0fb902bc Tweak output for 'add line' suggestion 2023-04-12 22:50:10 +00:00
Jamen Marz
28b80059ed Add notes to non-structural const in pattern error message 2023-03-27 11:08:11 -04:00
Philipp Krones
8df896c076 Merge commit 'd5e2a7aca55ed49fc943b7a07a8eba05ab5a0079' into clippyup 2023-03-24 14:26:19 +01:00
Philipp Krones
cf8a67d9ad Merge commit '3c06e0b1ce003912f8fe0536d3a7fe22558e38cf' into clippyup 2023-03-10 10:53:50 +01:00
Alex Macleod
64b54ef950 Fix array-size-threshold config deserialization error 2023-03-02 21:42:11 +01:00
Jason Newcomb
0413fb35ba Merge commit '149392b0baa4730c68f3c3eadf5c6ed7b16b85a4' into clippyup 2023-02-25 19:28:50 -05:00
Philipp Krones
e7fe1f9c14 Merge commit '0f7558148c22e53cd4608773b56cdfa50dcdeac3' into clippyup 2023-02-10 14:01:19 +01:00
Michael Goulet
2253646395 Don't suggest dyn as parameter to add 2023-01-12 22:04:30 +00:00
Albert Larsan
5f8686ec3b Change src/test to tests in source files, fix tidy and tests 2023-01-11 09:32:13 +00:00
Philipp Krones
4ccafea92d Merge commit '4f3ab69ea0a0908260944443c739426cc384ae1a' into clippyup 2022-12-29 14:28:34 +01:00
Philipp Krones
46c5a5d234 Merge commit 'f4850f7292efa33759b4f7f9b7621268979e9914' into clippyup 2022-11-21 20:51:52 +01:00
yukang
84c3a959a7 bless clippy 2022-11-09 19:23:23 +08:00
flip1995
cd0bb7de01 Merge commit '4f142aa1058f14f153f8bfd2d82f04ddb9982388' into clippyup 2022-10-23 15:18:45 +02:00
Ralf Jung
e91746ed82 make const_err a hard error 2022-10-07 18:08:49 +02:00
Philipp Krones
d75b25faab Merge commit 'ac0e10aa68325235069a842f47499852b2dee79e' into clippyup 2022-10-06 09:44:38 +02:00
Maybe Waffle
8dfbad9e49 bless clippy 2022-10-01 10:03:06 +00:00
Nilstrieb
334f4535bd Stabilize const BTree{Map,Set}::new
Since `len` and `is_empty` are not const stable yet, this also
creates a new feature for them since they previously used the same
`const_btree_new` feature.
2022-09-23 20:55:37 +02:00
David Koloski
4d015293d1 Merge commit '7248d06384c6a90de58c04c1f46be88821278d8b' into sync-from-clippy 2022-09-21 13:13:27 -04:00
Philipp Krones
98bf99e2f8 Merge commit 'b52fb5234cd7c11ecfae51897a6f7fa52e8777fc' into clippyup 2022-09-09 13:36:26 +02:00
Philipp Krones
dc29cfb8d5 Merge commit '2b2190cb5667cdd276a24ef8b9f3692209c54a89' into clippyup 2022-08-11 19:42:16 +02:00
Philipp Krones
67c405cc1d Merge commit '3c7e7dbc1583a0b06df5bd7623dd354a4debd23d' into clippyup 2022-07-28 19:08:22 +02:00
Michael Goulet
632f9945d6 Do not resolve associated const when there is no provided value 2022-07-22 18:58:07 +00:00
Philipp Krones
7d4daaa8fa Merge commit 'fdb84cbfd25908df5683f8f62388f663d9260e39' into clippyup 2022-07-18 09:39:37 +02:00