Rollup merge of #22504 - GuillaumeGomez:audit-integer-libcore, r=Manishearth

Part of #22240.
This commit is contained in:
Manish Goregaokar 2015-03-02 03:53:41 +05:30
commit fb19cd7fb7
17 changed files with 53 additions and 122 deletions

View file

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::{int, i8, i16, i32, i64};
use std::{isize, i8, i16, i32, i64};
use std::thread;
fn main() {
assert!(thread::spawn(move|| { int::MIN / -1; }).join().is_err());
assert!(thread::spawn(move|| { isize::MIN / -1; }).join().is_err());
//~^ ERROR attempted to divide with overflow in a constant expression
assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err());
//~^ ERROR attempted to divide with overflow in a constant expression
@ -32,7 +32,7 @@ fn main() {
//~^ ERROR attempted to divide by zero in a constant expression
assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err());
//~^ ERROR attempted to divide by zero in a constant expression
assert!(thread::spawn(move|| { int::MIN % -1; }).join().is_err());
assert!(thread::spawn(move|| { isize::MIN % -1; }).join().is_err());
//~^ ERROR attempted remainder with overflow in a constant expression
assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err());
//~^ ERROR attempted remainder with overflow in a constant expression

View file

@ -9,7 +9,7 @@
// except according to those terms.
fn main() {
pub use std::uint; //~ ERROR: visibility has no effect
pub use std::usize; //~ ERROR: visibility has no effect
pub struct A; //~ ERROR: visibility has no effect
pub enum B {} //~ ERROR: visibility has no effect
pub trait C { //~ ERROR: visibility has no effect

View file

@ -10,10 +10,10 @@
// error-pattern:index out of bounds: the len is 3 but the index is
use std::uint;
use std::usize;
use std::mem::size_of;
fn main() {
let xs = [1, 2, 3];
xs[uint::MAX / size_of::<int>() + 1];
xs[usize::MAX / size_of::<isize>() + 1];
}

View file

@ -11,11 +11,11 @@
// error-pattern:capacity overflow
use std::collections::hash_map::HashMap;
use std::uint;
use std::usize;
use std::mem::size_of;
fn main() {
let threshold = uint::MAX / size_of::<(u64, u64, u64)>();
let threshold = usize::MAX / size_of::<(u64, u64, u64)>();
let mut h = HashMap::<u64, u64>::with_capacity(threshold + 100);
h.insert(0, 0);
}