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

Array ref to slice coercion fails in generic context #34240

Closed
abonander opened this issue Jun 12, 2016 · 2 comments
Closed

Array ref to slice coercion fails in generic context #34240

abonander opened this issue Jun 12, 2016 · 2 comments

Comments

@abonander
Copy link
Contributor

abonander commented Jun 12, 2016

Simplest test case I could come up with:

struct Generic<V> {
    val: V,
}

struct Concrete { 
    val: &'static [i32],
}

// Produces the error
const GENERIC: Generic<&'static [i32]> = Generic { val: &[0] };

const CONCRETE: Concrete = Concrete { val : &[0] };

// Works by coercing in a concrete context
const WORKAROUND: Generic<&'static [i32]> = Generic { val: {const VAL: &'static [i32] = &[0]; VAL } };
// (Type ascription works as well but is gated)

Playground

Produces the following error on stable and nightly (new nightly formatting):

error: mismatched types [--explain E0308]
 --> <anon>:9:42
9 |> const GENERIC: Generic<&'static [i32]> = Generic { val: &[0] };
  |>                                          ^^^^^^^^^^^^^^^^^^^^^ expected slice, found array of 1 elements
note: expected type `Generic<&'static [i32]>`
note:    found type `Generic<&[_; 1]>`

error: aborting due to previous error

Comment out line 9 and it compiles successfully.

I did my best to search for a duplicate but nothing came up, although something tells me this is a known issue already. Sorry if it is actually duplicate.

Note: this is not restricted to generic context, it's just where I discovered it.

@abonander abonander changed the title Array ref to slice coercion fails in const + generic context Array ref to slice coercion fails in generic context Jun 12, 2016
@abonander
Copy link
Contributor Author

Possible duplicate of #31260, but I'll leave it open for ruling.

@abonander
Copy link
Contributor Author

Nevermind, I'll just comment there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant