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

Trait bound not satisfied when using trait constant in array expression #64866

Closed
gardell opened this issue Sep 28, 2019 · 1 comment
Closed
Labels
A-lazy-normalization Area: Lazy normalization (tracking issue: #60471)

Comments

@gardell
Copy link

gardell commented Sep 28, 2019

The following code fails on nightly/beta/stable

trait Trait {
    const SIZE: usize;
}

fn foo<T>(v: &T) where T: Trait {
    [0i32; <T as Trait>::SIZE];
}

with the following error:

error[E0277]: the trait bound `T: Trait` is not satisfied
 --> src/lib.rs:6:12
  |
6 |     [0i32; <T as Trait>::SIZE];
  |            ^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T`
  |
  = help: consider adding a `where T: Trait` bound
note: required by `Trait::SIZE`
 --> src/lib.rs:2:5
  |
2 |     const SIZE: usize;
  |     ^^^^^^^^^^^^^^^^^^

See playground at https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=94152b99b38a0faec9ef4231543cdc94

This is similar to the issues #61021 and #43580

However, the above compiles with a change of the offending line to

vec![0i32; <T as Trait>::SIZE];

Suggesting that it is specific to the constant expression being used in the array expression?

@Centril Centril added the A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) label Sep 28, 2019
@Centril
Copy link
Contributor

Centril commented Sep 28, 2019

Duplicate of #43408.

@Centril Centril closed this as completed Sep 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lazy-normalization Area: Lazy normalization (tracking issue: #60471)
Projects
None yet
Development

No branches or pull requests

2 participants