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!
}
```

View file

@ -1,8 +1,8 @@
error[E0161]: cannot move a value of type [i32]: the size of [i32] cannot be statically determined
--> $DIR/E0161.rs:22:9
error[E0161]: cannot move a value of type dyn Bar: the size of dyn Bar cannot be statically determined
--> $DIR/E0161.rs:29:5
|
LL | box *x;
| ^^
LL | x.f();
| ^
error: aborting due to previous error

View file

@ -1,9 +0,0 @@
error[E0161]: cannot move a value of type [i32]: the size of [i32] cannot be statically determined
--> $DIR/E0161.rs:22:5
|
LL | box *x;
| ^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0161`.

View file

@ -1,8 +1,8 @@
error[E0161]: cannot move a value of type [i32]: the size of [i32] cannot be statically determined
--> $DIR/E0161.rs:22:9
error[E0161]: cannot move a value of type dyn Bar: the size of dyn Bar cannot be statically determined
--> $DIR/E0161.rs:29:5
|
LL | box *x;
| ^^
LL | x.f();
| ^
error: aborting due to previous error

View file

@ -1,9 +0,0 @@
error[E0161]: cannot move a value of type [i32]: the size of [i32] cannot be statically determined
--> $DIR/E0161.rs:22:5
|
LL | box *x;
| ^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0161`.

View file

@ -1,8 +1,8 @@
error[E0161]: cannot move a value of type [i32]: the size of [i32] cannot be statically determined
--> $DIR/E0161.rs:22:9
error[E0161]: cannot move a value of type dyn Bar: the size of dyn Bar cannot be statically determined
--> $DIR/E0161.rs:29:5
|
LL | box *x;
| ^^
LL | x.f();
| ^
error: aborting due to previous error

View file

@ -1,9 +0,0 @@
error[E0161]: cannot move a value of type [i32]: the size of [i32] cannot be statically determined
--> $DIR/E0161.rs:22:5
|
LL | box *x;
| ^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0161`.

View file

@ -8,6 +8,10 @@
//[edition]edition:2018
//[zflagsul]compile-flags: -Z borrowck=migrate
//[editionul]edition:2018
//[migrateul] check-pass
//[nllul] check-pass
//[zflagsul] check-pass
//[editionul] check-pass
#![allow(incomplete_features)]
#![cfg_attr(nll, feature(nll))]
@ -16,12 +20,14 @@
#![cfg_attr(zflagsul, feature(unsized_locals))]
#![cfg_attr(nllul, feature(unsized_locals))]
#![cfg_attr(editionul, feature(unsized_locals))]
#![feature(box_syntax)]
fn foo(x: Box<[i32]>) {
box *x;
trait Bar {
fn f(self);
}
fn foo(x: Box<dyn Bar>) {
x.f();
//[migrate,nll,zflags,edition]~^ ERROR E0161
//[migrateul,nllul,zflagsul,editionul]~^^ ERROR E0161
}
fn main() {}

View file

@ -1,8 +1,8 @@
error[E0161]: cannot move a value of type [i32]: the size of [i32] cannot be statically determined
--> $DIR/E0161.rs:22:9
error[E0161]: cannot move a value of type dyn Bar: the size of dyn Bar cannot be statically determined
--> $DIR/E0161.rs:29:5
|
LL | box *x;
| ^^
LL | x.f();
| ^
error: aborting due to previous error

View file

@ -1,9 +0,0 @@
error[E0161]: cannot move a value of type [i32]: the size of [i32] cannot be statically determined
--> $DIR/E0161.rs:22:5
|
LL | box *x;
| ^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0161`.