Skip to content

Odd "mismatched types" error message #9249

@jruderman

Description

@jruderman
Contributor
static DATA:&'static [&'static str] = ["my string"];
fn main() { }

The error message seems to confuse lifetime with size:

error: mismatched types:
    expected `&'static [&'static str]` 
    but found `[&'static str, .. 1]`
    ([] storage differs: expected &'static  but found 1)

Also note the extra space after &'static.

Activity

alexcrichton

alexcrichton commented on Mar 18, 2014

@alexcrichton
Member

Closing as working as intended

The right hand side has type [&'static str, ..1] which will normally coerce to a &'static [&'static str] in code, but in statics there is no coercion. The right hand side will have to be &["my string"] to work.

jruderman

jruderman commented on Mar 19, 2014

@jruderman
ContributorAuthor

The error message could use some improvement.

ftxqxd

ftxqxd commented on Oct 4, 2014

@ftxqxd
Contributor

The given test case now compiles. Can this be closed, or is there some other case where coercion doesn’t occur?

alexcrichton

alexcrichton commented on Oct 6, 2014

@alexcrichton
Member

Flagging as needstest

added
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
on Oct 6, 2014
added a commit that references this issue on Oct 18, 2014
41a7910
added a commit that references this issue on Jul 28, 2022
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-diagnosticsArea: Messages for errors, warnings, and lintsE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @alexcrichton@jruderman@huonw@ftxqxd

      Issue actions

        Odd "mismatched types" error message · Issue #9249 · rust-lang/rust