-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Disambiguating associated types from super traits in a trait object #48285
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
Triage: I'm not aware of a way to do this. |
Repro from a duplicate issue: trait Foo {
type Error;
}
trait Bar {
type Error;
}
trait Cake : Foo + Bar {}
struct S {
f: Box<Cake<Error = i32>>,
}
fn main() {} |
There's a similar disambiguation problem here: trait A {
type C;
}
trait B: A {
type C;
}
struct S(Box<dyn B<C=()>>); though this is less of an issue because it's unlikely |
It's possible to work around this by defining an intermediate trait (thanks @estebank): trait Foo {
type Error;
}
trait Bar {
type Error;
}
trait Cake : Foo + Bar {}
trait Cake2 : Cake where Self : Foo<Error = i32>, Self : Bar<Error = u64> {}
struct S {
f: Box<dyn Cake2>,
} |
Here's a somewhat complete example of how the above could work (without having to add implementations for impl<T> Cake2 for T where T: Cake + Foo<Error = i32> + Bar<Error = u64> {} |
The error messages about these kind of things are also pretty bad: #100109 |
Suppose you have a trait:
How do you declare a
Foo
trait object, say aBox
? TheOutput
associated types need to be specified but they need to be disambiguated between the two super traits. Projections that I’ve tried don’t seem to work but it’s possible I didn’t try the right incarnation.This stems from the https://users.rust-lang.org/t/how-to-specify-associated-types-with-same-name-in-generics/15677 post.
The text was updated successfully, but these errors were encountered: