Skip to content

unconstrained type parameter with associated types that are actually constrained #140201

Open
@y86-dev

Description

@y86-dev

I tried this code (playground):

pub trait Marker {}

pub trait Foo {
    type Bar;
}

struct Baz<T>(T);

impl<T> Foo for Baz<T> {
    type Bar = Baz<T>;
}

impl<T> Marker for <Baz<T> as Foo>::Bar {}

I expected to see this happen: successful compilation

Instead, this happened: compilation error:

error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
  --> src/main.rs:13:6
   |
13 | impl<T> Marker for <Baz<T> as Foo>::Bar {}
   |      ^ unconstrained type parameter

For more information about this error, try `rustc --explain E0207`.
error: could not compile `tmp` (bin "tmp") due to 1 previous error

And this confuses me, as clearly the T is being used in the associated type of Baz.

I searched around for other issues similar to this, but I couldn't find one matching exactly with this problem.

Meta

rustc --version --verbose:

rustc 1.88.0-nightly (092a284ba 2025-04-13)
binary: rustc
commit-hash: 092a284ba0421695f2032c947765429fd7095796
commit-date: 2025-04-13
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemC-bugCategory: This is a bug.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