File tree 1 file changed +36
-2
lines changed
1 file changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -294,6 +294,42 @@ println!("{}", Y);
294
294
```
295
295
"## ,
296
296
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
+
297
333
E0020 : r##"
298
334
This error indicates that an attempt was made to divide by zero (or take the
299
335
remainder of a zero divisor) in a static or constant expression.
@@ -965,9 +1001,7 @@ static mut BAR: Option<Vec<i32>> = None;
965
1001
966
1002
967
1003
register_diagnostics ! {
968
- E0016 ,
969
1004
E0017 ,
970
- E0019 ,
971
1005
E0022 ,
972
1006
E0038 ,
973
1007
E0109 ,
You can’t perform that action at this time.
0 commit comments