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

Suggestion when encountering assoc types from hrtb #69048

Merged
merged 2 commits into from
Feb 13, 2020

Conversation

estebank
Copy link
Contributor

When encountering E0212, detect whether this is a representable case or
not, i.e. if it's happening on an fn or on an ADT. If the former,
provide a structured suggestion, otherwise note that this can't be
represented in Rust.

Fix #69000.

@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 11, 2020
@estebank
Copy link
Contributor Author

cc @nagisa

@@ -3,6 +3,8 @@ error[E0212]: cannot extract an associated type from a higher-ranked trait bound
|
LL | field: I::A
| ^^^^
|
= note: this is not currently representable in Rust
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this says "not representable", but you can still do things like:

pub trait Foo<T> {
    type A;
    fn get(&self, t: T) -> Self::A;
}

struct SomeStruct<'a, I : for<'x> Foo<&'x isize>> {
    field: <I as Foo<&'a isize>>::A
}

And it’ll work fine, likely doing exactly what you’d expect?

Copy link
Contributor Author

@estebank estebank Feb 11, 2020

Choose a reason for hiding this comment

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

I'll have a follow up PR with only the logic for this suggestion, as it will be more involved.

Added a very hacky version of the appropriate suggestion that would require some extra logic to be always accurate, but as a first approach it LGTM.

@nagisa
Copy link
Member

nagisa commented Feb 11, 2020

Very cool overall! I think we should remove the "not representable" message for now (or implement an alternative suggestion) and r=me then.

@nagisa
Copy link
Member

nagisa commented Feb 11, 2020

cc @eddyb

When encountering E0212, detect whether this is a representable case or
not, i.e. if it's happening on an `fn` or on an ADT. If the former,
provide a structured suggestion, otherwise note that this can't be
represented in Rust.
@eddyb
Copy link
Member

eddyb commented Feb 11, 2020

cc @nikomatsakis @pnkfelix

@petrochenkov
Copy link
Contributor

Could someone take this over? I have too many assigned PRs.
r? @nagisa

@rust-highfive rust-highfive assigned nagisa and unassigned petrochenkov Feb 12, 2020
@nagisa
Copy link
Member

nagisa commented Feb 13, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Feb 13, 2020

📌 Commit bde9677 has been approved by nagisa

@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-review Status: Awaiting review from the assignee but also interested parties. labels Feb 13, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Feb 13, 2020
Suggestion when encountering assoc types from hrtb

When encountering E0212, detect whether this is a representable case or
not, i.e. if it's happening on an `fn` or on an ADT. If the former,
provide a structured suggestion, otherwise note that this can't be
represented in Rust.

Fix rust-lang#69000.
bors added a commit that referenced this pull request Feb 13, 2020
Rollup of 9 pull requests

Successful merges:

 - #67642 (Relax bounds on HashMap/HashSet)
 - #68848 (Hasten macro parsing)
 - #69008 (Properly use parent generics for opaque types)
 - #69048 (Suggestion when encountering assoc types from hrtb)
 - #69049 (Optimize image sizes)
 - #69050 (Micro-optimize the heck out of LEB128 reading and writing.)
 - #69068 (Make the SGX arg cleanup implementation a NOP)
 - #69082 (When expecting `BoxFuture` and using `async {}`, suggest `Box::pin`)
 - #69104 (bootstrap: Configure cmake when building sanitizer runtimes)

Failed merges:

r? @ghost
@bors bors merged commit bde9677 into rust-lang:master Feb 13, 2020
Centril added a commit to Centril/rust that referenced this pull request Feb 17, 2020
…=ecstatic-morse

Select an appropriate unused lifetime name in suggestion

Follow up to rust-lang#69048.
Centril added a commit to Centril/rust that referenced this pull request Feb 18, 2020
…=ecstatic-morse

Select an appropriate unused lifetime name in suggestion

Follow up to rust-lang#69048.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Suggest how to workaround E0212
6 participants