Open uzytkownik opened 3 years ago
So, you're trying to impl Bar
, but Bar
doesn't have an associated type? Only Foo
@jackh726 Fixed (sorry - I have large app so I try to create minimal repo but sometimes I make errors when I simplify)
Minimized:
pub trait Foo {
type Assoc;
}
pub struct Baz<F: Foo, B = F::Assoc>(F, B);
Current output:
error[E0220]: associated type `Assoc` not found for `F`
--> src/lib.rs:5:31
|
5 | pub struct Baz<F: Foo, B = F::Assoc>(F, B);
| ^^^^^ there is an associated type `Assoc` in the trait `Foo`
|
help: change the associated type name to use `Assoc` from `Foo`
|
5 | pub struct Baz<F: Foo, B = F::Assoc>(F, B);
| ~~~~~
Of course, it compiles if fully qualified (B = <F as Foo>::Assoc
). Apparently, we don't pass the candidate <F as Foo>
to one_bound_for_assoc_item
.
+1. Just ran into this with an example that seems to highlight that this is a bug, namely that you can't replace the qualifier <C as T>
with C
here:
trait T {
type A;
}
struct S<
C: T,
F: Fn(C::A) = fn(<C as T>::A)
>(C, F);
I created https://github.com/rust-lang/rust/issues/129701 with a smaller reproduction of this:
trait Trait {
type Assoc;
}
struct Struct<A: Trait, B = A::Assoc> {
field_1: A,
field_2: B,
}
(that's basically https://github.com/rust-lang/rust/issues/87682#issuecomment-1907098685)
Ah, right, I somehow missed it.
I tried this code:
I expected to see this happen: Code compiles or provide a readable error
Instead, this happened:
Meta
It also happens on stable based on play.rust-lang.org.
rustc --version --verbose
: