-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add E0019 error explanation #26396
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
Add E0019 error explanation #26396
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
@@ -279,6 +279,41 @@ println!("{}", Y); | |||
``` | |||
"##, | |||
|
|||
E0019: r##" | |||
A function call isn't allowed in the const's initialization expression | |||
because the expression's value must be known at compile-time. Bad example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The phrase "Bad example" is often used when one is saying that the example itself is bad -- i.e. when the example does not actually serve as a demonstration of the topic at hand.
I would instead write: "Example of erroneous code:" or "Example of non-compiling code:"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually had the same comment on the other PRs I opened yesterday. I forgot to update this one, I do it.
Updated! |
} | ||
``` | ||
|
||
Remember: you can't use a function call inside a const's initialization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add an additional paragraph about the const fn
feature, which is currently feature-gated and thus only available in Nightly (but there are other error explanations like E0152 that reference feature-gated things). The sole purpose of const fn
is to be a function call that breaks the rule you wrote here. :)
Here is a demonstration of const fn
:
https://play.rust-lang.org/?gist=449fb78958b96eca7528&version=nightly
(I've been discussing the question of whether to include discussion of feature-gated things. For now I think it would be best if @GuillaumeGomez removes the final commit above from this PR, and then we land it. We can then put that final commit up as a separate PR that will only be landed after we resolve the question of how to discuss feature-gated things in error explanations.) |
Part of #24407.
cc @michaelsproul