Skip to content

const_eval funkiness with overflow #13768

Description

@alexcrichton

Case 1

fn main() {
    const N: u8 = !0;
    let _foo: [u8; 255] = [0; N as usize];
}

playpen

<anon>:3:27: 3:42 error: mismatched types:
 expected `[u8; 255]`,
    found `[u8; 18446744073709551615]`
(expected an array with a fixed size of 255 elements,
    found one with 18446744073709551615 elements) [E0308]
<anon>:3     let _foo: [u8; 255] = [0; N as usize];
                                   ^~~~~~~~~~~~~~~
error: aborting due to previous error

Case 2

fn main() {
    const N: u8 = 0 as u8 - 1 as u8;
    let _foo: [u8; 255] = [0; N as usize];
}

playpen

<anon>:3:31: 3:41 error: expected constant integer for repeat count, found non-constant expression [E0307]
<anon>:3     let _foo: [u8; 255] = [0; N as usize];
                                       ^~~~~~~~~~
<anon>:3:27: 3:42 error: mismatched types:
 expected `[u8; 255]`,
    found `[u8; 0]`
(expected an array with a fixed size of 255 elements,
    found one with 0 elements) [E0308]
<anon>:3     let _foo: [u8; 255] = [0; N as usize];
                                   ^~~~~~~~~~~~~~~
error: aborting due to 2 previous errors```

cc #13763

----

Update: revised test cases to run in playpen on modern rust, and updated error messages accordingly.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions