Skip to content

Inconsistent behavior when using associated type bounds in super trait with constraints #153002

@95th

Description

@95th

I tried this code:

pub trait A {
    type T: A<T = Self::T>;
}

pub trait B: A<T: B> {}

and it gives this error (similar to #65913):

error[E0391]: cycle detected when computing the implied predicates of `B`
 --> src/lib.rs:5:19
  |
5 | pub trait B: A<T: B> {}
  |                   ^
  |
  = note: ...which immediately requires computing the implied predicates of `B` again
note: cycle used when computing normalized predicates of `B`
 --> src/lib.rs:5:1
  |
5 | pub trait B: A<T: B> {}
  | ^^^^^^^^^^^^^^^^^^^^
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

As per @Centril comment here: #65913 (comment)
if I try the equivalent version, it also fails with the same error:

pub trait B
where
    Self: A<T: B>
{}

but If I tried the further equivalent version, it works:

pub trait B
where
    Self: A,
    <Self as A>::T: B
{}

I expected to see the same error as the first two variants.

Instead, this happened: it compiles.

Similarly, this works:

pub trait B: A
where
    Self::T: B
{}

Rust playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=8b0c5f1f71410a0feba69462f4e6d915

Meta

rustc --version --verbose:

rustc 1.93.1 (01f6ddf75 2026-02-11)
binary: rustc
commit-hash: 01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf
commit-date: 2026-02-11
host: aarch64-apple-darwin
release: 1.93.1
LLVM version: 21.1.8
Backtrace

<backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-trait-systemArea: Trait systemC-bugCategory: This is a bug.T-langRelevant to the language teamT-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