Skip to content

Commit

Permalink
Rollup merge of rust-lang#22504 - GuillaumeGomez:audit-integer-libcor…
Browse files Browse the repository at this point in the history
…e, r=Manishearth

 Part of rust-lang#22240.
  • Loading branch information
Manishearth committed Mar 1, 2015
2 parents 1576142 + df12658 commit fb19cd7
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 122 deletions.
4 changes: 1 addition & 3 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
//! distribution.
//!
//! * `rust_begin_unwind` - This function takes three arguments, a
//! `fmt::Arguments`, a `&str`, and a `uint`. These three arguments dictate
//! `fmt::Arguments`, a `&str`, and a `usize`. These three arguments dictate
//! the panic message, the file at which panic was invoked, and the line.
//! It is up to consumers of this core library to define this panic
//! function; it is only required to never return.
Expand Down Expand Up @@ -88,14 +88,12 @@ mod int_macros;
#[macro_use]
mod uint_macros;

#[path = "num/int.rs"] pub mod int;
#[path = "num/isize.rs"] pub mod isize;
#[path = "num/i8.rs"] pub mod i8;
#[path = "num/i16.rs"] pub mod i16;
#[path = "num/i32.rs"] pub mod i32;
#[path = "num/i64.rs"] pub mod i64;

#[path = "num/uint.rs"] pub mod uint;
#[path = "num/usize.rs"] pub mod usize;
#[path = "num/u8.rs"] pub mod u8;
#[path = "num/u16.rs"] pub mod u16;
Expand Down
21 changes: 0 additions & 21 deletions src/libcore/num/int.rs

This file was deleted.

20 changes: 0 additions & 20 deletions src/libcore/num/uint.rs

This file was deleted.

14 changes: 7 additions & 7 deletions src/libcoretest/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use core::iter::*;
use core::iter::order::*;
use core::iter::MinMaxResult::*;
use core::num::SignedInt;
use core::uint;
use core::usize;
use core::cmp;

