mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Update old box expression tests and add a new one.
New tests also check that we're not triggering this error over-zealously.
This commit is contained in:
parent
b8fff95961
commit
c75a93023a
@ -4,11 +4,9 @@
|
||||
|
||||
pub fn main() {
|
||||
let _x: Box<str> = box *"hello world";
|
||||
//~^ ERROR E0161
|
||||
//~^^ ERROR cannot move out of a shared reference
|
||||
//~^ ERROR E0277
|
||||
|
||||
let array: &[isize] = &[1, 2, 3];
|
||||
let _x: Box<[isize]> = box *array;
|
||||
//~^ ERROR E0161
|
||||
//~^^ ERROR cannot move out of type `[isize]`, a non-copy slice
|
||||
//~^ ERROR E0277
|
||||
}
|
||||
|
@ -1,31 +1,21 @@
|
||||
error[E0161]: cannot move a value of type str: the size of str cannot be statically determined
|
||||
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
||||
--> $DIR/dst-rvalue.rs:6:28
|
||||
|
|
||||
LL | let _x: Box<str> = box *"hello world";
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: the trait `Sized` is not implemented for `str`
|
||||
= note: the type of a box expression must have a statically known size
|
||||
|
||||
error[E0161]: cannot move a value of type [isize]: the size of [isize] cannot be statically determined
|
||||
--> $DIR/dst-rvalue.rs:11:32
|
||||
error[E0277]: the size for values of type `[isize]` cannot be known at compilation time
|
||||
--> $DIR/dst-rvalue.rs:10:32
|
||||
|
|
||||
LL | let _x: Box<[isize]> = box *array;
|
||||
| ^^^^^^
|
||||
|
||||
error[E0507]: cannot move out of a shared reference
|
||||
--> $DIR/dst-rvalue.rs:6:28
|
||||
| ^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
LL | let _x: Box<str> = box *"hello world";
|
||||
| ^^^^^^^^^^^^^^ move occurs because value has type `str`, which does not implement the `Copy` trait
|
||||
= help: the trait `Sized` is not implemented for `[isize]`
|
||||
= note: the type of a box expression must have a statically known size
|
||||
|
||||
error[E0508]: cannot move out of type `[isize]`, a non-copy slice
|
||||
--> $DIR/dst-rvalue.rs:11:32
|
||||
|
|
||||
LL | let _x: Box<[isize]> = box *array;
|
||||
| ^^^^^^
|
||||
| |
|
||||
| cannot move out of here
|
||||
| move occurs because `*array` has type `[isize]`, which does not implement the `Copy` trait
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0161, E0507, E0508.
|
||||
For more information about an error, try `rustc --explain E0161`.
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
10
src/test/ui/typeck/issue-87935-unsized-box-expr.rs
Normal file
10
src/test/ui/typeck/issue-87935-unsized-box-expr.rs
Normal file
@ -0,0 +1,10 @@
|
||||
#![feature(box_syntax)]
|
||||
// Box expression needs to be movable, and hence has to be of a Sized type.
|
||||
fn main() {
|
||||
let _x: Box<[u32]> = box { loop {} };
|
||||
//~^ ERROR: the size for values of type `[u32]` cannot be known at compilation time
|
||||
|
||||
// Check that a deduced size does not cause issues.
|
||||
let _y: Box<[u32]> = box [];
|
||||
let _z: Box<[u32; 0]> = box { loop {} };
|
||||
}
|
12
src/test/ui/typeck/issue-87935-unsized-box-expr.stderr
Normal file
12
src/test/ui/typeck/issue-87935-unsized-box-expr.stderr
Normal file
@ -0,0 +1,12 @@
|
||||
error[E0277]: the size for values of type `[u32]` cannot be known at compilation time
|
||||
--> $DIR/issue-87935-unsized-box-expr.rs:4:30
|
||||
|
|
||||
LL | let _x: Box<[u32]> = box { loop {} };
|
||||
| ^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: the trait `Sized` is not implemented for `[u32]`
|
||||
= note: the type of a box expression must have a statically known size
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
Loading…
Reference in New Issue
Block a user