]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Rollup merge of #95970 - WaffleLapkin:nicer_trait_suggestions, r=compiler-errors
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>
Tue, 12 Apr 2022 21:17:00 +0000 (23:17 +0200)
committerGitHub <noreply@github.com>
Tue, 12 Apr 2022 21:17:00 +0000 (23:17 +0200)
commitd63a46ad2845683266479ee6e945ac476a85edc6
tree8ca45c4741c4441a0fcfbc6824d0d9c3985907fc
parent91813a7175dacce03be33ba63c7abbdea3da1748
parente4710fe2214ba85fd9a3514c76c7722253a3a275
Rollup merge of #95970 - WaffleLapkin:nicer_trait_suggestions, r=compiler-errors

Fix suggestions in case of `T:` bounds

This PR fixes a corner case in `suggest_constraining_type_params` that was causing incorrect suggestions.

For the following functions:
```rust
fn a<T:>(t: T) { [t, t]; }
fn b<T>(t: T) where T: { [t, t]; }
```

We previously suggested the following:
```text
...
help: consider restricting type parameter `T`
  |
1 | fn a<T: Copy:>(t: T) { [t, t]; }
  |       ++++++
...
help: consider further restricting this bound
  |
2 | fn b<T>(t: T) where T: + Copy { [t, t]; }
  |                        ++++++
```

Note that neither `T: Copy:` not `where T: + Copy` is a correct bound.

With this commit the suggestions are correct:
```text
...
help: consider restricting type parameter `T`
  |
1 | fn a<T: Copy>(t: T) { [t, t]; }
  |         ++++
...
help: consider further restricting this bound
  |
2 | fn b<T>(t: T) where T: Copy { [t, t]; }
  |                        ++++
```

r? `@compiler-errors`

I've tried fixing #95898 here too, but got too confused with how `suggest_traits_to_import` works and what it does :sweat_smile: