Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Box "doesn't have a size known at compile-time" wrong diagnostic #63143

Closed
spastorino opened this issue Jul 30, 2019 · 1 comment · Fixed by #64498
Closed

Box "doesn't have a size known at compile-time" wrong diagnostic #63143

spastorino opened this issue Jul 30, 2019 · 1 comment · Fixed by #64498
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@spastorino
Copy link
Member

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.

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 30, 2019
@estebank
Copy link
Contributor

There are multiple cases of this, where we point at the method ident instead of the correct argument, as we should in this case. It will require some reworking on how we deal with this. The solution will fix a swath of similar issues. Sadly I think it'll be a medium size undertaking to fix.

Centril added a commit to Centril/rust that referenced this issue Sep 20, 2019
When possible point at argument causing item obligation failure

Fix rust-lang#41781, fix rust-lang#42855, fix rust-lang#46658, fix rust-lang#48099, fix rust-lang#63143.
@bors bors closed this as completed in 7225264 Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants