]> git.lizzy.rs Git - rust.git/blob - src/test/run-fail/bug-2470-bounds-check-overflow-2.rs
rollup merge of #18407 : thestinger/arena
[rust.git] / src / test / run-fail / bug-2470-bounds-check-overflow-2.rs
1 // Copyright 2012-2014 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
11 // ignore-test
12 // error-pattern:index out of bounds
13
14 use std::uint;
15
16 fn main() {
17     let x = vec!(1u,2u,3u);
18
19     // This should cause a bounds-check panic, but may not if we do our
20     // bounds checking by comparing a scaled index value to the vector's
21     // length (in bytes), because the scaling of the index will cause it to
22     // wrap around to a small number.
23
24     let idx = uint::MAX & !(uint::MAX >> 1u);
25     println!("ov2 idx = 0x%x", idx);
26
27     // This should panic.
28     println!("ov2 0x%x",  x[idx]);
29 }