Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

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

Closed

Description

@spastorino

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.

Activity

  1. added
    A-diagnostics
    C-bug
    T-compiler
    on Jul 30, 2019
  2. estebank commented on Jul 30, 2019

    @estebank
    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.

  3. added a commit that references this issue on Sep 20, 2019
  4. added a commit that references this issue on Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsC-bugT-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions