Skip to content

Commit 5212a18

Browse files
Improve E0161 error explanation
1 parent 4fa8483 commit 5212a18

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/librustc/diagnostics.rs

-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,6 @@ This error indicates that the compiler found multiple functions with the
438438
`#[start]` attribute. This is an error because there must be a unique entry
439439
point into a Rust program. Example:
440440
441-
442441
```
443442
#![feature(start)]
444443

src/librustc_passes/diagnostics.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,36 @@ match 5u32 {
5050
"##,
5151

5252
E0161: r##"
53+
A value was moved. However, its size was not known at compile time, and only
54+
values of a known size can be moved.
55+
56+
Erroneous code example:
57+
58+
```compile_fail
59+
#![feature(box_syntax)]
60+
61+
fn main() {
62+
let array: &[isize] = &[1, 2, 3];
63+
let _x: Box<[isize]> = box *array;
64+
// error: cannot move a value of type [isize]: the size of [isize] cannot
65+
// be statically determined
66+
}
67+
```
68+
5369
In Rust, you can only move a value when its size is known at compile time.
5470
5571
To work around this restriction, consider "hiding" the value behind a reference:
5672
either `&x` or `&mut x`. Since a reference has a fixed size, this lets you move
57-
it around as usual.
73+
it around as usual. Example:
74+
75+
```
76+
#![feature(box_syntax)]
77+
78+
fn main() {
79+
let array: &[isize] = &[1, 2, 3];
80+
let _x: Box<&[isize]> = box array; // ok!
81+
}
82+
```
5883
"##,
5984

6085
E0265: r##"

0 commit comments

Comments
 (0)