Skip to content

Commit 3ca5439

Browse files
committed
Rollup merge of rust-lang#22700 - nick29581:ints_hash, r=alexcrichton
fmt and hash are pretty straightforward I think. sync is a bit more complex. I thought one or two of the `isize`s ought to be `i32`s, but that would require a bunch of casting (the root cause being the lack of atomics other than isize/usize). r? @alexcrichton
2 parents eaacc7a + 1db684f commit 3ca5439

22 files changed

+253
-232
lines changed

src/libcore/fmt/float.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ pub enum ExponentFormat {
4040
pub enum SignificantDigits {
4141
/// At most the given number of digits will be printed, truncating any
4242
/// trailing zeroes.
43-
DigMax(uint),
43+
DigMax(usize),
4444

4545
/// Precisely the given number of digits will be printed.
46-
DigExact(uint)
46+
DigExact(usize)
4747
}
4848

4949
/// How to emit the sign of a number.
@@ -240,27 +240,27 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
240240
// If reached left end of number, have to
241241
// insert additional digit:
242242
if i < 0
243-
|| buf[i as uint] == b'-'
244-
|| buf[i as uint] == b'+' {
245-
for j in (i as uint + 1..end).rev() {
243+
|| buf[i as usize] == b'-'
244+
|| buf[i as usize] == b'+' {
245+
for j in (i as usize + 1..end).rev() {
246246
buf[j + 1] = buf[j];
247247
}
248-
buf[(i + 1) as uint] = value2ascii(1);
248+
buf[(i + 1) as usize] = value2ascii(1);
249249
end += 1;
250250
break;
251251
}
252252

253253
// Skip the '.'
254-
if buf[i as uint] == b'.' { i -= 1; continue; }
254+
if buf[i as usize] == b'.' { i -= 1; continue; }
255255

256256
// Either increment the digit,
257257
// or set to 0 if max and carry the 1.
258-
let current_digit = ascii2value(buf[i as uint]);
258+
let current_digit = ascii2value(buf[i as usize]);
259259
if current_digit < (radix - 1) {
260-
buf[i as uint] = value2ascii(current_digit+1);
260+
buf[i as usize] = value2ascii(current_digit+1);
261261
break;
262262
} else {
263-
buf[i as uint] = value2ascii(0);
263+
buf[i as usize] = value2ascii(0);
264264
i -= 1;
265265
}
266266
}
@@ -311,7 +311,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
311311

312312
struct Filler<'a> {
313313
buf: &'a mut [u8],
314-
end: &'a mut uint,
314+
end: &'a mut usize,
315315
}
316316

317317
impl<'a> fmt::Write for Filler<'a> {

src/libcore/fmt/mod.rs

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,14 @@ pub trait Write {
110110
/// traits.
111111
#[stable(feature = "rust1", since = "1.0.0")]
112112
pub struct Formatter<'a> {
113-
flags: uint,
113+
#[cfg(not(stage0))]
114+
flags: u32,
115+
#[cfg(stage0)]
116+
flags: usize,
114117
fill: char,
115118
align: rt::v1::Alignment,
116-
width: Option<uint>,
117-
precision: Option<uint>,
119+
width: Option<usize>,
120+
precision: Option<usize>,
118121

119122
buf: &'a mut (Write+'a),
120123
curarg: slice::Iter<'a, ArgumentV1<'a>>,
@@ -140,7 +143,7 @@ pub struct ArgumentV1<'a> {
140143

141144
impl<'a> ArgumentV1<'a> {
142145
#[inline(never)]
143-
fn show_uint(x: &uint, f: &mut Formatter) -> Result {
146+
fn show_usize(x: &usize, f: &mut Formatter) -> Result {
144147
Display::fmt(x, f)
145148
}
146149

@@ -156,15 +159,22 @@ impl<'a> ArgumentV1<'a> {
156159
}
157160
}
158161

162+
#[cfg(stage0)]
159163
#[doc(hidden)]
160164
#[stable(feature = "rust1", since = "1.0.0")]
161165
pub fn from_uint(x: &uint) -> ArgumentV1 {
162-
ArgumentV1::new(x, ArgumentV1::show_uint)
166+
ArgumentV1::new(x, ArgumentV1::show_usize)
167+
}
168+
#[cfg(not(stage0))]
169+
#[doc(hidden)]
170+
#[stable(feature = "rust1", since = "1.0.0")]
171+
pub fn from_usize(x: &usize) -> ArgumentV1 {
172+
ArgumentV1::new(x, ArgumentV1::show_usize)
163173
}
164174

165-
fn as_uint(&self) -> Option<uint> {
166-
if self.formatter as uint == ArgumentV1::show_uint as uint {
167-
Some(unsafe { *(self.value as *const _ as *const uint) })
175+
fn as_usize(&self) -> Option<usize> {
176+
if self.formatter as usize == ArgumentV1::show_usize as usize {
177+
Some(unsafe { *(self.value as *const _ as *const usize) })
168178
} else {
169179
None
170180
}
@@ -194,7 +204,7 @@ impl<'a> Arguments<'a> {
194204
/// The `pieces` array must be at least as long as `fmt` to construct
195205
/// a valid Arguments structure. Also, any `Count` within `fmt` that is
196206
/// `CountIsParam` or `CountIsNextParam` has to point to an argument
197-
/// created with `argumentuint`. However, failing to do so doesn't cause
207+
/// created with `argumentusize`. However, failing to do so doesn't cause
198208
/// unsafety, but will ignore invalid .
199209
#[doc(hidden)] #[inline]
200210
#[stable(feature = "rust1", since = "1.0.0")]
@@ -402,15 +412,15 @@ impl<'a> Formatter<'a> {
402412
(value.formatter)(value.value, self)
403413
}
404414

405-
fn getcount(&mut self, cnt: &rt::v1::Count) -> Option<uint> {
415+
fn getcount(&mut self, cnt: &rt::v1::Count) -> Option<usize> {
406416
match *cnt {
407417
rt::v1::Count::Is(n) => Some(n),
408418
rt::v1::Count::Implied => None,
409419
rt::v1::Count::Param(i) => {
410-
self.args[i].as_uint()
420+
self.args[i].as_usize()
411421
}
412422
rt::v1::Count::NextParam => {
413-
self.curarg.next().and_then(|arg| arg.as_uint())
423+
self.curarg.next().and_then(|arg| arg.as_usize())
414424
}
415425
}
416426
}
@@ -444,12 +454,12 @@ impl<'a> Formatter<'a> {
444454
let mut sign = None;
445455
if !is_positive {
446456
sign = Some('-'); width += 1;
447-
} else if self.flags & (1 << (FlagV1::SignPlus as uint)) != 0 {
457+
} else if self.flags & (1 << (FlagV1::SignPlus as u32)) != 0 {
448458
sign = Some('+'); width += 1;
449459
}
450460

451461
let mut prefixed = false;
452-
if self.flags & (1 << (FlagV1::Alternate as uint)) != 0 {
462+
if self.flags & (1 << (FlagV1::Alternate as u32)) != 0 {
453463
prefixed = true; width += prefix.char_len();
454464
}
455465

@@ -479,7 +489,7 @@ impl<'a> Formatter<'a> {
479489
}
480490
// The sign and prefix goes before the padding if the fill character
481491
// is zero
482-
Some(min) if self.flags & (1 << (FlagV1::SignAwareZeroPad as uint)) != 0 => {
492+
Some(min) if self.flags & (1 << (FlagV1::SignAwareZeroPad as u32)) != 0 => {
483493
self.fill = '0';
484494
try!(write_prefix(self));
485495
self.with_padding(min - width, Alignment::Right, |f| {
@@ -549,7 +559,7 @@ impl<'a> Formatter<'a> {
549559

550560
/// Runs a callback, emitting the correct padding either before or
551561
/// afterwards depending on whether right or left alignment is requested.
552-
fn with_padding<F>(&mut self, padding: uint, default: Alignment,
562+
fn with_padding<F>(&mut self, padding: usize, default: Alignment,
553563
f: F) -> Result
554564
where F: FnOnce(&mut Formatter) -> Result,
555565
{
@@ -595,6 +605,11 @@ impl<'a> Formatter<'a> {
595605
write(self.buf, fmt)
596606
}
597607

608+
#[cfg(not(stage0))]
609+
/// Flags for formatting (packed version of rt::Flag)
610+
#[stable(feature = "rust1", since = "1.0.0")]
611+
pub fn flags(&self) -> u32 { self.flags }
612+
#[cfg(stage0)]
598613
/// Flags for formatting (packed version of rt::Flag)
599614
#[stable(feature = "rust1", since = "1.0.0")]
600615
pub fn flags(&self) -> usize { self.flags }
@@ -609,11 +624,11 @@ impl<'a> Formatter<'a> {
609624

610625
/// Optionally specified integer width that the output should be
611626
#[unstable(feature = "core", reason = "method was just created")]
612-
pub fn width(&self) -> Option<uint> { self.width }
627+
pub fn width(&self) -> Option<usize> { self.width }
613628

614629
/// Optionally specified precision for numeric types
615630
#[unstable(feature = "core", reason = "method was just created")]
616-
pub fn precision(&self) -> Option<uint> { self.precision }
631+
pub fn precision(&self) -> Option<usize> { self.precision }
617632
}
618633

619634
#[stable(feature = "rust1", since = "1.0.0")]
@@ -699,9 +714,9 @@ impl Display for char {
699714
#[stable(feature = "rust1", since = "1.0.0")]
700715
impl<T> Pointer for *const T {
701716
fn fmt(&self, f: &mut Formatter) -> Result {
702-
f.flags |= 1 << (FlagV1::Alternate as uint);
703-
let ret = LowerHex::fmt(&(*self as uint), f);
704-
f.flags &= !(1 << (FlagV1::Alternate as uint));
717+
f.flags |= 1 << (FlagV1::Alternate as u32);
718+
let ret = LowerHex::fmt(&(*self as u32), f);
719+
f.flags &= !(1 << (FlagV1::Alternate as u32));
705720
ret
706721
}
707722
}
@@ -857,7 +872,7 @@ impl<'a> Debug for &'a (any::Any+'a) {
857872
#[stable(feature = "rust1", since = "1.0.0")]
858873
impl<T: Debug> Debug for [T] {
859874
fn fmt(&self, f: &mut Formatter) -> Result {
860-
if f.flags & (1 << (FlagV1::Alternate as uint)) == 0 {
875+
if f.flags & (1 << (FlagV1::Alternate as u32)) == 0 {
861876
try!(write!(f, "["));
862877
}
863878
let mut is_first = true;
@@ -869,7 +884,7 @@ impl<T: Debug> Debug for [T] {
869884
}
870885
try!(write!(f, "{:?}", *x))
871886
}
872-
if f.flags & (1 << (FlagV1::Alternate as uint)) == 0 {
887+
if f.flags & (1 << (FlagV1::Alternate as u32)) == 0 {
873888
try!(write!(f, "]"));
874889
}
875890
Ok(())

src/libcore/fmt/num.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ macro_rules! integer {
214214
show! { $Uint with $SU }
215215
}
216216
}
217-
integer! { int, uint, "i", "u" }
217+
integer! { isize, usize, "i", "u" }
218218
integer! { i8, u8 }
219219
integer! { i16, u16 }
220220
integer! { i32, u32 }

src/libcore/fmt/rt/v1.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ pub struct FormatSpec {
3232
pub fill: char,
3333
#[stable(feature = "rust1", since = "1.0.0")]
3434
pub align: Alignment,
35+
#[cfg(stage0)]
3536
#[stable(feature = "rust1", since = "1.0.0")]
36-
pub flags: uint,
37+
pub flags: usize,
38+
#[cfg(not(stage0))]
39+
#[stable(feature = "rust1", since = "1.0.0")]
40+
pub flags: u32,
3741
#[stable(feature = "rust1", since = "1.0.0")]
3842
pub precision: Count,
3943
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/hash/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//!
2121
//! #[derive(Hash)]
2222
//! struct Person {
23-
//! id: uint,
23+
//! id: u32,
2424
//! name: String,
2525
//! phone: u64,
2626
//! }
@@ -38,7 +38,7 @@
3838
//! use std::hash::{hash, Hash, Hasher, SipHasher};
3939
//!
4040
//! struct Person {
41-
//! id: uint,
41+
//! id: u32,
4242
//! name: String,
4343
//! phone: u64,
4444
//! }

src/libcore/hash/sip.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ use super::Hasher;
3434
pub struct SipHasher {
3535
k0: u64,
3636
k1: u64,
37-
length: uint, // how many bytes we've processed
37+
length: usize, // how many bytes we've processed
3838
v0: u64, // hash state
3939
v1: u64,
4040
v2: u64,
4141
v3: u64,
4242
tail: u64, // unprocessed bytes le
43-
ntail: uint, // how many bytes in tail are valid
43+
ntail: usize, // how many bytes in tail are valid
4444
}
4545

4646
// sadly, these macro definitions can't appear later,

src/libfmt_macros/lib.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
html_root_url = "http://doc.rust-lang.org/nightly/",
2525
html_playground_url = "http://play.rust-lang.org/")]
2626

27-
#![feature(int_uint)]
2827
#![feature(staged_api)]
2928
#![feature(unicode)]
3029

@@ -65,7 +64,7 @@ pub struct FormatSpec<'a> {
6564
/// Optionally specified alignment
6665
pub align: Alignment,
6766
/// Packed version of various flags provided
68-
pub flags: uint,
67+
pub flags: u32,
6968
/// The integer precision to use
7069
pub precision: Count<'a>,
7170
/// The string width requested for the resulting format
@@ -82,7 +81,7 @@ pub enum Position<'a> {
8281
/// The argument will be in the next position. This is the default.
8382
ArgumentNext,
8483
/// The argument is located at a specific index.
85-
ArgumentIs(uint),
84+
ArgumentIs(usize),
8685
/// The argument has a name.
8786
ArgumentNamed(&'a str),
8887
}
@@ -121,11 +120,11 @@ pub enum Flag {
121120
#[derive(Copy, PartialEq)]
122121
pub enum Count<'a> {
123122
/// The count is specified explicitly.
124-
CountIs(uint),
123+
CountIs(usize),
125124
/// The count is specified by the argument with the given name.
126125
CountIsName(&'a str),
127126
/// The count is specified by the argument at the given index.
128-
CountIsParam(uint),
127+
CountIsParam(usize),
129128
/// The count is specified by the next parameter.
130129
CountIsNextParam,
131130
/// The count is implied and cannot be explicitly specified.
@@ -237,7 +236,7 @@ impl<'a> Parser<'a> {
237236

238237
/// Parses all of a string which is to be considered a "raw literal" in a
239238
/// format string. This is everything outside of the braces.
240-
fn string(&mut self, start: uint) -> &'a str {
239+
fn string(&mut self, start: usize) -> &'a str {
241240
loop {
242241
// we may not consume the character, so clone the iterator
243242
match self.cur.clone().next() {
@@ -314,13 +313,13 @@ impl<'a> Parser<'a> {
314313
}
315314
// Sign flags
316315
if self.consume('+') {
317-
spec.flags |= 1 << (FlagSignPlus as uint);
316+
spec.flags |= 1 << (FlagSignPlus as u32);
318317
} else if self.consume('-') {
319-
spec.flags |= 1 << (FlagSignMinus as uint);
318+
spec.flags |= 1 << (FlagSignMinus as u32);
320319
}
321320
// Alternate marker
322321
if self.consume('#') {
323-
spec.flags |= 1 << (FlagAlternate as uint);
322+
spec.flags |= 1 << (FlagAlternate as u32);
324323
}
325324
// Width and precision
326325
let mut havewidth = false;
@@ -333,7 +332,7 @@ impl<'a> Parser<'a> {
333332
spec.width = CountIsParam(0);
334333
havewidth = true;
335334
} else {
336-
spec.flags |= 1 << (FlagSignAwareZeroPad as uint);
335+
spec.flags |= 1 << (FlagSignAwareZeroPad as u32);
337336
}
338337
}
339338
if !havewidth {
@@ -413,7 +412,7 @@ impl<'a> Parser<'a> {
413412

414413
/// Optionally parses an integer at the current position. This doesn't deal
415414
/// with overflow at all, it's just accumulating digits.
416-
fn integer(&mut self) -> Option<uint> {
415+
fn integer(&mut self) -> Option<usize> {
417416
let mut cur = 0;
418417
let mut found = false;
419418
loop {
@@ -617,7 +616,7 @@ mod tests {
617616
format: FormatSpec {
618617
fill: None,
619618
align: AlignUnknown,
620-
flags: (1 << FlagSignMinus as uint),
619+
flags: (1 << FlagSignMinus as u32),
621620
precision: CountImplied,
622621
width: CountImplied,
623622
ty: "",
@@ -628,7 +627,7 @@ mod tests {
628627
format: FormatSpec {
629628
fill: None,
630629
align: AlignUnknown,
631-
flags: (1 << FlagSignPlus as uint) | (1 << FlagAlternate as uint),
630+
flags: (1 << FlagSignPlus as u32) | (1 << FlagAlternate as u32),
632631
precision: CountImplied,
633632
width: CountImplied,
634633
ty: "",

0 commit comments

Comments
 (0)