]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/diagnostics.rs
Rollup merge of #41249 - GuillaumeGomez:rustdoc-render, r=steveklabnik,frewsxcv
[rust.git] / src / librustc_mir / diagnostics.rs
index 4a731d898a937d8edabcce09e07e6834febcce96..bb07081fe433b74dab3ccf6ae1fbce3480616218 100644 (file)
@@ -18,7 +18,7 @@
 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;
@@ -30,7 +30,7 @@
 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;
 ```
@@ -66,7 +66,7 @@ struct Bar {x: u8}
 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!
 ```
 
@@ -81,7 +81,7 @@ struct Bar {x: u8}
 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;
 
@@ -107,7 +107,7 @@ struct Bar {x: u8}
 
 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;
@@ -152,7 +152,7 @@ fn test(&self) -> i32 {
 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!
 }
 ```
 
@@ -214,14 +214,13 @@ const fn foo(mut x: u8) {
 ```
 "##,
 
-
 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;
 
@@ -245,12 +244,45 @@ const fn foo(mut x: u8) {
 ```
 "##,
 
+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 };
@@ -272,7 +304,7 @@ const fn foo(mut x: u8) {
 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;
@@ -299,7 +331,7 @@ const fn foo(mut x: u8) {
 
 You can also have this error while using a cell type:
 
-```compile_fail
+```compile_fail,E0492
 #![feature(const_fn)]
 
 use std::cell::Cell;
@@ -351,7 +383,7 @@ unsafe impl<T> Sync for NotThreadSafe<T> {}
 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
 }
@@ -374,7 +406,7 @@ fn drop(&mut self) {}
 A reference of an interior static was assigned to another const/static.
 Erroneous code example:
 
-```compile_fail
+```compile_fail,E0494
 struct Foo {
     a: u32
 }