Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access supertrait items in trait definition #72192

Closed
djc opened this issue May 14, 2020 · 1 comment
Closed

Cannot access supertrait items in trait definition #72192

djc opened this issue May 14, 2020 · 1 comment
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug.

Comments

@djc
Copy link
Contributor

djc commented May 14, 2020

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.

@djc djc added the C-bug Category: This is a bug. label May 14, 2020
@Havvy Havvy added the A-trait-system Area: Trait system label May 14, 2020
@jonas-schievink
Copy link
Contributor

Since fn array() -> usize { <Self as SuperTrait>::SIZE } works fine, this is a duplicate of #43408

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants