-
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
Fails to resolve associated types correctly in trait impls if the concrete type is in another crate #45945
Comments
cc @rust-lang/compiler, seems like a scary compiler bug! Is there perhaps an issue already open for this? |
This isn't as spooky as it appears at first glance. This is not a soundness issue (coherence rejects code that is not unsound) or a weird bug: The problem is that, because of the future-compatibility orphan rules, coherence is not allowed to know whether As such, this looks like nothing more than a somewhat-unexpected consequence of the orphan checking rules. I'm not sure whether this is the right thing to do or not - cc the trait guys @nikomatsakis @aturon @scalexm - but this is more of a language issue. Because this affects the API future-compatibility guarantee, I would expect this to at least be documented in an RFC amendment to rust-lang/rfcs#1023 either way we choose to go. |
On a second thought, the parent crate can't actually change the value of a preexisting associated type without causing obvious downstream breakage, so that's an argument for the code being allowed to compile. On the other hand, figuring out what this means probably requires the better control over "inference guessing" that Chalk gives us. |
triage: P-medium Marking as T-lang, I-nominated. |
Removing nomination. I think we should consider revisiting this, but just in general as part of a push on cleaning up coherence + trait code. |
I just ran into this again in a different place. Is there any known way to work around this, or any plans/ideas how to fix it? |
this is a duplicate of #99940 which has more information about this bug, closing in favor of that one thank you for opening this issue ❤️ |
See https://github.com/sdroege/rust-associated-types-from-other-crate-projection-bug
The following are the relevant parts of the code:
https://github.com/sdroege/rust-associated-types-from-other-crate-projection-bug/blob/5586433d247734d0efdb73cf51f9b8b9ecde1852/bar/src/lib.rs#L7-L16
https://github.com/sdroege/rust-associated-types-from-other-crate-projection-bug/blob/5586433d247734d0efdb73cf51f9b8b9ecde1852/bar/src/lib.rs#L28-L38
In summary it seems like
impl Something<<Foo as Mapper>::OtherType> for Baz {}
works fine as long asFoo
is defined in the same crate, otherwise it maps theFoo
(for whatever reason) toBaz
itself.@alexcrichton
The text was updated successfully, but these errors were encountered: