-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implementing trait for Existential type ICE's #53345
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
Comments
@rust-lang/lang How should this ICE be fixed? Do we want to support implementing traits for existential types? Right now existential types just hide the concrete type. Not sure if the use case for extending it exists. It also seems odd that a single type may have two completely different implementations of a trait, but one of the implementations is indirect via an existential type. Just an implementation detail, but allowing this will also make codegen more complex, as currently it just assumes that any mention of an existential type or #![feature(existential_type)]
trait MyEq {
fn my_eq(&self, other: &Self) -> bool;
}
existential type Bar: PartialEq + Eq;
fn bazr(x: u32) -> Bar {
x
}
impl MyEq for Bar {
fn my_eq(&self, other: &Self) -> bool {
self == other
}
}
fn main() {
let x = bazr(42);
let y = bazr(99);
let z = bazr(42);
assert!(x.my_eq(&z));
assert!(!x.my_eq(&y));
assert!(z.my_eq(&x));
} |
The RFC notes that:
So
Probably a matter of convenience most of the time... |
Existential types aren't really a thing anymore, so the example code above fails to compile. However, this compiles now: #![feature(type_alias_impl_trait)]
trait MyTrait {}
impl MyTrait for () {}
type Bar = impl MyTrait;
impl MyTrait for Bar {}
fn bazr() -> Bar { }
fn main() {} Im not sure this should be allowed. |
@DutchGhost can you file that as a new issue (and close this one)? |
Closing this in favor of #65384 |
Trying to implement a trait for an existential type, ICE's:
Backtrace:
The text was updated successfully, but these errors were encountered: