Detect overflows of non u32 shifts
This commit is contained in:
parent
612c28004c
commit
0fa166ad7f
3 changed files with 30 additions and 1 deletions
19
src/test/ui/const-eval/shift_overflow.rs
Normal file
19
src/test/ui/const-eval/shift_overflow.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
enum Foo {
|
||||
// test that we detect overflows for non-u32 discriminants
|
||||
X = 1 << ((u32::max_value() as u64) + 1), //~ ERROR E0080
|
||||
Y = 42,
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
}
|
||||
9
src/test/ui/const-eval/shift_overflow.stderr
Normal file
9
src/test/ui/const-eval/shift_overflow.stderr
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
error[E0080]: could not evaluate enum discriminant
|
||||
--> $DIR/shift_overflow.rs:13:9
|
||||
|
|
||||
LL | X = 1 << ((u32::max_value() as u64) + 1), //~ ERROR E0080
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to shift left with overflow
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue