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

Error message should be improved for associated consts in array lengths #44168

Closed
nwin opened this issue Aug 29, 2017 · 2 comments
Closed

Error message should be improved for associated consts in array lengths #44168

nwin opened this issue Aug 29, 2017 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nwin
Copy link
Contributor

nwin commented Aug 29, 2017

The following code

pub trait HasLength {
    const LENGTH: usize;
}

fn foo<T: Copy + HasLength>(x: T) -> [T; T::LENGTH] { [x; T::LENGTH] }

results in an error “error[E0599]: no associated item named LENGTH found for type T in the current scope”. Which is not true, it just doesn’t work in arrays yet (see #29646). The error message should reflect that.

@shepmaster shepmaster added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 1, 2017
@sfackler
Copy link
Member

The error message gets even worse if you explicitly project:

pub trait HasLength {
    const LENGTH: usize;
}

fn foo<T: Copy + HasLength>(x: T) -> [T; <T as HasLength>::LENGTH] { [x; <T as HasLength>::LENGTH] }
error[E0277]: the trait bound `T: HasLength` is not satisfied
 --> src/main.rs:5:42
  |
5 | fn foo<T: Copy + HasLength>(x: T) -> [T; <T as HasLength>::LENGTH] { [x; <T as HasLength>::LENGTH] }
  |                                          ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `HasLength` is not implemented for `T`
  |
  = help: consider adding a `where T: HasLength` bound
  = note: required by `HasLength::LENGTH`

@dtolnay
Copy link
Member

dtolnay commented Jun 9, 2018

Closing as a duplicate of #43408. According to #43408 (comment) the error message is "emergent" from the same reason we can't "just" allow this to work right now. That means fixing the error message would be as hard as lifting the limitation in the first place, which is tracked in that issue.

@dtolnay dtolnay closed this as completed Jun 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants