Skip to content

Remove more deprecated functionality #24636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 22, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/doc/trpl/traits.md
Original file line number Diff line number Diff line change
@@ -336,7 +336,7 @@ This shows off the additional feature of `where` clauses: they allow bounds
where the left-hand side is an arbitrary type (`i32` in this case), not just a
plain type parameter (like `T`).

# Default methods
## Default methods

There’s one last feature of traits we should cover: default methods. It’s
easiest just to show an example:
1 change: 0 additions & 1 deletion src/libcollections/bit.rs
Original file line number Diff line number Diff line change
@@ -40,7 +40,6 @@
//! ```
//! # #![feature(collections, core, step_by)]
//! use std::collections::{BitSet, BitVec};
//! use std::num::Float;
//! use std::iter;
//!
//! let max_prime = 10000;
8 changes: 4 additions & 4 deletions src/libcollections/fmt.rs
Original file line number Diff line number Diff line change
@@ -175,7 +175,6 @@
//! # #![feature(core, std_misc)]
//! use std::fmt;
//! use std::f64;
//! use std::num::Float;
//!
//! #[derive(Debug)]
//! struct Vector2D {
@@ -200,10 +199,11 @@
//! let magnitude = magnitude.sqrt();
//!
//! // Respect the formatting flags by using the helper method
//! // `pad_integral` on the Formatter object. See the method documentation
//! // for details, and the function `pad` can be used to pad strings.
//! // `pad_integral` on the Formatter object. See the method
//! // documentation for details, and the function `pad` can be used
//! // to pad strings.
//! let decimals = f.precision().unwrap_or(3);
//! let string = f64::to_str_exact(magnitude, decimals);
//! let string = format!("{:.*}", decimals, magnitude);
//! f.pad_integral(true, "", &string)
//! }
//! }
2 changes: 1 addition & 1 deletion src/libcollections/slice.rs
Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@ use self::Direction::*;
use borrow::{Borrow, BorrowMut, ToOwned};
use vec::Vec;

pub use core::slice::{Chunks, AsSlice, Windows};
pub use core::slice::{Chunks, Windows};
pub use core::slice::{Iter, IterMut};
pub use core::slice::{IntSliceExt, SplitMut, ChunksMut, Split};
pub use core::slice::{SplitN, RSplitN, SplitNMut, RSplitNMut};
2 changes: 1 addition & 1 deletion src/libcollections/str.rs
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ use rustc_unicode;
use vec::Vec;
use slice::SliceConcatExt;

pub use core::str::{FromStr, Utf8Error, Str};
pub use core::str::{FromStr, Utf8Error};
pub use core::str::{Lines, LinesAny, CharRange};
pub use core::str::{Split, RSplit};
pub use core::str::{SplitN, RSplitN};
17 changes: 0 additions & 17 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
@@ -837,15 +837,6 @@ impl<'a, 'b> PartialEq<Cow<'a, str>> for &'b str {
fn ne(&self, other: &Cow<'a, str>) -> bool { PartialEq::ne(&self[..], &other[..]) }
}

#[unstable(feature = "collections", reason = "waiting on Str stabilization")]
#[allow(deprecated)]
impl Str for String {
#[inline]
fn as_slice(&self) -> &str {
unsafe { mem::transmute(&*self.vec) }
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl Default for String {
#[inline]
@@ -1067,14 +1058,6 @@ impl<'a> IntoCow<'a, str> for &'a str {
}
}

#[allow(deprecated)]
impl<'a> Str for Cow<'a, str> {
#[inline]
fn as_slice<'b>(&'b self) -> &'b str {
&**self
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Write for String {
#[inline]
12 changes: 0 additions & 12 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
@@ -1597,18 +1597,6 @@ impl<T: Ord> Ord for Vec<T> {
}
}

#[unstable(feature = "collections",
reason = "will be replaced by slice syntax")]
#[deprecated(since = "1.0.0", reason = "use &mut s[..] instead")]
#[allow(deprecated)]
impl<T> AsSlice<T> for Vec<T> {
/// Deprecated: use `&mut s[..]` instead.
#[inline]
fn as_slice(&self) -> &[T] {
self
}
}

