Skip to content

Constants behave differently depending on the way they're initialized. #28315

Closed
@tbu-

Description

@tbu-

I can't match using a constant that was initialized using a byte string literal:

const ARRAY1: [u8; 0] = [];
const ARRAY2: [u8; 0] = *b"";

fn main() {
    match [] {
        ARRAY1 => {}
        ARRAY2 => {}
    }
}

This gets an error:

a.rs:2:25: 2:29 error: constant evaluation error: unsupported constant expr
a.rs:2 const ARRAY2: [u8; 0] = *b"";
                               ^~~~
a.rs:7:9: 7:15 note: in pattern here
a.rs:7         ARRAY2 => {}
               ^~~~~~
a.rs:2:25: 2:29 error: unsupported constant expr
a.rs:2 const ARRAY2: [u8; 0] = *b"";
                               ^~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions