Skip to content

Associated type constraints on supertraits don't propagate to usage sites #36978

Closed
@Twey

Description

@Twey

Consider the following:

trait Foo { type FooT; }
trait Bar { }
trait FooBar: Foo<FooT=usize> + Bar { }
type BoxedFooBar = Box<FooBar>;

Since the value of FooT is known from the definition of FooBar, line 4 should be fine — if FB: FooBar then necessarily FB::FooT = usize. However, this fails to compile with rustc 1.12.0, with the error:

error[E0191]: the value of the associated type `FooT` (from the trait `Foo`) must be specified
 --> <anon>:4:24
  |
4 | type BoxedFooBar = Box<FooBar>;
  |                        ^^^^^^ missing associated type `FooT` value

To make it compile, one must duplicate the information at every use-site:

trait Foo { type FooT; }
trait Bar { }
trait FooBar: Foo<FooT=usize> + Bar { }
type BoxedFooBar = Box<FooBar<FooT=usize>>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-trait-systemArea: Trait system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions