Closed
Description
If I do ...
fn main() {
let x = "hello";
let y = Box::new(*x);
}
I get the following error ...
--> src/main.rs:3:13
|
3 | let y = Box::new(*x);
| ^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `str`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: required by `std::boxed::Box::<T>::new`
I think the right error should be ...
--> src/main.rs:3:13
|
3 | let y = Box::new(*x);
| ^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `str`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: required by `std::boxed::Box::<T>::new`
Is not that Box
is not Sized
, the problem is that the parameter of the Box
's new
function is not Sized
. So the last note in the error is important and also kind of lost in a lot of noise.
Possibly related to #61860.