diff options
| author | bors <bors@rust-lang.org> | 2021-08-20 23:04:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-08-20 23:04:57 +0000 |
| commit | 1e3d632f8f921d03ccc5b71d97decf980df7dbe4 (patch) | |
| tree | 7bc2ba77dbc9b6e8ff164d449f2d0fe6d1ac17cf /compiler/rustc_error_codes/src | |
| parent | a0035916e01d8e644ccd44554c57f0874cef8c8c (diff) | |
| parent | c75a93023a77dc9c468519e79a1206e5b56b33b9 (diff) | |
| download | rust-1e3d632f8f921d03ccc5b71d97decf980df7dbe4.tar.gz rust-1e3d632f8f921d03ccc5b71d97decf980df7dbe4.zip | |
Auto merge of #88087 - jesyspa:issue-87935-box, r=jackh726
Check that a box expression's type is Sized This resolves [issue 87935](https://github.com/rust-lang/rust/issues/87935). This makes E0161 (move from an unsized rvalue) much less common. I've replaced the test to use [this case](https://github.com/rust-lang/rust/blob/master/src/test/ui/object-safety/object-safety-by-value-self-use.rs), when a boxed `dyn` trait is passed by value, but that isn't an error when `unsized_locals` is enabled. I think it may be possible to get rid of E0161 entirely by checking that case earlier, but I'm not sure if that's desirable?
Diffstat (limited to 'compiler/rustc_error_codes/src')
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0161.md | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0161.md b/compiler/rustc_error_codes/src/error_codes/E0161.md index c2e2f0240f4..ebd2c97698b 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0161.md +++ b/compiler/rustc_error_codes/src/error_codes/E0161.md @@ -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! } ``` |
