Skip to content

transitive coercion to slice doesn't work for arrays #103259

Open
@oconnor663

Description

@oconnor663

The first three coercions here work fine, but the last one fails on both v1.64.0 and v1.66.0-nightly (playground link):

let vec: Vec<i32> = vec![1, 2, 3];
let _: &[i32] = &vec;

let array: [i32; 3] = [1, 2, 3];
let _: &[i32] = &array;

let vec_rc: Rc<Vec<i32>> = Rc::new(vec![1, 2, 3]);
let _: &[i32] = &vec_rc;

let array_rc: Rc<[i32; 3]> = Rc::new([1, 2, 3]);
let _: &[i32] = &array_rc;  // error[E0308]: mismatched types

Is that expected? The Reference mentions that transitive coercions are "not fully supported yet", so maybe this is a known limitation, but I wasn't able to find anything explicit about it. This old unfinished RFC might also be related, but I'm not totally sure. If there's a known limitation like "transitive unsized coercions aren't currently supported", I'd be happy to submit a PR clarifying that in the Reference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-arrayArea: `[T; N]`A-coercionsArea: implicit and explicit `expr as Type` coercionsC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions