Skip to content

Goofy error when destructuring via Box pattern #38700

Closed
@pnkfelix

Description

@pnkfelix

Consider this code:

fn main() {
    use std::boxed;
    let boxed::Box(..) = boxed::Box::new("Hello");
}

on the playpen, it yields the error:

rustc 1.16.0-nightly (4ecc85beb 2016-12-28)
error[E0308]: mismatched types
 --> <anon>:3:9
  |
3 |     let boxed::Box(..) = boxed::Box::new("Hello");
  |         ^^^^^^^^^^^^^^ expected box, found struct `std::boxed::Box`
  |
  = note: expected type `Box<&str>`
  = note:    found type `std::boxed::Box<_>`

error: aborting due to previous error

This is probably an artifact of how we partially treat Boxes as a built-in language feature within the compiler. Nonetheless, we could do better with the message here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions