-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)C-bugCategory: This is a bug.Category: This is a bug.F-associated_type_defaults`#![feature(associated_type_defaults)]``#![feature(associated_type_defaults)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
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
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)C-bugCategory: This is a bug.Category: This is a bug.F-associated_type_defaults`#![feature(associated_type_defaults)]``#![feature(associated_type_defaults)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.