Skip to content

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

Open
@oconnor663

Description

@oconnor663
Contributor

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.

Activity

added
A-coercionsArea: implicit and explicit `expr as Type` coercions
on Oct 15, 2023
RodBurman

RodBurman commented on Feb 24, 2025

@RodBurman

Version 1.85.0 still produces error[E0308].

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-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

        Participants

        @Enselic@oconnor663@workingjubilee@RodBurman

        Issue actions

          transitive coercion to slice doesn't work for arrays · Issue #103259 · rust-lang/rust