Skip to content

Commit ba83b39

Browse files
committed
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).
1 parent 5217347 commit ba83b39

File tree

10 files changed

+47
-61
lines changed

10 files changed

+47
-61
lines changed

compiler/rustc_error_codes/src/error_codes/E0161.md

+21-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@ Erroneous code example:
44

55
```compile_fail,E0161
66
#![feature(box_syntax)]
7+
trait Bar {
8+
fn f(self);
9+
}
10+
11+
impl Bar for i32 {
12+
fn f(self) {}
13+
}
714
815
fn main() {
9-
let array: &[isize] = &[1, 2, 3];
10-
let _x: Box<[isize]> = box *array;
11-
// error: cannot move a value of type [isize]: the size of [isize] cannot
16+
let b: Box<dyn Bar> = box (0 as i32);
17+
b.f();
18+
// error: cannot move a value of type dyn Bar: the size of dyn Bar cannot
1219
// be statically determined
1320
}
1421
```
@@ -22,8 +29,17 @@ it around as usual. Example:
2229
```
2330
#![feature(box_syntax)]
2431
32+
trait Bar {
33+
fn f(&self);
34+
}
35+
36+
impl Bar for i32 {
37+
fn f(&self) {}
38+
}
39+
2540
fn main() {
26-
let array: &[isize] = &[1, 2, 3];
27-
let _x: Box<&[isize]> = box array; // ok!
41+
let b: Box<dyn Bar> = box (0 as i32);
42+
b.f();
43+
// ok!
2844
}
2945
```

src/test/ui/error-codes/E0161.edition.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0161]: cannot move a value of type [i32]: the size of [i32] cannot be statically determined
2-
--> $DIR/E0161.rs:22:9
1+
error[E0161]: cannot move a value of type dyn Bar: the size of dyn Bar cannot be statically determined
2+
--> $DIR/E0161.rs:29:5
33
|
4-
LL | box *x;
5-
| ^^
4+
LL | x.f();
5+
| ^
66

77
error: aborting due to previous error
88

src/test/ui/error-codes/E0161.editionul.stderr

-9
This file was deleted.

src/test/ui/error-codes/E0161.migrate.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0161]: cannot move a value of type [i32]: the size of [i32] cannot be statically determined
2-
--> $DIR/E0161.rs:22:9
1+
error[E0161]: cannot move a value of type dyn Bar: the size of dyn Bar cannot be statically determined
2+
--> $DIR/E0161.rs:29:5
33
|
4-
LL | box *x;
5-
| ^^
4+
LL | x.f();
5+
| ^
66

77
error: aborting due to previous error
88

src/test/ui/error-codes/E0161.migrateul.stderr

-9
This file was deleted.

src/test/ui/error-codes/E0161.nll.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0161]: cannot move a value of type [i32]: the size of [i32] cannot be statically determined
2-
--> $DIR/E0161.rs:22:9
1+
error[E0161]: cannot move a value of type dyn Bar: the size of dyn Bar cannot be statically determined
2+
--> $DIR/E0161.rs:29:5
33
|
4-
LL | box *x;
5-
| ^^
4+
LL | x.f();
5+
| ^
66

77
error: aborting due to previous error
88

src/test/ui/error-codes/E0161.nllul.stderr

-9
This file was deleted.

src/test/ui/error-codes/E0161.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
//[edition]edition:2018
99
//[zflagsul]compile-flags: -Z borrowck=migrate
1010
//[editionul]edition:2018
11+
//[migrateul] check-pass
12+
//[nllul] check-pass
13+
//[zflagsul] check-pass
14+
//[editionul] check-pass
1115

1216
#![allow(incomplete_features)]
1317
#![cfg_attr(nll, feature(nll))]
@@ -16,12 +20,14 @@
1620
#![cfg_attr(zflagsul, feature(unsized_locals))]
1721
#![cfg_attr(nllul, feature(unsized_locals))]
1822
#![cfg_attr(editionul, feature(unsized_locals))]
19-
#![feature(box_syntax)]
2023

21-
fn foo(x: Box<[i32]>) {
22-
box *x;
24+
trait Bar {
25+
fn f(self);
26+
}
27+
28+
fn foo(x: Box<dyn Bar>) {
29+
x.f();
2330
//[migrate,nll,zflags,edition]~^ ERROR E0161
24-
//[migrateul,nllul,zflagsul,editionul]~^^ ERROR E0161
2531
}
2632

2733
fn main() {}

src/test/ui/error-codes/E0161.zflags.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0161]: cannot move a value of type [i32]: the size of [i32] cannot be statically determined
2-
--> $DIR/E0161.rs:22:9
1+
error[E0161]: cannot move a value of type dyn Bar: the size of dyn Bar cannot be statically determined
2+
--> $DIR/E0161.rs:29:5
33
|
4-
LL | box *x;
5-
| ^^
4+
LL | x.f();
5+
| ^
66

77
error: aborting due to previous error
88

src/test/ui/error-codes/E0161.zflagsul.stderr

-9
This file was deleted.

0 commit comments

Comments
 (0)