Skip to content

Commit c75a930

Browse files
committed
Update old box expression tests and add a new one.
New tests also check that we're not triggering this error over-zealously.
1 parent b8fff95 commit c75a930

File tree

4 files changed

+36
-26
lines changed

4 files changed

+36
-26
lines changed

src/test/ui/dst/dst-rvalue.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
pub fn main() {
66
let _x: Box<str> = box *"hello world";
7-
//~^ ERROR E0161
8-
//~^^ ERROR cannot move out of a shared reference
7+
//~^ ERROR E0277
98

109
let array: &[isize] = &[1, 2, 3];
1110
let _x: Box<[isize]> = box *array;
12-
//~^ ERROR E0161
13-
//~^^ ERROR cannot move out of type `[isize]`, a non-copy slice
11+
//~^ ERROR E0277
1412
}

src/test/ui/dst/dst-rvalue.stderr

+12-22
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
1-
error[E0161]: cannot move a value of type str: the size of str cannot be statically determined
1+
error[E0277]: the size for values of type `str` cannot be known at compilation time
22
--> $DIR/dst-rvalue.rs:6:28
33
|
44
LL | let _x: Box<str> = box *"hello world";
5-
| ^^^^^^^^^^^^^^
6-
7-
error[E0161]: cannot move a value of type [isize]: the size of [isize] cannot be statically determined
8-
--> $DIR/dst-rvalue.rs:11:32
5+
| ^^^^^^^^^^^^^^ doesn't have a size known at compile-time
96
|
10-
LL | let _x: Box<[isize]> = box *array;
11-
| ^^^^^^
7+
= help: the trait `Sized` is not implemented for `str`
8+
= note: the type of a box expression must have a statically known size
129

13-
error[E0507]: cannot move out of a shared reference
14-
--> $DIR/dst-rvalue.rs:6:28
15-
|
16-
LL | let _x: Box<str> = box *"hello world";
17-
| ^^^^^^^^^^^^^^ move occurs because value has type `str`, which does not implement the `Copy` trait
18-
19-
error[E0508]: cannot move out of type `[isize]`, a non-copy slice
20-
--> $DIR/dst-rvalue.rs:11:32
10+
error[E0277]: the size for values of type `[isize]` cannot be known at compilation time
11+
--> $DIR/dst-rvalue.rs:10:32
2112
|
2213
LL | let _x: Box<[isize]> = box *array;
23-
| ^^^^^^
24-
| |
25-
| cannot move out of here
26-
| move occurs because `*array` has type `[isize]`, which does not implement the `Copy` trait
14+
| ^^^^^^ doesn't have a size known at compile-time
15+
|
16+
= help: the trait `Sized` is not implemented for `[isize]`
17+
= note: the type of a box expression must have a statically known size
2718

28-
error: aborting due to 4 previous errors
19+
error: aborting due to 2 previous errors
2920

30-
Some errors have detailed explanations: E0161, E0507, E0508.
31-
For more information about an error, try `rustc --explain E0161`.
21+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(box_syntax)]
2+
// Box expression needs to be movable, and hence has to be of a Sized type.
3+
fn main() {
4+
let _x: Box<[u32]> = box { loop {} };
5+
//~^ ERROR: the size for values of type `[u32]` cannot be known at compilation time
6+
7+
// Check that a deduced size does not cause issues.
8+
let _y: Box<[u32]> = box [];
9+
let _z: Box<[u32; 0]> = box { loop {} };
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0277]: the size for values of type `[u32]` cannot be known at compilation time
2+
--> $DIR/issue-87935-unsized-box-expr.rs:4:30
3+
|
4+
LL | let _x: Box<[u32]> = box { loop {} };
5+
| ^^^^^^^^^^^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `[u32]`
8+
= note: the type of a box expression must have a statically known size
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)