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

Confusing diagnostics when using associated const as an array size #68695

Closed
Disasm opened this issue Jan 31, 2020 · 0 comments · Fixed by #68763
Closed

Confusing diagnostics when using associated const as an array size #68695

Disasm opened this issue Jan 31, 2020 · 0 comments · Fixed by #68763
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

@Disasm
Copy link
Contributor

Disasm commented Jan 31, 2020

trait Adapter {
    const LINKS: usize;
}

struct Foo<A: Adapter> {
    adapter: A,
    links: [u32; A::LINKS],
}

Playground

error[E0599]: no associated item named `LINKS` found for type `A` in the current scope
 --> src/lib.rs:7:21
  |
7 |     links: [u32; A::LINKS],
  |                     ^^^^^ associated item not found in `A`
  |
  = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `LINKS`, perhaps you need to restrict type parameter `A` with it:
  |
5 | struct Foo<A: Adapter + Adapter> {
  |            ^^^^^^^^^^^^

At the same time on nightly with #![feature(const_generics)] error description is much better:

#![feature(const_generics)]
trait Adapter {
    const LINKS: usize;
}

struct Foo<A: Adapter> {
    adapter: A,
    links: [u32; A::LINKS],
}

Playground

error: constant expression depends on a generic parameter
 --> src/lib.rs:8:5
  |
8 |     links: [u32; A::LINKS],
  |     ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this may fail depending on what value the parameter takes
@jonas-schievink jonas-schievink 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 Jan 31, 2020
Centril added a commit to Centril/rust that referenced this issue Feb 2, 2020
@bors bors closed this as completed in 2e1790d Feb 2, 2020
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

Successfully merging a pull request may close this issue.

2 participants