the heap at runtime, and therefore cannot be done at compile time. Erroneous
code example:
-```compile_fail
+```compile_fail,E0010
#![feature(box_syntax)]
const CON : Box<i32> = box 0;
variable cannot refer to a static variable. For example, `Y` cannot refer to
`X` here:
-```compile_fail
+```compile_fail,E0013
static X: i32 = 42;
const Y: i32 = X;
```
Blocks in constants may only contain items (such as constant, function
definition, etc...) and a tail expression. Erroneous code example:
-```compile_fail
+```compile_fail,E0016
const FOO: i32 = { let x = 0; x }; // 'x' isn't an item!
```
References in statics and constants may only refer to immutable values.
Erroneous code example:
-```compile_fail
+```compile_fail,E0017
static X: i32 = 1;
const C: i32 = 2;
For example, if you write:
-```compile_fail
+```compile_fail,E0018
static MY_STATIC: u32 = 42;
static MY_STATIC_ADDR: usize = &MY_STATIC as *const _ as usize;
static WHAT: usize = (MY_STATIC_ADDR^17) + MY_STATIC_ADDR;
fn main() {
const FOO: Test = Test::V1;
- const A: i32 = FOO.test(); // You can't call Test::func() here !
+ const A: i32 = FOO.test(); // You can't call Test::func() here!
}
```
```
"##,
-
E0395: r##"
The value assigned to a constant scalar must be known at compile time,
which is not the case when comparing raw pointers.
Erroneous code example:
-```compile_fail
+```compile_fail,E0395
static FOO: i32 = 42;
static BAR: i32 = 42;
```
"##,
+E0161: r##"
+A value was moved. However, its size was not known at compile time, and only
+values of a known size can be moved.
+
+Erroneous code example:
+
+```compile_fail
+#![feature(box_syntax)]
+
+fn main() {
+ let array: &[isize] = &[1, 2, 3];
+ let _x: Box<[isize]> = box *array;
+ // error: cannot move a value of type [isize]: the size of [isize] cannot
+ // be statically determined
+}
+```
+
+In Rust, you can only move a value when its size is known at compile time.
+
+To work around this restriction, consider "hiding" the value behind a reference:
+either `&x` or `&mut x`. Since a reference has a fixed size, this lets you move
+it around as usual. Example:
+
+```
+#![feature(box_syntax)]
+
+fn main() {
+ let array: &[isize] = &[1, 2, 3];
+ let _x: Box<&[isize]> = box array; // ok!
+}
+```
+"##,
+
E0396: r##"
The value behind a raw pointer can't be determined at compile-time
(or even link-time), which means it can't be used in a constant
expression. Erroneous code example:
-```compile_fail
+```compile_fail,E0396
const REG_ADDR: *const u8 = 0x5f3759df as *const u8;
const VALUE: u8 = unsafe { *REG_ADDR };
A borrow of a constant containing interior mutability was attempted. Erroneous
code example:
-```compile_fail
+```compile_fail,E0492
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
const A: AtomicUsize = ATOMIC_USIZE_INIT;
You can also have this error while using a cell type:
-```compile_fail
+```compile_fail,E0492
#![feature(const_fn)]
use std::cell::Cell;
A type with a destructor was assigned to an invalid type of variable. Erroneous
code example:
-```compile_fail
+```compile_fail,E0493
struct Foo {
a: u32
}
A reference of an interior static was assigned to another const/static.
Erroneous code example:
-```compile_fail
+```compile_fail,E0494
struct Foo {
a: u32
}