Inconsistent behavior when using associated type bounds in super trait with constraints
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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 https://github.com/rust-lang/rust/issues/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: https://github.com/rust-lang/rust/issues/65913#issuecomment-547201080
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>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the minimal reproducer in src/lib.rs and compare the three associated-type bound forms shown in the report. Trace why the first two produce a cycle while the equivalent forms compile; done means the inconsistent behavior is resolved and the relevant cases have regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 45/100