-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
problems with trait objects with a trait projection value that contains Self #56288
Comments
triage: P-high. assigning to self. |
oop @arielb1 volunteered to take it in parallel. |
The problem is that The problem with these supertraits is that of course, The regression was caused by #55687 - "Take supertraits into account when calculating associated types". I'm not sure what's the best way to solve this while keeping #55687. We could regard trait-objects with a projection that contains
|
We could require the user to explicitly specify the value of the type in these cases - if they'll specify it wrongly, they'll get an error anyway (that's it, it would always give an error if WF on trait object types actually worked. Right now, it doesn't, but the object type will still be uninhabited because all the "good" implementors of the trait will have consistent associated types). That would be the backwards compatible fix. |
A post-Chalk option might be to have |
Reduced version (@arielb1 has more): trait Alpha {
fn build() -> &'static dyn Beta<Delta = ()>;
}
trait Beta: Gamma<Delta = Self> {}
trait Gamma {
type Delta;
} |
Nominating for T-lang discussion. That's not a call I should make unilaterally.The question is about trait objects of these traits: trait MyTrait: Supertrait<Output=SOMETHING<Self>> {
// ...
} With the "classical useful" case being: trait MyTrait: FnMut() -> <Self as MyTrait>::MyOutput {
type MyOutput;
} A few observations:
There could also be some other alternative I haven't noticed. |
Another option would be to have trait-object types be some sort of recursive types themselves, e.g. |
T-compiler triage: This is still waiting for the lang team. (Its understandable that they didn't see it yet, as the meeting last week was cancelled.) |
This seems like the obvious "short-term" solution. It's certainly the one I thought of. Basically we would permit you to elide associated types that are specified, so long as those specifications don't involve Longer term, we definitely have to wrestle a bit with trait objects. Between the WF problems, #51443, etc, it feels like something should be adjusted. One question we've been wondering about is just how to extend Chalk to cover object types. |
Discussed in the @rust-lang/lang meeting. In short, we think the best fix is to take the ALT2 approach for now -- sidestep the ICE, but retain the benefits of #55687. (That said, for backporting purposes, it might be fine to revert #55687, that's more of an engineering question.) In principle it would be nice if trait Foo: Bar<Out = Self> {
}
trait Bar { type Out; } |
@arielb1 are you interested in doing that fix? |
Sure. |
This follows ALT2 in the issue. Fixes rust-lang#56288.
fix trait objects with a Self-containing projection values Fixes #56288. This follows ALT2 in the issue. beta-nominating since this is a regression. r? @nikomatsakis
This follows ALT2 in the issue. Fixes rust-lang#56288.
Title Edited. Original title was: ICE: Encountered a freshend type with id 0 but our counter is only at 0
Only on nightly. Minimized for your pleasure:
Error/Backtrace if
Input
is commented outError/Backtrace if
Input
is present"Correct" output on
beta
At least, "correct" as in "not an ICE"...
Additional notes:
It is not related to the name clash of the associated types, because the following modified snippet:
...also produces the same ICE on
nightly
(but compiles onbeta
).The text was updated successfully, but these errors were encountered: