Skip to content

Associated type default and From #47385

Closed
@valff

Description

@valff

Associated type defaults seem broken in the following case: (play)

#![feature(associated_type_defaults)]

pub struct Foo;

pub trait Bar: From<<Self as Bar>::Input> {
    type Input = Self;
}

impl Bar for Foo {
    // Will compile with explicit type:
    // type Input = Self;
}

fn main() {}

Compile error:

error[E0277]: the trait bound `Foo: std::convert::From<<Foo as Bar>::Input>` is not satisfied
 --> src/main.rs:9:6
  |
9 | impl Bar for Foo {
  |      ^^^ the trait `std::convert::From<<Foo as Bar>::Input>` is not implemented for `Foo`

However if I uncomment type Input = Self in impl, it will work. It is confusing, because Input should be already set to Self in the default case.

Metadata

Metadata

Labels

A-associated-itemsArea: Associated items (types, constants & functions)C-bugCategory: This is a bug.F-associated_type_defaults`#![feature(associated_type_defaults)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions