Change example and tests for E0161.

The code will not emit this warning once box expressions require a sized
type (since that error is emitted earlier in the flow).
This commit is contained in:
Anton Golov 2021-08-20 15:59:42 +02:00
parent 521734787e
commit ba83b39d4e
10 changed files with 47 additions and 61 deletions

View file

@ -4,11 +4,18 @@ Erroneous code example:
```compile_fail,E0161
#![feature(box_syntax)]
trait Bar {
fn f(self);
}
impl Bar for i32 {
fn f(self) {}
}
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
let b: Box<dyn Bar> = box (0 as i32);
b.f();
// error: cannot move a value of type dyn Bar: the size of dyn Bar cannot
// be statically determined
}
```
@ -22,8 +29,17 @@ it around as usual. Example:
```
#![feature(box_syntax)]
trait Bar {
fn f(&self);
}
impl Bar for i32 {
fn f(&self) {}
}
fn main() {
let array: &[isize] = &[1, 2, 3];
let _x: Box<&[isize]> = box array; // ok!
let b: Box<dyn Bar> = box (0 as i32);
b.f();
// ok!
}
```