Specifying one associated type makes Rust forget about the constraint on the other ones #72207
Labels
A-associated-items
Area: Associated items (types, constants & functions)
A-closures
Area: Closures (`|…| { … }`)
A-impl-trait
Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
A-trait-system
Area: Trait system
C-bug
Category: This is a bug.
E-needs-test
Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-types
Relevant to the types team, which will review and decide on the PR/issue.
I tried this code (which is actually the minimum reproduction I could find, as the bug seems to disappear when I try to reduce it more):
It does compile: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=54e239ced207241c8438dddbc325ef19
If however we specify the value for the associated type
E
inf
andf2
, so that code callingf2()
can depend on knowing the typeE
:The compiler seems to forget that any
X::F2
implementsFn(Self::E)
, and stops compiling: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=1e84aea4402bd45da498aace9682b1adNote that the bug does not happen if
F2: Fn()
instead ofF2: Fn(E)
:https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=266f91f2ba2f0730148c4dea8c3732a4
It does not happen either if
F2: Fn(T)
instead ofF2: Fn(E)
:https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=e37b04bfdeec2a1ebddc10a4422931e8
Meta
rustc --version --verbose
:This also happens on nightly.
The text was updated successfully, but these errors were encountered: