Skip to content

Commit 46fc549

Browse files
committed
rm obsolete integer to_str{,_radix} free functions
1 parent 0d72f60 commit 46fc549

File tree

27 files changed

+104
-152
lines changed

27 files changed

+104
-152
lines changed

doc/rust.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2864,17 +2864,16 @@ the vtable pointer for the `T` implementation of `R`, and the pointer value of `
28642864
An example of an object type:
28652865

28662866
~~~~~~~~
2867-
# use std::int;
28682867
trait Printable {
2869-
fn to_str(&self) -> ~str;
2868+
fn to_string(&self) -> ~str;
28702869
}
28712870
28722871
impl Printable for int {
2873-
fn to_str(&self) -> ~str { int::to_str(*self) }
2872+
fn to_string(&self) -> ~str { self.to_str() }
28742873
}
28752874
28762875
fn print(a: @Printable) {
2877-
println(a.to_str());
2876+
println(a.to_string());
28782877
}
28792878
28802879
fn main() {

doc/tutorial.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,12 +555,11 @@ while cake_amount > 0 {
555555
`loop` denotes an infinite loop, and is the preferred way of writing `while true`:
556556

557557
~~~~
558-
use std::int;
559-
let mut x = 5;
558+
let mut x = 5u;
560559
loop {
561560
x += x - 3;
562561
if x % 5 == 0 { break; }
563-
println(int::to_str(x));
562+
println(x.to_str());
564563
}
565564
~~~~
566565

src/libextra/crypto/digest.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::uint;
1211
use std::vec;
1312

1413

@@ -71,7 +70,7 @@ pub trait Digest {
7170
fn to_hex(rr: &[u8]) -> ~str {
7271
let mut s = ~"";
7372
for b in rr.iter() {
74-
let hex = uint::to_str_radix(*b as uint, 16u);
73+
let hex = (*b as uint).to_str_radix(16u);
7574
if hex.len() == 1 {
7675
s.push_char('0');
7776
}

src/libextra/md4.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111

12-
use std::uint;
1312
use std::vec;
1413

1514
struct Quad {
@@ -121,7 +120,7 @@ pub fn md4_str(msg: &[u8]) -> ~str {
121120
if byte <= 16u8 {
122121
result.push_char('0')
123122
}
124-
result.push_str(uint::to_str_radix(byte as uint, 16u));
123+
result.push_str((byte as uint).to_str_radix(16u));
125124
i += 1u32;
126125
}
127126
}

src/libextra/num/bigint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl ToStrRadix for BigUint {
525525
if v.is_empty() { return ~"0" }
526526
let mut s = str::with_capacity(v.len() * l);
527527
for n in v.rev_iter() {
528-
let ss = uint::to_str_radix(*n as uint, radix);
528+
let ss = (*n as uint).to_str_radix(radix);
529529
s.push_str("0".repeat(l - ss.len()));
530530
s.push_str(ss);
531531
}

src/libextra/time.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
#[allow(missing_doc)];
1212

13-
14-
use std::int;
1513
use std::io;
1614
use std::num;
1715
use std::str;
@@ -824,7 +822,7 @@ fn do_strftime(format: &str, tm: &Tm) -> ~str {
824822
//'U' {}
825823
'u' => {
826824
let i = tm.tm_wday as int;
827-
int::to_str(if i == 0 { 7 } else { i })
825+
(if i == 0 { 7 } else { i }).to_str()
828826
}
829827
//'V' {}
830828
'v' => {
@@ -834,10 +832,10 @@ fn do_strftime(format: &str, tm: &Tm) -> ~str {
834832
parse_type('Y', tm))
835833
}
836834
//'W' {}
837-
'w' => int::to_str(tm.tm_wday as int),
835+
'w' => (tm.tm_wday as int).to_str(),
838836
//'X' {}
839837
//'x' {}
840-
'Y' => int::to_str(tm.tm_year as int + 1900),
838+
'Y' => (tm.tm_year as int + 1900).to_str(),
841839
'y' => fmt!("%02d", (tm.tm_year as int + 1900) % 100),
842840
'Z' => tm.tm_zone.clone(),
843841
'z' => {

src/librustc/driver/driver.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use util::common::time;
2626
use util::ppaux;
2727

2828
use std::hashmap::{HashMap,HashSet};
29-
use std::int;
3029
use std::io;
3130
use std::os;
3231
use std::vec;
@@ -454,21 +453,21 @@ pub fn pretty_print_input(sess: Session, cfg: ast::CrateConfig, input: &input,
454453
match node {
455454
pprust::node_item(s, item) => {
456455
pp::space(s.s);
457-
pprust::synth_comment(s, int::to_str(item.id));
456+
pprust::synth_comment(s, item.id.to_str());
458457
}
459458
pprust::node_block(s, ref blk) => {
460459
pp::space(s.s);
461460
pprust::synth_comment(
462-
s, ~"block " + int::to_str(blk.id));
461+
s, ~"block " + blk.id.to_str());
463462
}
464463
pprust::node_expr(s, expr) => {
465464
pp::space(s.s);
466-
pprust::synth_comment(s, int::to_str(expr.id));
465+
pprust::synth_comment(s, expr.id.to_str());
467466
pprust::pclose(s);
468467
}
469468
pprust::node_pat(s, pat) => {
470469
pp::space(s.s);
471-
pprust::synth_comment(s, ~"pat " + int::to_str(pat.id));
470+
pprust::synth_comment(s, ~"pat " + pat.id.to_str());
472471
}
473472
}
474473
}

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use std::hash::HashUtil;
2525
use std::hashmap::{HashMap, HashSet};
2626
use std::io;
2727
use std::str;
28-
use std::uint;
2928
use std::vec;
3029
use extra::flate;
3130
use extra::serialize::Encodable;
@@ -303,7 +302,7 @@ fn encode_disr_val(_: &EncodeContext,
303302
ebml_w: &mut writer::Encoder,
304303
disr_val: uint) {
305304
ebml_w.start_tag(tag_disr_val);
306-
let s = uint::to_str(disr_val);
305+
let s = disr_val.to_str();
307306
ebml_w.writer.write(s.as_bytes());
308307
ebml_w.end_tag();
309308
}

src/librustc/metadata/tyencode.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use middle::ty;
1717
use std::hashmap::HashMap;
1818
use std::io::WriterUtil;
1919
use std::io;
20-
use std::uint;
2120
use syntax::abi::AbiSet;
2221
use syntax::ast;
2322
use syntax::ast::*;
@@ -324,7 +323,7 @@ fn enc_sty(w: @io::Writer, cx: @ctxt, st: &ty::sty) {
324323
w.write_char('p');
325324
w.write_str((cx.ds)(did));
326325
w.write_char('|');
327-
w.write_str(uint::to_str(id));
326+
w.write_str(id.to_str());
328327
}
329328
ty::ty_self(did) => {
330329
w.write_char('s');

src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ use std::hash;
7171
use std::hashmap::HashMap;
7272
use std::io;
7373
use std::libc::c_uint;
74-
use std::uint;
7574
use std::vec;
7675
use std::local_data;
7776
use extra::time;
@@ -719,7 +718,7 @@ pub fn iter_structural_ty(cx: @mut Block, av: ValueRef, t: ty::t,
719718
for variant in (*variants).iter() {
720719
let variant_cx =
721720
sub_block(cx, ~"enum-iter-variant-" +
722-
uint::to_str(variant.disr_val));
721+
variant.disr_val.to_str());
723722
let variant_cx =
724723
iter_variant(variant_cx, repr, av, *variant,
725724
substs.tps, |x,y,z| f(x,y,z));

src/librustc/middle/ty.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use std::ops;
3333
use std::ptr::to_unsafe_ptr;
3434
use std::to_bytes;
3535
use std::to_str::ToStr;
36-
use std::u32;
3736
use std::vec;
3837
use syntax::ast::*;
3938
use syntax::ast_util::is_local;
@@ -1944,7 +1943,7 @@ impl ops::Sub<TypeContents,TypeContents> for TypeContents {
19441943

19451944
impl ToStr for TypeContents {
19461945
fn to_str(&self) -> ~str {
1947-
fmt!("TypeContents(%s)", u32::to_str_radix(self.bits, 2))
1946+
fmt!("TypeContents(%s)", self.bits.to_str_radix(2))
19481947
}
19491948
}
19501949

src/librustc/middle/typeck/infer/to_str.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use middle::typeck::infer::InferCtxt;
1717
use middle::typeck::infer::unify::{Redirect, Root, VarValue};
1818
use util::ppaux::{mt_to_str, ty_to_str, trait_ref_to_str};
1919

20-
use std::uint;
2120
use syntax::ast;
2221

2322
pub trait InferStr {
@@ -72,7 +71,7 @@ impl<V:Vid + ToStr,T:InferStr> InferStr for VarValue<V, T> {
7271
match *self {
7372
Redirect(ref vid) => fmt!("Redirect(%s)", vid.to_str()),
7473
Root(ref pt, rk) => fmt!("Root(%s, %s)", pt.inf_str(cx),
75-
uint::to_str_radix(rk, 10u))
74+
rk.to_str_radix(10u))
7675
}
7776
}
7877
}

src/libstd/hash.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use option::{Some, None};
2727
use rt::io::Writer;
2828
use str::OwnedStr;
2929
use to_bytes::IterBytes;
30-
use uint;
3130
use vec::ImmutableVector;
31+
use num::ToStrRadix;
3232

3333
// Alias `SipState` to `State`.
3434
pub use State = hash::SipState;
@@ -386,7 +386,7 @@ impl Streaming for SipState {
386386
let r = self.result_bytes();
387387
let mut s = ~"";
388388
for b in r.iter() {
389-
s.push_str(uint::to_str_radix(*b as uint, 16u));
389+
s.push_str((*b as uint).to_str_radix(16u));
390390
}
391391
s
392392
}
@@ -407,8 +407,6 @@ mod tests {
407407
use super::*;
408408
use prelude::*;
409409

410-
use uint;
411-
412410
// Hash just the bytes of the slice, without length prefix
413411
struct Bytes<'self>(&'self [u8]);
414412
impl<'self> IterBytes for Bytes<'self> {
@@ -496,7 +494,7 @@ mod tests {
496494
fn to_hex_str(r: &[u8, ..8]) -> ~str {
497495
let mut s = ~"";
498496
for b in r.iter() {
499-
s.push_str(uint::to_str_radix(*b as uint, 16u));
497+
s.push_str((*b as uint).to_str_radix(16u));
500498
}
501499
s
502500
}

src/libstd/num/int_macros.rs

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -525,35 +525,25 @@ pub fn to_str_bytes<U>(n: $T, radix: uint, f: &fn(v: &[u8]) -> U) -> U {
525525
f(buf.slice(0, cur))
526526
}
527527
528-
/// Convert to a string in base 10.
529-
#[inline]
530-
pub fn to_str(num: $T) -> ~str {
531-
to_str_radix(num, 10u)
532-
}
533-
534-
/// Convert to a string in a given base.
535-
#[inline]
536-
pub fn to_str_radix(num: $T, radix: uint) -> ~str {
537-
let mut buf: ~[u8] = ~[];
538-
do strconv::int_to_str_bytes_common(num, radix, strconv::SignNeg) |i| {
539-
buf.push(i);
540-
}
541-
// We know we generated valid utf-8, so we don't need to go through that
542-
// check.
543-
unsafe { str::raw::from_bytes_owned(buf) }
544-
}
545-
546528
impl ToStr for $T {
529+
/// Convert to a string in base 10.
547530
#[inline]
548531
fn to_str(&self) -> ~str {
549-
to_str(*self)
532+
self.to_str_radix(10)
550533
}
551534
}
552535
553536
impl ToStrRadix for $T {
537+
/// Convert to a string in a given base.
554538
#[inline]
555539
fn to_str_radix(&self, radix: uint) -> ~str {
556-
to_str_radix(*self, radix)
540+
let mut buf: ~[u8] = ~[];
541+
do strconv::int_to_str_bytes_common(*self, radix, strconv::SignNeg) |i| {
542+
buf.push(i);
543+
}
544+
// We know we generated valid utf-8, so we don't need to go through that
545+
// check.
546+
unsafe { str::raw::from_bytes_owned(buf) }
557547
}
558548
}
559549
@@ -813,39 +803,39 @@ mod tests {
813803
814804
#[test]
815805
fn test_to_str() {
816-
assert_eq!(to_str_radix(0 as $T, 10u), ~"0");
817-
assert_eq!(to_str_radix(1 as $T, 10u), ~"1");
818-
assert_eq!(to_str_radix(-1 as $T, 10u), ~"-1");
819-
assert_eq!(to_str_radix(127 as $T, 16u), ~"7f");
820-
assert_eq!(to_str_radix(100 as $T, 10u), ~"100");
806+
assert_eq!((0 as $T).to_str_radix(10u), ~"0");
807+
assert_eq!((1 as $T).to_str_radix(10u), ~"1");
808+
assert_eq!((-1 as $T).to_str_radix(10u), ~"-1");
809+
assert_eq!((127 as $T).to_str_radix(16u), ~"7f");
810+
assert_eq!((100 as $T).to_str_radix(10u), ~"100");
821811
822812
}
823813
824814
#[test]
825815
fn test_int_to_str_overflow() {
826816
let mut i8_val: i8 = 127_i8;
827-
assert_eq!(i8::to_str(i8_val), ~"127");
817+
assert_eq!(i8_val.to_str(), ~"127");
828818
829819
i8_val += 1 as i8;
830-
assert_eq!(i8::to_str(i8_val), ~"-128");
820+
assert_eq!(i8_val.to_str(), ~"-128");
831821
832822
let mut i16_val: i16 = 32_767_i16;
833-
assert_eq!(i16::to_str(i16_val), ~"32767");
823+
assert_eq!(i16_val.to_str(), ~"32767");
834824
835825
i16_val += 1 as i16;
836-
assert_eq!(i16::to_str(i16_val), ~"-32768");
826+
assert_eq!(i16_val.to_str(), ~"-32768");
837827
838828
let mut i32_val: i32 = 2_147_483_647_i32;
839-
assert_eq!(i32::to_str(i32_val), ~"2147483647");
829+
assert_eq!(i32_val.to_str(), ~"2147483647");
840830
841831
i32_val += 1 as i32;
842-
assert_eq!(i32::to_str(i32_val), ~"-2147483648");
832+
assert_eq!(i32_val.to_str(), ~"-2147483648");
843833
844834
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
845-
assert_eq!(i64::to_str(i64_val), ~"9223372036854775807");
835+
assert_eq!(i64_val.to_str(), ~"9223372036854775807");
846836
847837
i64_val += 1 as i64;
848-
assert_eq!(i64::to_str(i64_val), ~"-9223372036854775808");
838+
assert_eq!(i64_val.to_str(), ~"-9223372036854775808");
849839
}
850840
851841
#[test]

src/libstd/num/strconv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,14 +708,14 @@ mod test {
708708
mod bench {
709709
use extra::test::BenchHarness;
710710
use rand::{XorShiftRng,RngUtil};
711-
use uint;
712711
use float;
712+
use to_str::ToStr;
713713

714714
#[bench]
715715
fn uint_to_str_rand(bh: &mut BenchHarness) {
716716
let mut rng = XorShiftRng::new();
717717
do bh.iter {
718-
uint::to_str(rng.gen());
718+
rng.gen::<uint>().to_str();
719719
}
720720
}
721721

0 commit comments

Comments
 (0)