#[unstable(feature = "collections",
reason = "recent addition, needs more experience")]
impl<'a, T: Clone> Add<&'a [T]> for Vec<T> {
43 changes: 29 additions & 14 deletions src/libcore/fmt/float.rs
Original file line number Diff line number Diff line change
@@ -11,15 +11,15 @@
pub use self::ExponentFormat::*;
pub use self::SignificantDigits::*;

use char::{self, CharExt};
use prelude::*;

use char;
use fmt;
use iter::Iterator;
use num::{cast, Float, ToPrimitive};
use num::Float;
use num::FpCategory as Fp;
use ops::FnOnce;
use result::Result::Ok;
use slice::{self, SliceExt};
use str::{self, StrExt};
use ops::{Div, Rem, Mul};
use slice;
use str;

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

#[doc(hidden)]
pub trait MyFloat: Float + PartialEq + PartialOrd + Div<Output=Self> +
Mul<Output=Self> + Rem<Output=Self> + Copy {
fn from_u32(u: u32) -> Self;
fn to_i32(&self) -> i32;
}

macro_rules! doit {
($($t:ident)*) => ($(impl MyFloat for $t {
fn from_u32(u: u32) -> $t { u as $t }
fn to_i32(&self) -> i32 { *self as i32 }
})*)
}
doit! { f32 f64 }

/// Converts a float number to its string representation.
/// This is meant to be a common base implementation for various formatting styles.
/// The number is assumed to be non-negative, callers use `Formatter::pad_integral`
@@ -63,7 +78,7 @@ pub enum SignificantDigits {
/// # Panics
///
/// - Panics if `num` is negative.
pub fn float_to_str_bytes_common<T: Float, U, F>(
pub fn float_to_str_bytes_common<T: MyFloat, U, F>(
num: T,
digits: SignificantDigits,
exp_format: ExponentFormat,
@@ -72,10 +87,10 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
) -> U where
F: FnOnce(&str) -> U,
{
let _0: T = Float::zero();
let _1: T = Float::one();
let _0: T = T::zero();
let _1: T = T::one();
let radix: u32 = 10;
let radix_f: T = cast(radix).unwrap();
let radix_f = T::from_u32(radix);

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

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

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

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

let current_digit = deccum.trunc();

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

24 changes: 8 additions & 16 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
@@ -12,21 +12,16 @@

#![stable(feature = "rust1", since = "1.0.0")]

use prelude::*;

use cell::{Cell, RefCell, Ref, RefMut, BorrowState};
use char::CharExt;
use clone::Clone;
use iter::Iterator;
use marker::{Copy, PhantomData, Sized};
use marker::PhantomData;
use mem;
use num::Float;
use option::Option;
use option::Option::{Some, None};
use result::Result::Ok;
use ops::{Deref, FnOnce};
use ops::Deref;
use result;
use slice::SliceExt;
use num::Float;
use slice;
use str::{self, StrExt};
use str;
use self::rt::v1::Alignment;

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

// Common code of floating point Debug and Display.
fn float_to_str_common<T: Float, F>(num: &T, precision: Option<usize>, post: F) -> Result
fn float_to_str_common<T: float::MyFloat, F>(num: &T, precision: Option<usize>,
post: F) -> Result
where F : FnOnce(&str) -> Result {
let digits = match precision {
Some(i) => float::DigExact(i),
@@ -950,8 +946,6 @@ macro_rules! floating { ($ty:ident) => {
#[stable(feature = "rust1", since = "1.0.0")]
impl LowerExp for $ty {
fn fmt(&self, fmt: &mut Formatter) -> Result {
use num::Float;

let digits = match fmt.precision {
Some(i) => float::DigExact(i),
None => float::DigMax(6),
@@ -969,8 +963,6 @@ macro_rules! floating { ($ty:ident) => {
#[stable(feature = "rust1", since = "1.0.0")]
impl UpperExp for $ty {
fn fmt(&self, fmt: &mut Formatter) -> Result {
use num::Float;

let digits = match fmt.precision {
Some(i) => float::DigExact(i),
None => float::DigMax(6),
43 changes: 29 additions & 14 deletions src/libcore/fmt/num.rs
Original file line number Diff line number Diff line change
@@ -14,12 +14,28 @@

#![allow(unsigned_negation)]

use prelude::*;

use fmt;
use iter::Iterator;
use num::{Int, cast};
use slice::SliceExt;
use num::Zero;
use ops::{Div, Rem, Sub};
use str;

#[doc(hidden)]
trait Int: Zero + PartialEq + PartialOrd + Div<Output=Self> + Rem<Output=Self> +
Sub<Output=Self> + Copy {
fn from_u8(u: u8) -> Self;
fn to_u8(&self) -> u8;
}

macro_rules! doit {
($($t:ident)*) => ($(impl Int for $t {
fn from_u8(u: u8) -> $t { u as $t }
fn to_u8(&self) -> u8 { *self as u8 }
})*)
}
doit! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize }

/// A type that represents a specific radix
#[doc(hidden)]
trait GenericRadix {
@@ -33,33 +49,32 @@ trait GenericRadix {
fn digit(&self, x: u8) -> u8;

/// Format an integer using the radix using a formatter.
#[allow(deprecated)] // Int
fn fmt_int<T: Int>(&self, mut x: T, f: &mut fmt::Formatter) -> fmt::Result {
// The radix can be as low as 2, so we need a buffer of at least 64
// characters for a base 2 number.
let zero = Int::zero();
let zero = T::zero();
let is_positive = x >= zero;
let mut buf = [0; 64];
let mut curr = buf.len();
let base = cast(self.base()).unwrap();
let base = T::from_u8(self.base());
if is_positive {
// Accumulate each digit of the number from the least significant
// to the most significant figure.
for byte in buf.iter_mut().rev() {
let n = x % base; // Get the current place value.
x = x / base; // Deaccumulate the number.
*byte = self.digit(cast(n).unwrap()); // Store the digit in the buffer.
let n = x % base; // Get the current place value.
x = x / base; // Deaccumulate the number.
*byte = self.digit(n.to_u8()); // Store the digit in the buffer.
curr -= 1;
if x == zero { break }; // No more digits left to accumulate.
if x == zero { break }; // No more digits left to accumulate.
}
} else {
// Do the same as above, but accounting for two's complement.
for byte in buf.iter_mut().rev() {
let n = zero - (x % base); // Get the current place value.
x = x / base; // Deaccumulate the number.
*byte = self.digit(cast(n).unwrap()); // Store the digit in the buffer.
let n = zero - (x % base); // Get the current place value.
x = x / base; // Deaccumulate the number.
*byte = self.digit(n.to_u8()); // Store the digit in the buffer.
curr -= 1;
if x == zero { break }; // No more digits left to accumulate.
if x == zero { break }; // No more digits left to accumulate.
}
}
let buf = unsafe { str::from_utf8_unchecked(&buf[curr..]) };
Loading