]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/const-err.rs
New upstream version 1.24.1+dfsg1
[rustc.git] / src / test / compile-fail / const-err.rs
CommitLineData
b039eaaf
SL
1// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
3157f602
XL
11// compile-flags: -Zforce-overflow-checks=on
12
a7813a04
XL
13// these errors are not actually "const_err", they occur in trans/consts
14// and are unconditional warnings that can't be denied or allowed
15
54a0048b 16#![allow(exceeding_bitshifts)]
a7813a04 17#![allow(const_err)]
b039eaaf
SL
18
19fn black_box<T>(_: T) {
20 unimplemented!()
21}
22
a7813a04
XL
23// Make sure that the two uses get two errors.
24const FOO: u8 = [5u8][1];
5bcae85e
SL
25//~^ ERROR constant evaluation error
26//~| index out of bounds: the len is 1 but the index is 1
a7813a04 27
b039eaaf
SL
28fn main() {
29 let a = -std::i8::MIN;
5bcae85e
SL
30 //~^ WARN this expression will panic at run-time
31 //~| attempt to negate with overflow
b039eaaf 32 let b = 200u8 + 200u8 + 200u8;
5bcae85e 33 //~^ WARN this expression will panic at run-time
abe05a73 34 //~^^ WARN this expression will panic at run-time
5bcae85e 35 //~| attempt to add with overflow
b039eaaf 36 let c = 200u8 * 4;
5bcae85e
SL
37 //~^ WARN this expression will panic at run-time
38 //~| attempt to multiply with overflow
b039eaaf 39 let d = 42u8 - (42u8 + 1);
5bcae85e
SL
40 //~^ WARN this expression will panic at run-time
41 //~| attempt to subtract with overflow
54a0048b 42 let _e = [5u8][1];
5bcae85e
SL
43 //~^ WARN this expression will panic at run-time
44 //~| index out of bounds: the len is 1 but the index is 1
b039eaaf
SL
45 black_box(a);
46 black_box(b);
47 black_box(c);
48 black_box(d);
a7813a04
XL
49
50 black_box((FOO, FOO));
b039eaaf 51}