Skip to content

Cannot do x as Box<[T]> for x: Box<[T; k]> #22403

Closed
@pnkfelix

Description

@pnkfelix

This explicit cast does not work:

fn main() {
    let x = Box::new([1, 2, 3]);
    let y = x as Box<[i32]>;

    println!("y: {:?}", y);
}

However, this implicit coercion does work:

fn main() {
    let x = Box::new([1, 2, 3]);
    let y: Box<[i32]> = x;

    println!("y: {:?}", y);
}

It is unfortunate, because I would like the overloaded-box inference to work for expr as Box<[T]> in the same manner that it does for expr as Box<Trait>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions