-
Notifications
You must be signed in to change notification settings - Fork 13.4k
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
Changes from 2 commits
448779d
e6696dc
402ac99
465b0db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
||
``` | ||
enum Test { | ||
V1 | ||
} | ||
|
||
impl Test { | ||
fn test(&self) -> i32 { | ||
12 | ||
} | ||
} | ||
|
||
fn main() { | ||
const FOO: Test = Test::V1; | ||
|
||
const A: i32 = FOO.test(); // You can't call Test::func() here ! | ||
} | ||
``` | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. You should add an additional paragraph about the Here is a demonstration of https://play.rust-lang.org/?gist=449fb78958b96eca7528&version=nightly |
||
expression! However, you can totally use it elsewhere you want: | ||
|
||
``` | ||
fn main() { | ||
const FOO: Test = Test::V1; | ||
|
||
FOO.func(); // here is good | ||
let x = FOO.func(); // or even here! | ||
} | ||
``` | ||
"##, | ||
|
||
E0020: r##" | ||
This error indicates that an attempt was made to divide by zero (or take the | ||
remainder of a zero divisor) in a static or constant expression. | ||
|
@@ -952,7 +987,6 @@ static mut BAR: Option<Vec<i32>> = None; | |
register_diagnostics! { | ||
E0016, | ||
E0017, | ||
E0019, | ||
E0022, | ||
E0038, | ||
E0109, | ||
|
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.