Skip to content
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

Closed
sdroege opened this issue Nov 12, 2017 · 7 comments
Labels
C-bug Category: This is a bug. P-medium Medium priority T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@sdroege
Copy link
Contributor

sdroege commented Nov 12, 2017

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 as Foo is defined in the same crate, otherwise it maps the Foo (for whatever reason) to Baz itself.

@alexcrichton

@alexcrichton
Copy link
Member

cc @rust-lang/compiler, seems like a scary compiler bug! Is there perhaps an issue already open for this?

@Mark-Simulacrum Mark-Simulacrum added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 12, 2017
@arielb1 arielb1 added P-high High priority and removed I-nominated labels Nov 16, 2017
@arielb1 arielb1 self-assigned this Nov 16, 2017
@arielb1 arielb1 added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Nov 19, 2017
@arielb1
Copy link
Contributor

arielb1 commented Nov 19, 2017

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 Foo: Mapper holds (type not local, trait not local and not fundamental), and, as a consequence, it is not allowed to normalize (or, in a post-lazy-normalization world, to know what types are equal to) <Foo as Mapper>::OtherType.

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.

@arielb1
Copy link
Contributor

arielb1 commented Nov 19, 2017

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.

@nikomatsakis
Copy link
Contributor

triage: P-medium

Marking as T-lang, I-nominated.

@rust-highfive rust-highfive added P-medium Medium priority and removed P-high High priority labels Dec 7, 2017
@nikomatsakis nikomatsakis added I-nominated and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 7, 2017
@arielb1 arielb1 removed their assignment Dec 25, 2017
@nikomatsakis
Copy link
Contributor

Removing nomination. I think we should consider revisiting this, but just in general as part of a push on cleaning up coherence + trait code.

@XAMPPRocky XAMPPRocky added the C-bug Category: This is a bug. label Feb 12, 2018
@sdroege
Copy link
Contributor Author

sdroege commented Nov 28, 2018

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?

@lcnr
Copy link
Contributor

lcnr commented Sep 5, 2022

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 ❤️

@lcnr lcnr closed this as completed Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. P-medium Medium priority T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants