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

Badly worded note for non-constant array length #41871

Closed
durka opened this issue May 10, 2017 · 8 comments
Closed

Badly worded note for non-constant array length #41871

durka opened this issue May 10, 2017 · 8 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@durka
Copy link
Contributor

durka commented May 10, 2017

let len = 42;
let arr = [0; len];

rustc 1.0.0 - 1.11.0: error: expected constant integer for repeat count, found variable
rustc 1.12.0 - 1.15.0: non-constant path in constant expression
rustc 1.16.0 - present: non-constant used with constant

Can we have the first one back please?

@cbreeden
Copy link
Contributor

To clarify, the problem is in the note:

rustc 1.17.0 (56124baa9 2017-04-24)
error[E0435]: attempt to use a non-constant value in a constant
 --> <anon>:3:19
  |
3 |     let arr = [0; len];
  |                   ^^^ non-constant used with constant

error: aborting due to previous error

@kennytm
Copy link
Member

kennytm commented May 10, 2017

Note introduced in #35858, using the exact wording from #35801.

Rust 1.12 fully transitioned to MIR, which made the repeat count no longer special, thus losing the special error message.

I think the note should be reworded to "non-constant used as constant".

@Mark-Simulacrum
Copy link
Member

The error message today speaks the truth and does so quite well. Closing.

error[E0435]: attempt to use a non-constant value in a constant
 --> test.rs:3:19
  |
3 |     let arr = [0; len];
  |                   ^^^ non-constant used with constant

error: aborting due to previous error(s)

@durka
Copy link
Contributor Author

durka commented Jun 22, 2017

The span label is still pretty nonsensical.

@Mark-Simulacrum
Copy link
Member

Okay, I'll reopen. Can you provide the exact wording you'd expect? (I personally don't really see any point for a span label, but ... ).

@durka
Copy link
Contributor Author

durka commented Jun 22, 2017

Either remove the label or just "non-constant value" seems to make more sense to me. It's the "with constant" that is weird IMO.

@durka
Copy link
Contributor Author

durka commented Jun 22, 2017

I'll PR.

@Mark-Simulacrum Mark-Simulacrum added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 23, 2017
@bors bors closed this as completed in 0883ce1 Jun 23, 2017
@JeffCarpenter
Copy link

I just came here after googling attempt to use a non-constant value in a constant: non-constant value and want to say that the first error message is a lot easier to understand!

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 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

5 participants