Skip to content

Cannot access supertrait items in trait definition #72192

Closed
@djc

Description

@djc

I tried this code:

trait Trait: SuperTrait {
    fn array() -> [u8; <Self as SuperTrait>::SIZE];
}

trait SuperTrait {
    const SIZE: usize;
}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=9d962e9ed3712729d2d9150df48ecddf

I expected to see this happen: compiled without errors.

Instead, this happened:

error[E0277]: the trait bound `Self: SuperTrait` is not satisfied
 --> src/lib.rs:2:24
  |
2 |     fn array() -> [u8; <Self as SuperTrait>::SIZE];
  |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^ - help: consider further restricting `Self`: `where Self: SuperTrait`
  |                        |
  |                        the trait `SuperTrait` is not implemented for `Self`
...
6 |     const SIZE: usize;
  |     ------------------ required by `SuperTrait::SIZE`

I'm not sure whether rustc is incapable of accessing the supertrait items (because Chalk, I guess), or whether it's erroneously detecting an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions