-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
When the return type of a default trait method returns an associated type (that has a default), there's always a mismatched type error #106968
Comments
This is correct, as I could write the following impl: impl Trait for () {
type Res = ();
} Now, |
Yeah, well, it's correct to reject the code at least, it just occurred to me that default associated types shouldn't be accessible from default trait methods (broadly: the trait method might be inherited by impls where the associated type has changed and violated the assumptions that the default method made about what the type would be.) I guess this is an error reporting problem, then. It took me like, maybe 3 hours to figure out what was actually going on. The message it gives in this situation is basically a falsehood. I'm not sure what to recommend instead. At minimum, a |
As to how I got into that situation: I wanted to define a default associated type that I actually didn't expect impls to ever override, because it was just a sort of convenience function of other associated types (that impls would define). pub trait Graph<K, V, E> {
type Index: Debug Display;
type Res<T> = Result<T, GraphError<Self::Index>>;
...
} Of course, that can run into the same problem, but the code that I had written, where the error was firing, wasn't running afoul of that problem, so it didn't occur to me that the problem existed, or that it was actually about it. |
playground
At line of '2':
error[E0308]: mismatched types
expected associated type, found integer
The text was updated successfully, but these errors were encountered: