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

Trait bounds don't work on default associated types #67187

Closed
pythongirl325 opened this issue Dec 10, 2019 · 2 comments · Fixed by #61812
Closed

Trait bounds don't work on default associated types #67187

pythongirl325 opened this issue Dec 10, 2019 · 2 comments · Fixed by #61812
Assignees
Labels
A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. F-associated_type_defaults `#![feature(associated_type_defaults)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pythongirl325
Copy link

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
@Centril Centril added the F-associated_type_defaults `#![feature(associated_type_defaults)]` label Dec 10, 2019
@Centril
Copy link
Contributor

Centril commented Dec 10, 2019

cc @jonas-schievink

@Centril Centril added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Dec 10, 2019
@jonas-schievink
Copy link
Contributor

This will be fixed by #61812, but I'm not adding a test for this issue specifically since there are already plenty (and the normalization of the assoc. type is controlled by flipping a single bool in librustc).

@jonas-schievink jonas-schievink self-assigned this Dec 10, 2019
@jonas-schievink jonas-schievink added requires-nightly This issue requires a nightly compiler in some way. A-associated-items Area: Associated items (types, constants & functions) labels Jan 4, 2020
@bors bors closed this as completed in 3a0d106 Feb 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. F-associated_type_defaults `#![feature(associated_type_defaults)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants