Skip to content

Commit fe5b760

Browse files
committed
Alternative workaround for unsized box error.
1 parent 3b5df01 commit fe5b760

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

compiler/rustc_mir/src/borrow_check/type_check/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,10 +2021,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20212021

20222022
Rvalue::NullaryOp(_, ty) => {
20232023
// Even with unsized locals cannot box an unsized value.
2024-
if self.unsized_feature_enabled() {
2025-
let span = body.source_info(location).span;
2026-
self.ensure_place_sized(ty, span);
2027-
}
2024+
let span = body.source_info(location).span;
2025+
self.ensure_place_sized(ty, span);
20282026

20292027
let trait_ref = ty::TraitRef {
20302028
def_id: tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(box_syntax)]
2+
// Box expression needs to be movable, and hence has to be of a Sized type.
3+
fn main() {
4+
let _x: Box<[u32]> = box { loop {} };
5+
//~^ ERROR: cannot move a value of type [u32]
6+
7+
// Check that a deduced size does not cause issues.
8+
let _y: Box<[u32]> = box [];
9+
let _z: Box<[u32; 0]> = box { loop {} };
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0161]: cannot move a value of type [u32]: the size of [u32] cannot be statically determined
2+
--> $DIR/issue-87935-unsized-box-expr.rs:4:26
3+
|
4+
LL | let _x: Box<[u32]> = box { loop {} };
5+
| ^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0161`.

0 commit comments

Comments
 (0)