Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

const_eval funkiness with overflow #13768

Closed
alexcrichton opened this issue Apr 25, 2014 · 9 comments
Closed

const_eval funkiness with overflow #13768

alexcrichton opened this issue Apr 25, 2014 · 9 comments

Comments

@alexcrichton
Copy link
Member

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.
alexcrichton added a commit to alexcrichton/rust that referenced this issue Apr 25, 2014
This addresses the ICE from rust-lang#13763, but it does not allow the test to compile,
due to rust-lang#13768. An alternate test was checked in in the meantime.

Closes rust-lang#13763
bors added a commit that referenced this issue Apr 26, 2014
This addresses the ICE from #13763, but it does not allow the test to compile,
due to #13768. An alternate test was checked in in the meantime.

Closes #13763
@huonw
Copy link
Member

huonw commented Nov 21, 2014

Triage: no change.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 19, 2015

error message changed:

fn main() {                          
    const N: u8 = 0 - 1;            
    let _foo: [u8; 255] = [0; N as usize];
}
<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];
                                   ^~~~~~~~~~~~~~~

@oli-obk
Copy link
Contributor

oli-obk commented Feb 19, 2015

Note: the error about the array types appears before an error about the array length:

fn main() {                          
    const N: u8 = 0;
    const M: u8 = 1;
    const O: u8 = N - M;
    const P: usize = O;
    let _foo: [u8; 255] = [0; P];
}
<anon>:6:27: 6:33 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>:6     let _foo: [u8; 255] = [0; P];
                                   ^~~~~~
<anon>:5:22: 5:23 error: mismatched types:
 expected `usize`,
    found `u8`
(expected usize,
    found u8) [E0308]
<anon>:5     const P: usize = O;
                              ^

@pnkfelix
Copy link
Member

(Note that if I ever get #22532 to the point where its bootstrapping rustc, I imagine we'll be forced to resolve this in some fashion. :) )

@pnkfelix
Copy link
Member

Hmm, apparently my previous assertion was wrong; I expected to see overflowing constant evaluation fail within rustc, but I have not seen that in my work on #22532. (Does LLVM do the constant evaluation on our behalf? Shows what I know...)

@pnkfelix
Copy link
Member

(ah, maybe its because my test was using const-eval adding two u8's with overflow; its possible we use usize arithmetic instead.)

@pnkfelix
Copy link
Member

(just making a note here that I updated description, so that triage script skips this bug for a while longer.)

@pnkfelix
Copy link
Member

cc #23897

@nagisa
Copy link
Member

nagisa commented Aug 11, 2016

Not an issue anymore. Should be closed.

@eddyb eddyb closed this as completed Aug 11, 2016
flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 20, 2025
fixes rust-lang#13768

The existing implemention forgets to handle the binding mode (i.e. `ref`
and `ref mut`), so I just modified it to cover these cases.

changelog: [`manual_let_else`]: fix missing binding mode
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants