Skip to content

Commit eeb9488

Browse files
committed
std: Remove deprecated/unstable num functionality
This commit removes all the old casting/generic traits from `std::num` that are no longer in use by the standard library. This additionally removes the old `strconv` module which has not seen much use in quite a long time. All generic functionality has been supplanted with traits in the `num` crate and the `strconv` module is supplanted with the [rust-strconv crate][rust-strconv]. [rust-strconv]: https://github.com/lifthrasiir/rust-strconv This is a breaking change due to the removal of these deprecated crates, and the alternative crates are listed above. [breaking-change]
1 parent e091ba3 commit eeb9488

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+623
-5599
lines changed

src/libcollections/string.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1058,14 +1058,6 @@ impl<'a> IntoCow<'a, str> for &'a str {
10581058
}
10591059
}
10601060

1061-
#[allow(deprecated)]
1062-
impl<'a> Str for Cow<'a, str> {
1063-
#[inline]
1064-
fn as_slice<'b>(&'b self) -> &'b str {
1065-
&**self
1066-
}
1067-
}
1068-
10691061
#[stable(feature = "rust1", since = "1.0.0")]
10701062
impl fmt::Write for String {
10711063
#[inline]

src/libcore/fmt/float.rs

+29-14
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
pub use self::ExponentFormat::*;
1212
pub use self::SignificantDigits::*;
1313

14-
use char::{self, CharExt};
14+
use prelude::*;
15+
16+
use char;
1517
use fmt;
16-
use iter::Iterator;
17-
use num::{cast, Float, ToPrimitive};
18+
use num::Float;
1819
use num::FpCategory as Fp;
19-
use ops::FnOnce;
20-
use result::Result::Ok;
21-
use slice::{self, SliceExt};
22-
use str::{self, StrExt};
20+
use ops::{Div, Rem, Mul};
21+
use slice;
22+
use str;
2323

2424
/// A flag that specifies whether to use exponential (scientific) notation.
2525
pub enum ExponentFormat {
@@ -42,6 +42,21 @@ pub enum SignificantDigits {
4242
DigExact(usize)
4343
}
4444

45+
#[doc(hidden)]
46+
pub trait MyFloat: Float + PartialEq + PartialOrd + Div<Output=Self> +
47+
Mul<Output=Self> + Rem<Output=Self> + Copy {
48+
fn from_u32(u: u32) -> Self;
49+
fn to_i32(&self) -> i32;
50+
}
51+
52+
macro_rules! doit {
53+
($($t:ident)*) => ($(impl MyFloat for $t {
54+
fn from_u32(u: u32) -> $t { u as $t }
55+
fn to_i32(&self) -> i32 { *self as i32 }
56+
})*)
57+
}
58+
doit! { f32 f64 }
59+
4560
/// Converts a float number to its string representation.
4661
/// This is meant to be a common base implementation for various formatting styles.
4762
/// The number is assumed to be non-negative, callers use `Formatter::pad_integral`
@@ -63,7 +78,7 @@ pub enum SignificantDigits {
6378
/// # Panics
6479
///
6580
/// - Panics if `num` is negative.
66-
pub fn float_to_str_bytes_common<T: Float, U, F>(
81+
pub fn float_to_str_bytes_common<T: MyFloat, U, F>(
6782
num: T,
6883
digits: SignificantDigits,
6984
exp_format: ExponentFormat,
@@ -72,10 +87,10 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
7287
) -> U where
7388
F: FnOnce(&str) -> U,
7489
{
75-
let _0: T = Float::zero();
76-
let _1: T = Float::one();
90+
let _0: T = T::zero();
91+
let _1: T = T::one();
7792
let radix: u32 = 10;
78-
let radix_f: T = cast(radix).unwrap();
93+
let radix_f = T::from_u32(radix);
7994

8095
assert!(num.is_nan() || num >= _0, "float_to_str_bytes_common: number is negative");
8196

@@ -99,7 +114,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
99114
let (num, exp) = match exp_format {
100115
ExpDec if num != _0 => {
101116
let exp = num.log10().floor();
102-
(num / radix_f.powf(exp), cast::<T, i32>(exp).unwrap())
117+
(num / radix_f.powf(exp), exp.to_i32())
103118
}
104119
_ => (num, 0)
105120
};
@@ -114,7 +129,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
114129
deccum = deccum / radix_f;
115130
deccum = deccum.trunc();
116131

117-
let c = char::from_digit(current_digit.to_isize().unwrap() as u32, radix);
132+
let c = char::from_digit(current_digit.to_i32() as u32, radix);
118133
buf[end] = c.unwrap() as u8;
119134
end += 1;
120135

@@ -158,7 +173,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
158173

159174
let current_digit = deccum.trunc();
160175

161-
let c = char::from_digit(current_digit.to_isize().unwrap() as u32, radix);
176+
let c = char::from_digit(current_digit.to_i32() as u32, radix);
162177
buf[end] = c.unwrap() as u8;
163178
end += 1;
164179

src/libcore/fmt/mod.rs

+8-16
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,16 @@
1212
1313
#![stable(feature = "rust1", since = "1.0.0")]
1414

15+
use prelude::*;
16+
1517
use cell::{Cell, RefCell, Ref, RefMut, BorrowState};
16-
use char::CharExt;
17-
use clone::Clone;
18-
use iter::Iterator;
19-
use marker::{Copy, PhantomData, Sized};
18+
use marker::PhantomData;
2019
use mem;
21-
use num::Float;
22-
use option::Option;
23-
use option::Option::{Some, None};
24-
use result::Result::Ok;
25-
use ops::{Deref, FnOnce};
20+
use ops::Deref;
2621
use result;
27-
use slice::SliceExt;
22+
use num::Float;
2823
use slice;
29-
use str::{self, StrExt};
24+
use str;
3025
use self::rt::v1::Alignment;
3126

3227
pub use self::num::radix;
@@ -912,7 +907,8 @@ impl<'a, T> Pointer for &'a mut T {
912907
}
913908

914909
// Common code of floating point Debug and Display.
915-
fn float_to_str_common<T: Float, F>(num: &T, precision: Option<usize>, post: F) -> Result
910+
fn float_to_str_common<T: float::MyFloat, F>(num: &T, precision: Option<usize>,
911+
post: F) -> Result
916912
where F : FnOnce(&str) -> Result {
917913
let digits = match precision {
918914
Some(i) => float::DigExact(i),
@@ -950,8 +946,6 @@ macro_rules! floating { ($ty:ident) => {
950946
#[stable(feature = "rust1", since = "1.0.0")]
951947
impl LowerExp for $ty {
952948
fn fmt(&self, fmt: &mut Formatter) -> Result {
953-
use num::Float;
954-
955949
let digits = match fmt.precision {
956950
Some(i) => float::DigExact(i),
957951
None => float::DigMax(6),
@@ -969,8 +963,6 @@ macro_rules! floating { ($ty:ident) => {
969963
#[stable(feature = "rust1", since = "1.0.0")]
970964
impl UpperExp for $ty {
971965
fn fmt(&self, fmt: &mut Formatter) -> Result {
972-
use num::Float;
973-
974966
let digits = match fmt.precision {
975967
Some(i) => float::DigExact(i),
976968
None => float::DigMax(6),

src/libcore/fmt/num.rs

+29-14
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,28 @@
1414

1515
#![allow(unsigned_negation)]
1616

17+
use prelude::*;
18+
1719
use fmt;
18-
use iter::Iterator;
19-
use num::{Int, cast};
20-
use slice::SliceExt;
20+
use num::Zero;
21+
use ops::{Div, Rem, Sub};
2122
use str;
2223

24+
#[doc(hidden)]
25+
trait Int: Zero + PartialEq + PartialOrd + Div<Output=Self> + Rem<Output=Self> +
26+
Sub<Output=Self> + Copy {
27+
fn from_u8(u: u8) -> Self;
28+
fn to_u8(&self) -> u8;
29+
}
30+
31+
macro_rules! doit {
32+
($($t:ident)*) => ($(impl Int for $t {
33+
fn from_u8(u: u8) -> $t { u as $t }
34+
fn to_u8(&self) -> u8 { *self as u8 }
35+
})*)
36+
}
37+
doit! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize }
38+
2339
/// A type that represents a specific radix
2440
#[doc(hidden)]
2541
trait GenericRadix {
@@ -33,33 +49,32 @@ trait GenericRadix {
3349
fn digit(&self, x: u8) -> u8;
3450

3551
/// Format an integer using the radix using a formatter.
36-
#[allow(deprecated)] // Int
3752
fn fmt_int<T: Int>(&self, mut x: T, f: &mut fmt::Formatter) -> fmt::Result {
3853
// The radix can be as low as 2, so we need a buffer of at least 64
3954
// characters for a base 2 number.
40-
let zero = Int::zero();
55+
let zero = T::zero();
4156
let is_positive = x >= zero;
4257
let mut buf = [0; 64];
4358
let mut curr = buf.len();
44-
let base = cast(self.base()).unwrap();
59+
let base = T::from_u8(self.base());
4560
if is_positive {
4661
// Accumulate each digit of the number from the least significant
4762
// to the most significant figure.
4863
for byte in buf.iter_mut().rev() {
49-
let n = x % base; // Get the current place value.
50-
x = x / base; // Deaccumulate the number.
51-
*byte = self.digit(cast(n).unwrap()); // Store the digit in the buffer.
64+
let n = x % base; // Get the current place value.
65+
x = x / base; // Deaccumulate the number.
66+
*byte = self.digit(n.to_u8()); // Store the digit in the buffer.
5267
curr -= 1;
53-
if x == zero { break }; // No more digits left to accumulate.
68+
if x == zero { break }; // No more digits left to accumulate.
5469
}
5570
} else {
5671
// Do the same as above, but accounting for two's complement.
5772
for byte in buf.iter_mut().rev() {
58-
let n = zero - (x % base); // Get the current place value.
59-
x = x / base; // Deaccumulate the number.
60-
*byte = self.digit(cast(n).unwrap()); // Store the digit in the buffer.
73+
let n = zero - (x % base); // Get the current place value.
74+
x = x / base; // Deaccumulate the number.
75+
*byte = self.digit(n.to_u8()); // Store the digit in the buffer.
6176
curr -= 1;
62-
if x == zero { break }; // No more digits left to accumulate.
77+
if x == zero { break }; // No more digits left to accumulate.
6378
}
6479
}
6580
let buf = unsafe { str::from_utf8_unchecked(&buf[curr..]) };

src/libcore/iter.rs

+1-75
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use cmp::{Ord, PartialOrd, PartialEq};
6464
use default::Default;
6565
use marker;
6666
use mem;
67-
use num::{Int, Zero, One};
67+
use num::{Zero, One};
6868
use ops::{self, Add, Sub, FnMut, Mul, RangeFrom};
6969
use option::Option::{self, Some, None};
7070
use marker::Sized;
@@ -2647,80 +2647,6 @@ impl<A: Step + Zero + Clone> Iterator for StepBy<A, ops::Range<A>> {
26472647
}
26482648
}
26492649

2650-
/// An iterator over the range [start, stop] by `step`. It handles overflow by stopping.
2651-
#[derive(Clone)]
2652-
#[unstable(feature = "core",
2653-
reason = "likely to be replaced by range notation and adapters")]
2654-
pub struct RangeStepInclusive<A> {
2655-
state: A,
2656-
stop: A,
2657-
step: A,
2658-
rev: bool,
2659-
done: bool,
2660-
}
2661-
2662-
/// Returns an iterator over the range [start, stop] by `step`.
2663-
///
2664-
/// It handles overflow by stopping.
2665-
///
2666-
/// # Examples
2667-
///
2668-
/// ```
2669-
/// # #![feature(core)]
2670-
/// use std::iter::range_step_inclusive;
2671-
///
2672-
/// for i in range_step_inclusive(0, 10, 2) {
2673-
/// println!("{}", i);
2674-
/// }
2675-
/// ```
2676-
///
2677-
/// This prints:
2678-
///
2679-
/// ```text
2680-
/// 0
2681-
/// 2
2682-
/// 4
2683-
/// 6
2684-
/// 8
2685-
/// 10
2686-
/// ```
2687-
#[inline]
2688-
#[unstable(feature = "core",
2689-
reason = "likely to be replaced by range notation and adapters")]
2690-
#[allow(deprecated)]
2691-
pub fn range_step_inclusive<A: Int>(start: A, stop: A, step: A) -> RangeStepInclusive<A> {
2692-
let rev = step < Int::zero();
2693-
RangeStepInclusive {
2694-
state: start,
2695-
stop: stop,
2696-
step: step,
2697-
rev: rev,
2698-
done: false,
2699-
}
2700-
}
2701-
2702-
#[unstable(feature = "core",
2703-
reason = "likely to be replaced by range notation and adapters")]
2704-
#[allow(deprecated)]
2705-
impl<A: Int> Iterator for RangeStepInclusive<A> {
2706-
type Item = A;
2707-
2708-
#[inline]
2709-
fn next(&mut self) -> Option<A> {
2710-
if !self.done && ((self.rev && self.state >= self.stop) ||
2711-
(!self.rev && self.state <= self.stop)) {
2712-
let result = self.state;
2713-
match self.state.checked_add(self.step) {
2714-
Some(x) => self.state = x,
2715-
None => self.done = true
2716-
}
2717-
Some(result)
2718-
} else {
2719-
None
2720-
}
2721-
}
2722-
}
2723-
27242650
macro_rules! range_exact_iter_impl {
27252651
($($t:ty)*) => ($(
27262652
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)