use test::Bencher;
Expand Down Expand Up @@ -292,7 +292,7 @@ fn test_unfoldr() {
fn test_cycle() {
let cycle_len = 3;
let it = count(0, 1).take(cycle_len).cycle();
assert_eq!(it.size_hint(), (uint::MAX, None));
assert_eq!(it.size_hint(), (usize::MAX, None));
for (i, x) in it.take(100).enumerate() {
assert_eq!(i % cycle_len, x);
}
Expand Down Expand Up @@ -365,19 +365,19 @@ fn test_iterator_size_hint() {
let v2 = &[10, 11, 12];
let vi = v.iter();

assert_eq!(c.size_hint(), (uint::MAX, None));
assert_eq!(c.size_hint(), (usize::MAX, None));
assert_eq!(vi.clone().size_hint(), (10, Some(10)));

assert_eq!(c.clone().take(5).size_hint(), (5, Some(5)));
assert_eq!(c.clone().skip(5).size_hint().1, None);
assert_eq!(c.clone().take_while(|_| false).size_hint(), (0, None));
assert_eq!(c.clone().skip_while(|_| false).size_hint(), (0, None));
assert_eq!(c.clone().enumerate().size_hint(), (uint::MAX, None));
assert_eq!(c.clone().chain(vi.clone().cloned()).size_hint(), (uint::MAX, None));
assert_eq!(c.clone().enumerate().size_hint(), (usize::MAX, None));
assert_eq!(c.clone().chain(vi.clone().cloned()).size_hint(), (usize::MAX, None));
assert_eq!(c.clone().zip(vi.clone()).size_hint(), (10, Some(10)));
assert_eq!(c.clone().scan(0, |_,_| Some(0)).size_hint(), (0, None));
assert_eq!(c.clone().filter(|_| false).size_hint(), (0, None));
assert_eq!(c.clone().map(|_| 0).size_hint(), (uint::MAX, None));
assert_eq!(c.clone().map(|_| 0).size_hint(), (usize::MAX, None));
assert_eq!(c.filter_map(|_| Some(0)).size_hint(), (0, None));

assert_eq!(vi.clone().take(5).size_hint(), (5, Some(5)));
Expand Down Expand Up @@ -753,7 +753,7 @@ fn test_range() {

assert_eq!((0..100).size_hint(), (100, Some(100)));
// this test is only meaningful when sizeof uint < sizeof u64
assert_eq!((uint::MAX - 1..uint::MAX).size_hint(), (1, Some(1)));
assert_eq!((usize::MAX - 1..usize::MAX).size_hint(), (1, Some(1)));
assert_eq!((-10..-1).size_hint(), (9, Some(9)));
assert_eq!((-1..-10).size_hint(), (0, Some(0)));
}
Expand Down
11 changes: 0 additions & 11 deletions src/libcoretest/num/int.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/libcoretest/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ macro_rules! int_module { ($T:ty, $T_i:ident) => (
#[cfg(test)]
mod tests {
use core::$T_i::*;
use core::int;
use core::isize;
use core::num::{FromStrRadix, Int, SignedInt};
use core::ops::{Shl, Shr, Not, BitXor, BitAnd, BitOr};
use num;
Expand Down Expand Up @@ -153,7 +153,7 @@ mod tests {
fn test_signed_checked_div() {
assert!(10.checked_div(2) == Some(5));
assert!(5.checked_div(0) == None);
assert!(int::MIN.checked_div(-1) == None);
assert!(isize::MIN.checked_div(-1) == None);
}

#[test]
Expand Down
2 changes: 0 additions & 2 deletions src/libcoretest/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ mod i8;
mod i16;
mod i32;
mod i64;
mod int;

#[macro_use]
mod uint_macros;
Expand All @@ -30,7 +29,6 @@ mod u8;
mod u16;
mod u32;
mod u64;
mod uint;

/// Helper function for testing numeric operations
pub fn test_num<T>(ten: T, two: T) where
Expand Down
11 changes: 0 additions & 11 deletions src/libcoretest/num/uint.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/libgetopts/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ fn test_split_within() {
"little lamb".to_string(),
"Little lamb".to_string()
]);
t("\nMary had a little lamb\nLittle lamb\n", ::std::uint::MAX,
t("\nMary had a little lamb\nLittle lamb\n", ::std::usize::MAX,
&["Mary had a little lamb\nLittle lamb".to_string()]);
}

Expand Down
24 changes: 12 additions & 12 deletions src/librand/rand_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
use core::prelude::*;
use core::char;
use core::int;
use core::uint;
use core::isize;
use core::usize;

use {Rand,Rng};

impl Rand for int {
impl Rand for isize {
#[inline]
fn rand<R: Rng>(rng: &mut R) -> int {
if int::BITS == 32 {
rng.gen::<i32>() as int
fn rand<R: Rng>(rng: &mut R) -> isize {
if isize::BITS == 32 {
rng.gen::<i32>() as isize
} else {
rng.gen::<i64>() as int
rng.gen::<i64>() as isize
}
}
}
Expand Down Expand Up @@ -56,13 +56,13 @@ impl Rand for i64 {
}
}

impl Rand for uint {
impl Rand for usize {
#[inline]
fn rand<R: Rng>(rng: &mut R) -> uint {
if uint::BITS == 32 {
rng.gen::<u32>() as uint
fn rand<R: Rng>(rng: &mut R) -> usize {
if usize::BITS == 32 {
rng.gen::<u32>() as usize
} else {
rng.gen::<u64>() as uint
rng.gen::<u64>() as usize
}
}
}
Expand Down
40 changes: 20 additions & 20 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
//! enclosing function. On the way down the tree, it identifies those AST
//! nodes and variable IDs that will be needed for the liveness analysis
//! and assigns them contiguous IDs. The liveness id for an AST node is
//! called a `live_node` (it's a newtype'd uint) and the id for a variable
//! is called a `variable` (another newtype'd uint).
//! called a `live_node` (it's a newtype'd usize) and the id for a variable
//! is called a `variable` (another newtype'd usize).
//!
//! On the way back up the tree, as we are about to exit from a function
//! declaration we allocate a `liveness` instance. Now that we know
Expand Down Expand Up @@ -118,7 +118,7 @@ use middle::ty::ClosureTyper;
use lint;
use util::nodemap::NodeMap;

use std::{fmt, old_io, uint};
use std::{fmt, old_io, usize};
use std::rc::Rc;
use std::iter::repeat;
use syntax::ast::{self, NodeId, Expr};
Expand All @@ -138,17 +138,17 @@ enum LoopKind<'a> {
}

#[derive(Copy, PartialEq)]
struct Variable(uint);
struct Variable(usize);

#[derive(Copy, PartialEq)]
struct LiveNode(uint);
struct LiveNode(usize);

impl Variable {
fn get(&self) -> uint { let Variable(v) = *self; v }
fn get(&self) -> usize { let Variable(v) = *self; v }
}

impl LiveNode {
fn get(&self) -> uint { let LiveNode(v) = *self; v }
fn get(&self) -> usize { let LiveNode(v) = *self; v }
}

impl Clone for LiveNode {
Expand Down Expand Up @@ -232,11 +232,11 @@ impl fmt::Debug for Variable {

impl LiveNode {
fn is_valid(&self) -> bool {
self.get() != uint::MAX
self.get() != usize::MAX
}
}

fn invalid_node() -> LiveNode { LiveNode(uint::MAX) }
fn invalid_node() -> LiveNode { LiveNode(usize::MAX) }

struct CaptureInfo {
ln: LiveNode,
Expand All @@ -260,8 +260,8 @@ enum VarKind {
struct IrMaps<'a, 'tcx: 'a> {
tcx: &'a ty::ctxt<'tcx>,

num_live_nodes: uint,
num_vars: uint,
num_live_nodes: usize,
num_vars: usize,
live_node_map: NodeMap<LiveNode>,
variable_map: NodeMap<Variable>,
capture_info_map: NodeMap<Rc<Vec<CaptureInfo>>>,
Expand Down Expand Up @@ -540,9 +540,9 @@ struct Specials {
clean_exit_var: Variable
}

static ACC_READ: uint = 1;
static ACC_WRITE: uint = 2;
static ACC_USE: uint = 4;
static ACC_READ: u32 = 1;
static ACC_WRITE: u32 = 2;
static ACC_USE: u32 = 4;

struct Liveness<'a, 'tcx: 'a> {
ir: &'a mut IrMaps<'a, 'tcx>,
Expand Down Expand Up @@ -631,7 +631,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
succ
}

fn idx(&self, ln: LiveNode, var: Variable) -> uint {
fn idx(&self, ln: LiveNode, var: Variable) -> usize {
ln.get() * self.ir.num_vars + var.get()
}

Expand Down Expand Up @@ -670,7 +670,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}

fn indices2<F>(&mut self, ln: LiveNode, succ_ln: LiveNode, mut op: F) where
F: FnMut(&mut Liveness<'a, 'tcx>, uint, uint),
F: FnMut(&mut Liveness<'a, 'tcx>, usize, usize),
{
let node_base_idx = self.idx(ln, Variable(0));
let succ_base_idx = self.idx(succ_ln, Variable(0));
Expand All @@ -684,7 +684,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
ln: LiveNode,
mut test: F)
-> old_io::IoResult<()> where
F: FnMut(uint) -> LiveNode,
F: FnMut(usize) -> LiveNode,
{
let node_base_idx = self.idx(ln, Variable(0));
for var_idx in 0..self.ir.num_vars {
Expand Down Expand Up @@ -807,7 +807,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}

// Either read, write, or both depending on the acc bitset
fn acc(&mut self, ln: LiveNode, var: Variable, acc: uint) {
fn acc(&mut self, ln: LiveNode, var: Variable, acc: u32) {
debug!("{:?} accesses[{:x}] {:?}: {}",
ln, acc, var, self.ln_str(ln));

Expand Down Expand Up @@ -1283,7 +1283,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}

// see comment on propagate_through_lvalue()
fn write_lvalue(&mut self, expr: &Expr, succ: LiveNode, acc: uint)
fn write_lvalue(&mut self, expr: &Expr, succ: LiveNode, acc: u32)
-> LiveNode {
match expr.node {
ast::ExprPath(..) => {
Expand All @@ -1298,7 +1298,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
}

fn access_path(&mut self, expr: &Expr, succ: LiveNode, acc: uint)
fn access_path(&mut self, expr: &Expr, succ: LiveNode, acc: u32)
-> LiveNode {
match self.ir.tcx.def_map.borrow()[expr.id].full_def() {
DefLocal(nid) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ fn pick_column_to_specialize(def_map: &DefMap, m: &[Match]) -> Option<uint> {

// Irrefutable columns always go first, they'd only be duplicated in the branches.
if total_score == 0 {
std::uint::MAX
std::usize::MAX
} else {
total_score
}
Expand Down
4 changes: 1 addition & 3 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
#![feature(box_syntax)]
#![feature(collections)]
#![feature(core)]
#![feature(int_uint)]
#![feature(hash)]
#![feature(lang_items)]
#![feature(libc)]
#![feature(linkage, thread_local, asm)]
Expand Down Expand Up @@ -221,14 +221,12 @@ mod int_macros;
mod uint_macros;

#[path = "num/isize.rs"] pub mod isize;
pub use isize as int;
#[path = "num/i8.rs"] pub mod i8;
#[path = "num/i16.rs"] pub mod i16;
#[path = "num/i32.rs"] pub mod i32;
#[path = "num/i64.rs"] pub mod i64;

#[path = "num/usize.rs"] pub mod usize;
pub use usize as uint;
#[path = "num/u8.rs"] pub mod u8;
#[path = "num/u16.rs"] pub mod u16;
#[path = "num/u32.rs"] pub mod u32;
Expand Down
Loading

0 comments on commit fb19cd7

Please sign in to comment.