diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-10-14 23:05:01 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-10-19 12:59:40 -0700 |
| commit | 9d5d97b55d6487ee23b805bc1acbaa0669b82116 (patch) | |
| tree | b72dcf7045e331e94ea0f8658d088ab42d917935 /src/libstd/num | |
| parent | fb169d5543c84e11038ba2d07b538ec88fb49ca6 (diff) | |
| download | rust-9d5d97b55d6487ee23b805bc1acbaa0669b82116.tar.gz rust-9d5d97b55d6487ee23b805bc1acbaa0669b82116.zip | |
Remove a large amount of deprecated functionality
Spring cleaning is here! In the Fall! This commit removes quite a large amount of deprecated functionality from the standard libraries. I tried to ensure that only old deprecated functionality was removed. This is removing lots and lots of deprecated features, so this is a breaking change. Please consult the deprecation messages of the deleted code to see how to migrate code forward if it still needs migration. [breaking-change]
Diffstat (limited to 'src/libstd/num')
| -rw-r--r-- | src/libstd/num/f32.rs | 23 | ||||
| -rw-r--r-- | src/libstd/num/f64.rs | 23 | ||||
| -rw-r--r-- | src/libstd/num/i16.rs | 3 | ||||
| -rw-r--r-- | src/libstd/num/i32.rs | 3 | ||||
| -rw-r--r-- | src/libstd/num/i64.rs | 3 | ||||
| -rw-r--r-- | src/libstd/num/i8.rs | 3 | ||||
| -rw-r--r-- | src/libstd/num/int.rs | 3 | ||||
| -rw-r--r-- | src/libstd/num/int_macros.rs | 50 | ||||
| -rw-r--r-- | src/libstd/num/mod.rs | 7 | ||||
| -rw-r--r-- | src/libstd/num/strconv.rs | 34 | ||||
| -rw-r--r-- | src/libstd/num/u16.rs | 3 | ||||
| -rw-r--r-- | src/libstd/num/u32.rs | 3 | ||||
| -rw-r--r-- | src/libstd/num/u64.rs | 3 | ||||
| -rw-r--r-- | src/libstd/num/u8.rs | 3 | ||||
| -rw-r--r-- | src/libstd/num/uint.rs | 3 | ||||
| -rw-r--r-- | src/libstd/num/uint_macros.rs | 33 |
16 files changed, 26 insertions, 174 deletions
diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index b2a9f1b7b20..92db94c5e9a 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -333,29 +333,6 @@ pub fn to_str_exp_digits(num: f32, dig: uint, upper: bool) -> String { r } -impl num::ToStrRadix for f32 { - /// Converts a float to a string in a given radix - /// - /// # Arguments - /// - /// * num - The float value - /// * radix - The base to use - /// - /// # Failure - /// - /// Fails if called on a special value like `inf`, `-inf` or `NaN` due to - /// possible misinterpretation of the result at higher bases. If those values - /// are expected, use `to_str_radix_special()` instead. - #[inline] - fn to_str_radix(&self, rdx: uint) -> String { - let (r, special) = strconv::float_to_str_common( - *self, rdx, true, strconv::SignNeg, strconv::DigAll, strconv::ExpNone, false); - if special { fail!("number has a special value, \ - try to_str_radix_special() if those are expected") } - r - } -} - /// Convert a string in base 16 to a float. /// Accepts an optional binary exponent. /// diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index 6fe9fcad2aa..3635c3192db 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -341,29 +341,6 @@ pub fn to_str_exp_digits(num: f64, dig: uint, upper: bool) -> String { r } -impl num::ToStrRadix for f64 { - /// Converts a float to a string in a given radix - /// - /// # Arguments - /// - /// * num - The float value - /// * radix - The base to use - /// - /// # Failure - /// - /// Fails if called on a special value like `inf`, `-inf` or `NAN` due to - /// possible misinterpretation of the result at higher bases. If those values - /// are expected, use `to_str_radix_special()` instead. - #[inline] - fn to_str_radix(&self, rdx: uint) -> String { - let (r, special) = strconv::float_to_str_common( - *self, rdx, true, strconv::SignNeg, strconv::DigAll, strconv::ExpNone, false); - if special { fail!("number has a special value, \ - try to_str_radix_special() if those are expected") } - r - } -} - /// Convert a string in base 16 to a float. /// Accepts an optional binary exponent. /// diff --git a/src/libstd/num/i16.rs b/src/libstd/num/i16.rs index 9e4cc06f0a2..d7732b474db 100644 --- a/src/libstd/num/i16.rs +++ b/src/libstd/num/i16.rs @@ -14,10 +14,9 @@ #![doc(primitive = "i16")] use from_str::FromStr; -use num::{ToStrRadix, FromStrRadix}; +use num::FromStrRadix; use num::strconv; use option::Option; -use string::String; pub use core::i16::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/i32.rs b/src/libstd/num/i32.rs index 54259fcad55..778f1c6748c 100644 --- a/src/libstd/num/i32.rs +++ b/src/libstd/num/i32.rs @@ -14,10 +14,9 @@ #![doc(primitive = "i32")] use from_str::FromStr; -use num::{ToStrRadix, FromStrRadix}; +use num::FromStrRadix; use num::strconv; use option::Option; -use string::String; pub use core::i32::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/i64.rs b/src/libstd/num/i64.rs index b5fe6825ca4..ae3d57eeac6 100644 --- a/src/libstd/num/i64.rs +++ b/src/libstd/num/i64.rs @@ -14,10 +14,9 @@ #![doc(primitive = "i64")] use from_str::FromStr; -use num::{ToStrRadix, FromStrRadix}; +use num::FromStrRadix; use num::strconv; use option::Option; -use string::String; pub use core::i64::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/i8.rs b/src/libstd/num/i8.rs index 7aa9a41e340..8a3f379893c 100644 --- a/src/libstd/num/i8.rs +++ b/src/libstd/num/i8.rs @@ -14,10 +14,9 @@ #![doc(primitive = "i8")] use from_str::FromStr; -use num::{ToStrRadix, FromStrRadix}; +use num::FromStrRadix; use num::strconv; use option::Option; -use string::String; pub use core::i8::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/int.rs b/src/libstd/num/int.rs index 74ee61634c6..51af04b32d4 100644 --- a/src/libstd/num/int.rs +++ b/src/libstd/num/int.rs @@ -14,10 +14,9 @@ #![doc(primitive = "int")] use from_str::FromStr; -use num::{ToStrRadix, FromStrRadix}; +use num::FromStrRadix; use num::strconv; use option::Option; -use string::String; pub use core::int::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs index 62e609bb2e1..ca45b40e687 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -51,52 +51,12 @@ impl FromStrRadix for $T { } } -// String conversion functions and impl num -> str - -/// Convert to a string as a byte slice in a given base. -/// -/// Use in place of x.to_string() when you do not need to store the string permanently -/// -/// # Examples -/// -/// ``` -/// #![allow(deprecated)] -/// -/// std::int::to_str_bytes(123, 10, |v| { -/// assert!(v == "123".as_bytes()); -/// }); -/// ``` -#[inline] -#[deprecated = "just use .to_string(), or a BufWriter with write! if you mustn't allocate"] -pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U { - use io::{Writer, Seek}; - // The radix can be as low as 2, so we need at least 64 characters for a - // base 2 number, and then we need another for a possible '-' character. - let mut buf = [0u8, ..65]; - let amt = { - let mut wr = ::io::BufWriter::new(buf); - (write!(&mut wr, "{}", ::fmt::radix(n, radix as u8))).unwrap(); - wr.tell().unwrap() as uint - }; - f(buf[..amt]) -} - -#[deprecated = "use fmt::radix"] -impl ToStrRadix for $T { - /// Convert to a string in a given base. - #[inline] - fn to_str_radix(&self, radix: uint) -> String { - format!("{}", ::fmt::radix(*self, radix as u8)) - } -} - #[cfg(test)] mod tests { use prelude::*; use super::*; use i32; - use num::ToStrRadix; use str::StrSlice; #[test] @@ -143,16 +103,6 @@ mod tests { } #[test] - fn test_to_string() { - assert_eq!((0 as $T).to_str_radix(10u), "0".to_string()); - assert_eq!((1 as $T).to_str_radix(10u), "1".to_string()); - assert_eq!((-1 as $T).to_str_radix(10u), "-1".to_string()); - assert_eq!((127 as $T).to_str_radix(16u), "7f".to_string()); - assert_eq!((100 as $T).to_str_radix(10u), "100".to_string()); - - } - - #[test] fn test_int_to_str_overflow() { let mut i8_val: i8 = 127_i8; assert_eq!(i8_val.to_string(), "127".to_string()); diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 27ee1e3ce3b..564b6a25f7f 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -17,7 +17,6 @@ #![allow(missing_doc)] use option::Option; -use string::String; #[cfg(test)] use fmt::Show; @@ -111,12 +110,6 @@ pub trait FloatMath: Float { fn atanh(self) -> Self; } -/// A generic trait for converting a value to a string with a radix (base) -#[deprecated = "use fmt::radix"] -pub trait ToStrRadix { - fn to_str_radix(&self, radix: uint) -> String; -} - /// A generic trait for converting a string with a radix (base) to a value #[experimental = "might need to return Result"] pub trait FromStrRadix { diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 48ee7664c16..af66e6ca934 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -20,7 +20,7 @@ use num::{Float, FPNaN, FPInfinite, ToPrimitive}; use num; use ops::{Add, Sub, Mul, Div, Rem, Neg}; use option::{None, Option, Some}; -use slice::{ImmutableSlice, MutableSlice}; +use slice::{ImmutableSlice, MutableSlice, CloneableVector}; use std::cmp::{PartialOrd, PartialEq}; use str::StrSlice; use string::String; @@ -168,8 +168,7 @@ static NAN_BUF: [u8, ..3] = [b'N', b'a', b'N']; * # Failure * - Fails if `radix` < 2 or `radix` > 36. */ -#[deprecated = "format!() and friends should be favored instead"] -pub fn int_to_str_bytes_common<T: Int>(num: T, radix: uint, sign: SignFormat, f: |u8|) { +fn int_to_str_bytes_common<T: Int>(num: T, radix: uint, sign: SignFormat, f: |u8|) { assert!(2 <= radix && radix <= 36); let _0: T = Zero::zero(); @@ -257,7 +256,6 @@ pub fn int_to_str_bytes_common<T: Int>(num: T, radix: uint, sign: SignFormat, f: * - Fails if `radix` > 25 and `exp_format` is `ExpBin` due to conflict * between digit and exponent sign `'p'`. */ -#[allow(deprecated)] pub fn float_to_str_bytes_common<T:NumCast+Zero+One+PartialEq+PartialOrd+Float+ Div<T,T>+Neg<T>+Rem<T,T>+Mul<T,T>>( num: T, radix: uint, negative_zero: bool, @@ -278,17 +276,17 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+PartialEq+PartialOrd+Float+ let _1: T = One::one(); match num.classify() { - FPNaN => { return (Vec::from_slice("NaN".as_bytes()), true); } + FPNaN => { return (b"NaN".to_vec(), true); } FPInfinite if num > _0 => { return match sign { - SignAll => (Vec::from_slice("+inf".as_bytes()), true), - _ => (Vec::from_slice("inf".as_bytes()), true) + SignAll => (b"+inf".to_vec(), true), + _ => (b"inf".to_vec(), true) }; } FPInfinite if num < _0 => { return match sign { - SignNone => (Vec::from_slice("inf".as_bytes()), true), - _ => (Vec::from_slice("-inf".as_bytes()), true), + SignNone => (b"inf".to_vec(), true), + _ => (b"-inf".to_vec(), true), }; } _ => {} @@ -413,18 +411,18 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+PartialEq+PartialOrd+Float+ // If reached left end of number, have to // insert additional digit: if i < 0 - || *buf.get(i as uint) == b'-' - || *buf.get(i as uint) == b'+' { + || buf[i as uint] == b'-' + || buf[i as uint] == b'+' { buf.insert((i + 1) as uint, value2ascii(1)); break; } // Skip the '.' - if *buf.get(i as uint) == b'.' { i -= 1; continue; } + if buf[i as uint] == b'.' { i -= 1; continue; } // Either increment the digit, // or set to 0 if max and carry the 1. - let current_digit = ascii2value(*buf.get(i as uint)); + let current_digit = ascii2value(buf[i as uint]); if current_digit < (radix - 1) { *buf.get_mut(i as uint) = value2ascii(current_digit+1); break; @@ -446,25 +444,25 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+PartialEq+PartialOrd+Float+ let mut i = buf_max_i; // discover trailing zeros of fractional part - while i > start_fractional_digits && *buf.get(i) == b'0' { + while i > start_fractional_digits && buf[i] == b'0' { i -= 1; } // Only attempt to truncate digits if buf has fractional digits if i >= start_fractional_digits { // If buf ends with '.', cut that too. - if *buf.get(i) == b'.' { i -= 1 } + if buf[i] == b'.' { i -= 1 } // only resize buf if we actually remove digits if i < buf_max_i { - buf = Vec::from_slice(buf.slice(0, i + 1)); + buf = buf.slice(0, i + 1).to_vec(); } } } // If exact and trailing '.', just cut that else { let max_i = buf.len() - 1; - if *buf.get(max_i) == b'.' { - buf = Vec::from_slice(buf.slice(0, max_i)); + if buf[max_i] == b'.' { + buf = buf.slice(0, max_i).to_vec(); } } diff --git a/src/libstd/num/u16.rs b/src/libstd/num/u16.rs index c141ecc9cba..bb619b5b2f5 100644 --- a/src/libstd/num/u16.rs +++ b/src/libstd/num/u16.rs @@ -14,10 +14,9 @@ #![doc(primitive = "u16")] use from_str::FromStr; -use num::{ToStrRadix, FromStrRadix}; +use num::FromStrRadix; use num::strconv; use option::Option; -use string::String; pub use core::u16::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/u32.rs b/src/libstd/num/u32.rs index 8a8e2729a53..754103ba5da 100644 --- a/src/libstd/num/u32.rs +++ b/src/libstd/num/u32.rs @@ -14,10 +14,9 @@ #![doc(primitive = "u32")] use from_str::FromStr; -use num::{ToStrRadix, FromStrRadix}; +use num::FromStrRadix; use num::strconv; use option::Option; -use string::String; pub use core::u32::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/u64.rs b/src/libstd/num/u64.rs index 1b4f8bc433f..da497d2cbe4 100644 --- a/src/libstd/num/u64.rs +++ b/src/libstd/num/u64.rs @@ -14,10 +14,9 @@ #![doc(primitive = "u64")] use from_str::FromStr; -use num::{ToStrRadix, FromStrRadix}; +use num::FromStrRadix; use num::strconv; use option::Option; -use string::String; pub use core::u64::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/u8.rs b/src/libstd/num/u8.rs index 28f22429235..bdfcdb2c5a5 100644 --- a/src/libstd/num/u8.rs +++ b/src/libstd/num/u8.rs @@ -14,10 +14,9 @@ #![doc(primitive = "u8")] use from_str::FromStr; -use num::{ToStrRadix, FromStrRadix}; +use num::FromStrRadix; use num::strconv; use option::Option; -use string::String; pub use core::u8::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/uint.rs b/src/libstd/num/uint.rs index da328074453..5090219d3de 100644 --- a/src/libstd/num/uint.rs +++ b/src/libstd/num/uint.rs @@ -14,10 +14,9 @@ #![doc(primitive = "uint")] use from_str::FromStr; -use num::{ToStrRadix, FromStrRadix}; +use num::FromStrRadix; use num::strconv; use option::Option; -use string::String; pub use core::uint::{BITS, BYTES, MIN, MAX}; diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index a033308af16..f9bc9eb539a 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -82,36 +82,15 @@ pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U { f(buf[..amt]) } -#[deprecated = "use fmt::radix"] -impl ToStrRadix for $T { - /// Convert to a string in a given base. - #[inline] - fn to_str_radix(&self, radix: uint) -> String { - format!("{}", ::fmt::radix(*self, radix as u8)) - } -} - #[cfg(test)] mod tests { use prelude::*; use super::*; - use num::ToStrRadix; use str::StrSlice; use u16; #[test] - pub fn test_to_string() { - assert_eq!((0 as $T).to_str_radix(10u), "0".to_string()); - assert_eq!((1 as $T).to_str_radix(10u), "1".to_string()); - assert_eq!((2 as $T).to_str_radix(10u), "2".to_string()); - assert_eq!((11 as $T).to_str_radix(10u), "11".to_string()); - assert_eq!((11 as $T).to_str_radix(16u), "b".to_string()); - assert_eq!((255 as $T).to_str_radix(16u), "ff".to_string()); - assert_eq!((0xff as $T).to_str_radix(10u), "255".to_string()); - } - - #[test] pub fn test_from_str() { assert_eq!(from_str::<$T>("0"), Some(0u as $T)); assert_eq!(from_str::<$T>("3"), Some(3u as $T)); @@ -199,18 +178,6 @@ mod tests { assert_eq!(from_str::<u64>("0"), Some(u64_val)); assert!(from_str::<u64>("-1").is_none()); } - - #[test] - #[should_fail] - pub fn to_str_radix1() { - 100u.to_str_radix(1u); - } - - #[test] - #[should_fail] - pub fn to_str_radix37() { - 100u.to_str_radix(37u); - } } )) |
