Skip to content

Default impls cannot take into account associated types #52396

Open
@Ericson2314

Description

@Ericson2314

Suppose I have some trait with a default method:

trait Foo {
  fn bar(&self, isize) { .. }
}

and I want to add an associated type:

trait Foo {
  type Baz = isize;
  fn bar(&self, Self::Baz);
}

This is a breaking change unless I move the old default method to a new default impl. But there is no way to condition the default impl on choice the choice of associated type. For example:

default impl<A: Foo<Baz = isize>> Foo for A {
  fn bar(&self, isize) { .. }
}

is prohibited, and both

default impl<A> Foo for A {
  type Baz = isize;
  fn bar(&self, Self::Baz);
}

and

default impl<A> Foo for A {
  default type Baz = isize;
  fn bar(&self, Self::Baz);
}

do the wrong thing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-specializationArea: Trait impl specializationC-bugCategory: This is a bug.F-specialization`#![feature(specialization)]`T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions