Skip to content

Coercion sites are not consistent between struct tuples and structs #31260

Closed

Description

pub struct Struct<K: 'static> {
    pub field: K,
}

static STRUCT: Struct<&'static [u8]> = Struct {
    field: &[1]
};

pub struct Tuple<K: 'static>(K);

static TUPLE: Tuple<&'static [u8]> = Tuple(&[1]);

STRUCT fails to type check, while TUPLE succeeds.

<anon>:7:40: 9:2 error: mismatched types:
 expected `Struct<&'static [u8]>`,
    found `Struct<&[_; 1]>`
(expected slice,
    found array of 1 elements) [E0308]
<anon>:7 static STRUCT: Struct<&'static [u8]> = Struct {
<anon>:8     field: &[1]
<anon>:9 };
<anon>:7:40: 9:2 help: see the detailed explanation for E0308
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions