-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #88087 - jesyspa:issue-87935-box, r=jackh726
Check that a box expression's type is Sized This resolves [issue 87935](#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?
- Loading branch information
Showing
18 changed files
with
90 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,21 @@ | ||
error[E0161]: cannot move a value of type str: the size of str cannot be statically determined | ||
error[E0277]: the size for values of type `str` cannot be known at compilation time | ||
--> $DIR/dst-rvalue.rs:6:28 | ||
| | ||
LL | let _x: Box<str> = box *"hello world"; | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error[E0161]: cannot move a value of type [isize]: the size of [isize] cannot be statically determined | ||
--> $DIR/dst-rvalue.rs:11:32 | ||
| ^^^^^^^^^^^^^^ doesn't have a size known at compile-time | ||
| | ||
LL | let _x: Box<[isize]> = box *array; | ||
| ^^^^^^ | ||
= help: the trait `Sized` is not implemented for `str` | ||
= note: the type of a box expression must have a statically known size | ||
|
||
error[E0507]: cannot move out of a shared reference | ||
--> $DIR/dst-rvalue.rs:6:28 | ||
| | ||
LL | let _x: Box<str> = box *"hello world"; | ||
| ^^^^^^^^^^^^^^ move occurs because value has type `str`, which does not implement the `Copy` trait | ||
|
||
error[E0508]: cannot move out of type `[isize]`, a non-copy slice | ||
--> $DIR/dst-rvalue.rs:11:32 | ||
error[E0277]: the size for values of type `[isize]` cannot be known at compilation time | ||
--> $DIR/dst-rvalue.rs:10:32 | ||
| | ||
LL | let _x: Box<[isize]> = box *array; | ||
| ^^^^^^ | ||
| | | ||
| cannot move out of here | ||
| move occurs because `*array` has type `[isize]`, which does not implement the `Copy` trait | ||
| ^^^^^^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `[isize]` | ||
= note: the type of a box expression must have a statically known size | ||
|
||
error: aborting due to 4 previous errors | ||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0161, E0507, E0508. | ||
For more information about an error, try `rustc --explain E0161`. | ||
For more information about this error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![feature(box_syntax)] | ||
// Box expression needs to be movable, and hence has to be of a Sized type. | ||
fn main() { | ||
let _x: Box<[u32]> = box { loop {} }; | ||
//~^ ERROR: the size for values of type `[u32]` cannot be known at compilation time | ||
|
||
// Check that a deduced size does not cause issues. | ||
let _y: Box<[u32]> = box []; | ||
let _z: Box<[u32; 0]> = box { loop {} }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0277]: the size for values of type `[u32]` cannot be known at compilation time | ||
--> $DIR/issue-87935-unsized-box-expr.rs:4:30 | ||
| | ||
LL | let _x: Box<[u32]> = box { loop {} }; | ||
| ^^^^^^^^^^^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `[u32]` | ||
= note: the type of a box expression must have a statically known size | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |