Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
oconnor663 opened this issue Oct 19, 2022 · 0 comments
Open

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

oconnor663 opened this issue Oct 19, 2022 · 0 comments
Labels
A-array Area: `[T; N]` A-coercions Area: implicit and explicit `expr as Type` coercions C-bug Category: This is a bug.

Comments

@oconnor663
Copy link
Contributor

oconnor663 commented Oct 19, 2022

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.

@oconnor663 oconnor663 added the C-bug Category: This is a bug. label Oct 19, 2022
@workingjubilee workingjubilee added the A-array Area: `[T; N]` label Mar 7, 2023
@Enselic Enselic added the A-coercions Area: implicit and explicit `expr as Type` coercions label Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-array Area: `[T; N]` A-coercions Area: implicit and explicit `expr as Type` coercions C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants