Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak suggest_constraining_type_param #70009

Merged
merged 1 commit into from
Mar 30, 2020
Merged

Conversation

estebank
Copy link
Contributor

Some of the bound restriction structured suggestions were incorrect while others had subpar output.

The only issue left is a suggestion for an already present bound when dealing with consts that should be handled independently.

Fix #69983.

@rust-highfive

This comment has been minimized.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 14, 2020
@Centril Centril self-assigned this Mar 18, 2020
@bors

This comment has been minimized.

@Centril Centril added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 24, 2020
Comment on lines +219 to +229
hir::Item { kind: hir::ItemKind::Struct(_, generics), .. }
| hir::Item { kind: hir::ItemKind::Enum(_, generics), .. }
| hir::Item { kind: hir::ItemKind::Union(_, generics), .. }
| hir::Item { kind: hir::ItemKind::Trait(_, _, generics, ..), .. }
| hir::Item { kind: hir::ItemKind::Impl { generics, .. }, .. }
| hir::Item { kind: hir::ItemKind::Fn(_, generics, _), .. }
| hir::Item { kind: hir::ItemKind::TyAlias(_, generics), .. }
| hir::Item { kind: hir::ItemKind::TraitAlias(generics, _), .. }
| hir::Item {
kind: hir::ItemKind::OpaqueTy(hir::OpaqueTy { generics, .. }), ..
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you can further simplify this by moving the or-pattern all the way into the kind: field-pattern (same above).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that first but I got a syntax error so I assumed it wasn't possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, that shouldn't happen... Let's merge this without and I'll see what's up with this myself.

@Centril
Copy link
Contributor

Centril commented Mar 26, 2020

r=me with final nit addressed. :)

@estebank
Copy link
Contributor Author

@bors r=Centril

@bors
Copy link
Contributor

bors commented Mar 26, 2020

📌 Commit 293cf51 has been approved by Centril

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 26, 2020
@bors
Copy link
Contributor

bors commented Mar 27, 2020

⌛ Testing commit 293cf51 with merge 1a69ea894186a265cbff1be75029e1e889a0bf5b...

Centril added a commit to Centril/rust that referenced this pull request Mar 27, 2020
Tweak `suggest_constraining_type_param`

Some of the bound restriction structured suggestions were incorrect while others had subpar output.

The only issue left is a suggestion for an already present bound when dealing with `const`s that should be handled independently.

Fix rust-lang#69983.
@Centril
Copy link
Contributor

Centril commented Mar 27, 2020

@bors retry

@Centril
Copy link
Contributor

Centril commented Mar 27, 2020

Failed in #70481 (comment), @bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 27, 2020
@estebank
Copy link
Contributor Author

It seems like --compare-mode=nll discrepancy. Rebasing and fixing.

Some of the bound restriction structured suggestions were incorrect
while others had subpar output.
@estebank
Copy link
Contributor Author

@bors r=Centril

@bors
Copy link
Contributor

bors commented Mar 29, 2020

📌 Commit 2c71894 has been approved by Centril

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 29, 2020
@bors
Copy link
Contributor

bors commented Mar 29, 2020

⌛ Testing commit 2c71894 with merge 4911572...

@bors
Copy link
Contributor

bors commented Mar 30, 2020

☀️ Test successful - checks-azure
Approved by: Centril
Pushing 4911572 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 30, 2020
@bors bors merged commit 4911572 into rust-lang:master Mar 30, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Sep 16, 2020
…ion, r=estebank

fix syntax error in suggesting generic constraint in trait parameter

suggest `where T: Foo` for the first bound on a trait, then suggest
`, T: Foo` when the suggested bound would add to an existing set of
`where` clauses. `where T: Foo` may be the first bound if `T` has a
default, because we'd rather suggest
```
trait A<T=()> where T: Copy
```
than
```
trait A<T: Copy=()>
```
for legibility reasons.

the test case i added here is derived from [this reproduction](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=0bf3ace9f2a183d0bdbd748c6b8e3971):
```
struct B<T: Copy> {
    t: T
}

trait A<T = ()> {
    fn returns_constrained_type(&self, t: T) -> B<T> {
        B { t }
    }
}
```
where the suggested fix,
```
trait A<T = ()>, T: Copy { ... }
```
is in fact invalid syntax!

i also found an error in the existing suggestion for `trait Base<T = String>: Super<T>` where rustc would suggest `trait Base<T = String>: Super<T>, T: Copy`, but `T: Copy` is the first of the trait's `where` clauses and should be `where T: Copy` as well. the test for that suggestion expects invalid syntax, and has been revised to a compiler-pleasing `trait Base<T = String>: Super<T> where T: Copy`.

judging by rust-lang#70009 i'll.. cc @estebank ?
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Sep 16, 2020
…ion, r=estebank

fix syntax error in suggesting generic constraint in trait parameter

suggest `where T: Foo` for the first bound on a trait, then suggest
`, T: Foo` when the suggested bound would add to an existing set of
`where` clauses. `where T: Foo` may be the first bound if `T` has a
default, because we'd rather suggest
```
trait A<T=()> where T: Copy
```
than
```
trait A<T: Copy=()>
```
for legibility reasons.

the test case i added here is derived from [this reproduction](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=0bf3ace9f2a183d0bdbd748c6b8e3971):
```
struct B<T: Copy> {
    t: T
}

trait A<T = ()> {
    fn returns_constrained_type(&self, t: T) -> B<T> {
        B { t }
    }
}
```
where the suggested fix,
```
trait A<T = ()>, T: Copy { ... }
```
is in fact invalid syntax!

i also found an error in the existing suggestion for `trait Base<T = String>: Super<T>` where rustc would suggest `trait Base<T = String>: Super<T>, T: Copy`, but `T: Copy` is the first of the trait's `where` clauses and should be `where T: Copy` as well. the test for that suggestion expects invalid syntax, and has been revised to a compiler-pleasing `trait Base<T = String>: Super<T> where T: Copy`.

judging by rust-lang#70009 i'll.. cc @estebank ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

help text for Send trait bound mismatch is misleading
5 participants