Skip to content

Commit 2015eb8

Browse files
Replace "Bad example" by a better sentence
1 parent 6471dcc commit 2015eb8

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/librustc/diagnostics.rs

+36-2
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,42 @@ println!("{}", Y);
294294
```
295295
"##,
296296

297+
E0019: r##"
298+
A function call isn't allowed in the const's initialization expression
299+
because the expression's value must be known at compile-time. Example of
300+
erroneous code:
301+
302+
```
303+
enum Test {
304+
V1
305+
}
306+
307+
impl Test {
308+
fn test(&self) -> i32 {
309+
12
310+
}
311+
}
312+
313+
fn main() {
314+
const FOO: Test = Test::V1;
315+
316+
const A: i32 = FOO.test(); // You can't call Test::func() here !
317+
}
318+
```
319+
320+
Remember: you can't use a function call inside a const's initialization
321+
expression! However, you can totally use it elsewhere you want:
322+
323+
```
324+
fn main() {
325+
const FOO: Test = Test::V1;
326+
327+
FOO.func(); // here is good
328+
let x = FOO.func(); // or even here!
329+
}
330+
```
331+
"##,
332+
297333
E0020: r##"
298334
This error indicates that an attempt was made to divide by zero (or take the
299335
remainder of a zero divisor) in a static or constant expression.
@@ -965,9 +1001,7 @@ static mut BAR: Option<Vec<i32>> = None;
9651001

9661002

9671003
register_diagnostics! {
968-
E0016,
9691004
E0017,
970-
E0019,
9711005
E0022,
9721006
E0038,
9731007
E0109,

0 commit comments

Comments
 (0)