Skip to content

Dyn compatibility error when using an associated type as a type parameter in the super-trait listing #40533

Open
@jonysy

Description

@jonysy

I tried this code:

trait Super<T> {}

trait Foo: Super<<Self as Foo>::Bar> { type Bar;  }

type BoxFoo = Box<Foo<Bar = u8>>;

The code should compile since Self::Bar is the type parameter, not Self.

Instead, it will fail with the following message:

the trait Foo cannot be made into an object
the trait cannot use Self as a type parameter in the supertrait listing

FYI the discussion that sparked this issue:

So this has to do with object safety -- any trait that references Self is not object safe because the true Self type is erased. However, the error doesn't seem appropriate in this case. I think this warrants a bug report at least to fix the error message, if not to relax the object safety check (because there could be something I don't see preventing it still... can't say I fully understand object safety).

Meta

rustc --version --verbose: rustc 1.17.0-nightly (b1e31766d 2017-03-03)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-dyn-compatibilityArea: Dyn compatibility (formerly: object safety)A-dyn-traitArea: trait objects, vtable layoutA-trait-systemArea: Trait systemA-type-systemArea: Type systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types 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