Closed
Description
Trait bounds fail for default associated types, but not for re-assigned associated types.
The following code does not compile as seen in this playground.
#![feature(associated_type_defaults)]
trait T {
type Item = ();
}
struct Foo;
impl T for Foo {}
fn f<I: T>() -> I::Item where I::Item: Default {
Default::default()
}
fn main(){
f::<Foo>();
}
This gives the error error[E0277]: the trait bound `<Foo as T>::Item: std::default::Default` is not satisfied
But the code does compile if impl T for Foo {}
is replaced with
impl T for Foo {
type Item = ();
}
as seen on this playground
Meta
rustc --version --verbose
:
rustc 1.41.0-nightly (59947fcae 2019-12-08)
binary: rustc
commit-hash: 59947fcae6a40df12e33af8c8c7291014b7603e0
commit-date: 2019-12-08
host: x86_64-unknown-linux-gnu
release: 1.41.0-nightly
LLVM version: 9.0