Skip to content

Bounds Inference Failure with Nested Associated Types #121325

@preston-evans98

Description

@preston-evans98

I tried this code:

pub trait BaseTrait {
    type MyType;
}

pub trait BaseTraitExt: BaseTrait
where Self::MyType: std::fmt::Debug {}

pub trait Container { 
    type Extended: BaseTraitExt;
}

I expected the code to compile successfully.

Instead, compilation fails with the following error:

error[E0277]: `<<Self as Container>::Extended as BaseTrait>::MyType` doesn't implement `Debug`
 --> src/main.rs:9:20
  |
9 |     type Extended: BaseTraitExt;
  |                    ^^^^^^^^^^^^ `<<Self as Container>::Extended as BaseTrait>::MyType` cannot be formatted using `{:?}` because it doesn't implement `Debug`
  |
  = help: the trait `Debug` is not implemented for `<<Self as Container>::Extended as BaseTrait>::MyType`
note: required by a bound in `BaseTraitExt`
 --> src/main.rs:6:21
  |
5 | pub trait BaseTraitExt: BaseTrait
  |           ------------ required by a bound in this trait
6 | where Self::MyType: std::fmt::Debug {}
  |                     ^^^^^^^^^^^^^^^ required by this bound in `BaseTraitExt`
help: consider further restricting the associated type
  |
8 | pub trait Container where <<Self as Container>::Extended as BaseTrait>::MyType: Debug { 
  |                     +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

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

Meta

rustc --version --verbose:

rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: aarch64-apple-darwin
release: 1.75.0
LLVM version: 17.0.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-type-systemArea: Type systemC-bugCategory: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler 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