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

"Cycle computing supertraits" error could be more helpful #62581

Open
joshlf opened this issue Jul 11, 2019 · 6 comments
Open

"Cycle computing supertraits" error could be more helpful #62581

joshlf opened this issue Jul 11, 2019 · 6 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@joshlf
Copy link
Contributor

joshlf commented Jul 11, 2019

Consider the following code:

trait Foo<F> {}

trait Bar: Foo<Self::F> {
    type F;
}

Trying to compile it, we get the following error:

error[E0391]: cycle detected when computing the supertraits of `Bar`
 --> src/lib.rs:3:1
  |
3 | trait Bar: Foo<Self::F> {
  | ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: ...which again requires computing the supertraits of `Bar`, completing the cycle
note: cycle used when collecting item types in top-level module
 --> src/lib.rs:3:1
  |
3 | trait Bar: Foo<Self::F> {
  | ^^^^^^^^^^^^^^^^^^^^^^^

To most programmers, this just looks like Rust won't let you have a trait bound which depends on an associated type in the trait being defined. That's what I thought for a long time. But that's not actually true - what's actually going on is that in order to figure out which F is being referred to in Self::F, the supertraits need to be computed. If we help the compiler out by disambiguating which F we mean, the error goes away:

trait Foo<F> {}

trait Bar: Foo<<Self as Bar>::F> {
    type F;
}

I suggest that we improve the error message in this case to suggest disambiguating any associated types in trait bounds in order to steer users towards this solution.

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 11, 2019
@samsartor
Copy link

@rustbot claim

@rustbot rustbot self-assigned this Jul 15, 2019
@joshlf
Copy link
Contributor Author

joshlf commented Jul 19, 2019

I would just like to say that I just got bitten by this again and, even though I ran into this just last week, I initially forgot and thought that I was screwed until I remembered this. We definitely need a better error message :)

@samsartor
Copy link

I'm on it!

@JohnTitor
Copy link
Member

Triage: I'm going to release assignment due to inactivity.
@samsartor If you're still interested in this, feel free to re-claim.
@rustbot release-assignment

@rustbot rustbot removed their assignment Jul 24, 2020
@samsartor
Copy link

Sorry about that. I worked on it a bit but then totally forgot I even had it assigned! Someone else should give it a shot.

@naiveai
Copy link

naiveai commented Oct 8, 2022

I'm new to the compiler, and I don't fully know whether this is a good issue to jump in on, but I find it interesting so I'll give it a shot. I'll set a reminder to unassign myself if I can't figure it out so I don't forget about it.

@rustbot claim

@naiveai naiveai removed their assignment Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants