Rollup merge of #30943 - alexcrichton:stabilize-1.7, r=aturon

This commit stabilizes and deprecates the FCP (final comment period) APIs for
the upcoming 1.7 beta release. The specific APIs which changed were:

Stabilized

* `Path::strip_prefix` (renamed from `relative_from`)
* `path::StripPrefixError` (new error type returned from `strip_prefix`)
* `Ipv4Addr::is_loopback`
* `Ipv4Addr::is_private`
* `Ipv4Addr::is_link_local`
* `Ipv4Addr::is_multicast`
* `Ipv4Addr::is_broadcast`
* `Ipv4Addr::is_documentation`
* `Ipv6Addr::is_unspecified`
* `Ipv6Addr::is_loopback`
* `Ipv6Addr::is_unique_local`
* `Ipv6Addr::is_multicast`
* `Vec::as_slice`
* `Vec::as_mut_slice`
* `String::as_str`
* `String::as_mut_str`
* `<[T]>::clone_from_slice` - the `usize` return value is removed
* `<[T]>::sort_by_key`
* `i32::checked_rem` (and other signed types)
* `i32::checked_neg` (and other signed types)
* `i32::checked_shl` (and other signed types)
* `i32::checked_shr` (and other signed types)
* `i32::saturating_mul` (and other signed types)
* `i32::overflowing_add` (and other signed types)
* `i32::overflowing_sub` (and other signed types)
* `i32::overflowing_mul` (and other signed types)
* `i32::overflowing_div` (and other signed types)
* `i32::overflowing_rem` (and other signed types)
* `i32::overflowing_neg` (and other signed types)
* `i32::overflowing_shl` (and other signed types)
* `i32::overflowing_shr` (and other signed types)
* `u32::checked_rem` (and other unsigned types)
* `u32::checked_shl` (and other unsigned types)
* `u32::saturating_mul` (and other unsigned types)
* `u32::overflowing_add` (and other unsigned types)
* `u32::overflowing_sub` (and other unsigned types)
* `u32::overflowing_mul` (and other unsigned types)
* `u32::overflowing_div` (and other unsigned types)
* `u32::overflowing_rem` (and other unsigned types)
* `u32::overflowing_neg` (and other unsigned types)
* `u32::overflowing_shl` (and other unsigned types)
* `u32::overflowing_shr` (and other unsigned types)
* `ffi::IntoStringError`
* `CString::into_string`
* `CString::into_bytes`
* `CString::into_bytes_with_nul`
* `From<CString> for Vec<u8>`
* `From<CString> for Vec<u8>`
* `IntoStringError::into_cstring`
* `IntoStringError::utf8_error`
* `Error for IntoStringError`

Deprecated

* `Path::relative_from` - renamed to `strip_prefix`
* `Path::prefix` - use `components().next()` instead
* `os::unix::fs` constants - moved to the `libc` crate
* `fmt::{radix, Radix, RadixFmt}` - not used enough to stabilize
* `IntoCow` - conflicts with `Into` and may come back later
* `i32::{BITS, BYTES}` (and other integers) - not pulling their weight
* `DebugTuple::formatter` - will be removed
* `sync::Semaphore` - not used enough and confused with system semaphores

Closes #23284
cc #27709 (still lots more methods though)
Closes #27712
Closes #27722
Closes #27728
Closes #27735
Closes #27729
Closes #27755
Closes #27782
Closes #27798
This commit is contained in:
Manish Goregaokar
2016-01-17 17:25:47 +05:30
58 changed files with 356 additions and 235 deletions

View File

@@ -181,6 +181,7 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {
/// Returns the wrapped `Formatter`.
#[unstable(feature = "debug_builder_formatter", reason = "recently added",
issue = "27782")]
#[rustc_deprecated(since = "1.7.0", reason = "will be removed")]
pub fn formatter(&mut self) -> &mut fmt::Formatter<'b> {
&mut self.fmt
}

View File

@@ -25,10 +25,16 @@ use str;
use self::rt::v1::Alignment;
#[unstable(feature = "fmt_radix", issue = "27728")]
#[rustc_deprecated(since = "1.7.0", reason = "not used enough to stabilize")]
#[allow(deprecated)]
pub use self::num::radix;
#[unstable(feature = "fmt_radix", issue = "27728")]
#[rustc_deprecated(since = "1.7.0", reason = "not used enough to stabilize")]
#[allow(deprecated)]
pub use self::num::Radix;
#[unstable(feature = "fmt_radix", issue = "27728")]
#[rustc_deprecated(since = "1.7.0", reason = "not used enough to stabilize")]
#[allow(deprecated)]
pub use self::num::RadixFmt;
#[stable(feature = "debug_builders", since = "1.2.0")]
pub use self::builders::{DebugStruct, DebugTuple, DebugSet, DebugList, DebugMap};
@@ -1391,7 +1397,7 @@ impl<T> Pointer for *const T {
f.flags |= 1 << (FlagV1::SignAwareZeroPad as u32);
if let None = f.width {
f.width = Some((::usize::BITS/4) + 2);
f.width = Some(((mem::size_of::<usize>() * 8) / 4) + 2);
}
}
f.flags |= 1 << (FlagV1::Alternate as u32);
@@ -1532,7 +1538,7 @@ macro_rules! tuple {
( $($name:ident,)+ ) => (
#[stable(feature = "rust1", since = "1.0.0")]
impl<$($name:Debug),*> Debug for ($($name,)*) {
#[allow(non_snake_case, unused_assignments)]
#[allow(non_snake_case, unused_assignments, deprecated)]
fn fmt(&self, f: &mut Formatter) -> Result {
let mut builder = f.debug_tuple("");
let ($(ref $name,)*) = *self;

View File

@@ -10,6 +10,8 @@
//! Integer and floating-point number formatting
#![allow(deprecated)]
// FIXME: #6220 Implement floating point formatting
use prelude::v1::*;
@@ -143,6 +145,7 @@ radix! { UpperHex, 16, "0x", x @ 0 ... 9 => b'0' + x,
#[unstable(feature = "fmt_radix",
reason = "may be renamed or move to a different module",
issue = "27728")]
#[rustc_deprecated(since = "1.7.0", reason = "not used enough to stabilize")]
pub struct Radix {
base: u8,
}
@@ -173,6 +176,7 @@ impl GenericRadix for Radix {
#[unstable(feature = "fmt_radix",
reason = "may be renamed or move to a different module",
issue = "27728")]
#[rustc_deprecated(since = "1.7.0", reason = "not used enough to stabilize")]
#[derive(Copy, Clone)]
pub struct RadixFmt<T, R>(T, R);
@@ -189,6 +193,7 @@ pub struct RadixFmt<T, R>(T, R);
#[unstable(feature = "fmt_radix",
reason = "may be renamed or move to a different module",
issue = "27728")]
#[rustc_deprecated(since = "1.7.0", reason = "not used enough to stabilize")]
pub fn radix<T>(x: T, base: u8) -> RadixFmt<T, Radix> {
RadixFmt(x, Radix::new(base))
}

View File

@@ -195,6 +195,7 @@ pub trait Hasher {
mod impls {
use prelude::v1::*;
use mem;
use slice;
use super::*;
@@ -207,9 +208,7 @@ mod impls {
}
fn hash_slice<H: Hasher>(data: &[$ty], state: &mut H) {
// FIXME(#23542) Replace with type ascription.
#![allow(trivial_casts)]
let newlen = data.len() * ::$ty::BYTES;
let newlen = data.len() * mem::size_of::<$ty>();
let ptr = data.as_ptr() as *const u8;
state.write(unsafe { slice::from_raw_parts(ptr, newlen) })
}

View File

@@ -210,7 +210,7 @@ impl<'a> Part<'a> {
}
}
Part::Copy(buf) => {
out.clone_from_slice(buf);
out[..buf.len()].clone_from_slice(buf);
}
}
Some(len)
@@ -245,7 +245,7 @@ impl<'a> Formatted<'a> {
/// (It may still leave partially written bytes in the buffer; do not rely on that.)
pub fn write(&self, out: &mut [u8]) -> Option<usize> {
if out.len() < self.sign.len() { return None; }
out.clone_from_slice(self.sign);
out[..self.sign.len()].clone_from_slice(self.sign);
let mut written = self.sign.len();
for part in self.parts {

View File

@@ -17,6 +17,8 @@ macro_rules! int_module { ($T:ty, $bits:expr) => (
#[unstable(feature = "num_bits_bytes",
reason = "may want to be an associated function",
issue = "27753")]
#[rustc_deprecated(since = "1.7.0",
reason = "will be replaced via const fn or associated constants")]
#[allow(missing_docs)]
pub const BITS : usize = $bits;
// FIXME(#11621): Should be deprecated once CTFE is implemented in favour of
@@ -24,6 +26,8 @@ pub const BITS : usize = $bits;
#[unstable(feature = "num_bits_bytes",
reason = "may want to be an associated function",
issue = "27753")]
#[rustc_deprecated(since = "1.7.0",
reason = "will be replaced via const fn or associated constants")]
#[allow(missing_docs)]
pub const BYTES : usize = ($bits / 8);
@@ -31,7 +35,7 @@ pub const BYTES : usize = ($bits / 8);
// calling the `Bounded::min_value` function.
#[stable(feature = "rust1", since = "1.0.0")]
#[allow(missing_docs)]
pub const MIN: $T = (-1 as $T) << (BITS - 1);
pub const MIN: $T = (-1 as $T) << ($bits - 1);
// FIXME(#9837): Compute MIN like this so the high bits that shouldn't exist are 0.
// FIXME(#11621): Should be deprecated once CTFE is implemented in favour of
// calling the `Bounded::max_value` function.

View File

@@ -13,8 +13,6 @@
#![stable(feature = "rust1", since = "1.0.0")]
#![allow(missing_docs)]
use self::wrapping::OverflowingOps;
use char::CharExt;
use cmp::{Eq, PartialOrd};
use convert::From;
@@ -464,15 +462,13 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// #![feature(wrapping)]
///
/// use std::i32;
///
/// assert_eq!(5i32.checked_rem(2), Some(1));
/// assert_eq!(5i32.checked_rem(0), None);
/// assert_eq!(i32::MIN.checked_rem(-1), None);
/// ```
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
#[inline]
pub fn checked_rem(self, other: Self) -> Option<Self> {
if other == 0 {
@@ -491,14 +487,12 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// #![feature(wrapping)]
///
/// use std::i32;
///
/// assert_eq!(5i32.checked_neg(), Some(-5));
/// assert_eq!(i32::MIN.checked_neg(), None);
/// ```
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
#[inline]
pub fn checked_neg(self) -> Option<Self> {
let (a, b) = self.overflowing_neg();
@@ -513,12 +507,10 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// #![feature(wrapping)]
///
/// assert_eq!(0x10i32.checked_shl(4), Some(0x100));
/// assert_eq!(0x10i32.checked_shl(33), None);
/// ```
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
#[inline]
pub fn checked_shl(self, rhs: u32) -> Option<Self> {
let (a, b) = self.overflowing_shl(rhs);
@@ -533,12 +525,10 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// #![feature(wrapping)]
///
/// assert_eq!(0x10i32.checked_shr(4), Some(0x1));
/// assert_eq!(0x10i32.checked_shr(33), None);
/// ```
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
#[inline]
pub fn checked_shr(self, rhs: u32) -> Option<Self> {
let (a, b) = self.overflowing_shr(rhs);
@@ -595,15 +585,13 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// #![feature(wrapping)]
///
/// use std::i32;
///
/// assert_eq!(100i32.saturating_mul(127), 12700);
/// assert_eq!((1i32 << 23).saturating_mul(1 << 23), i32::MAX);
/// assert_eq!((-1i32 << 23).saturating_mul(1 << 23), i32::MIN);
/// ```
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
#[inline]
pub fn saturating_mul(self, other: Self) -> Self {
self.checked_mul(other).unwrap_or_else(|| {
@@ -796,15 +784,13 @@ macro_rules! int_impl {
/// Basic usage
///
/// ```
/// #![feature(wrapping)]
///
/// use std::i32;
///
/// assert_eq!(5i32.overflowing_add(2), (7, false));
/// assert_eq!(i32::MAX.overflowing_add(1), (i32::MIN, true));
/// ```
#[inline]
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
pub fn overflowing_add(self, rhs: Self) -> (Self, bool) {
unsafe {
let (a, b) = $add_with_overflow(self as $ActualT,
@@ -824,15 +810,13 @@ macro_rules! int_impl {
/// Basic usage
///
/// ```
/// #![feature(wrapping)]
///
/// use std::i32;
///
/// assert_eq!(5i32.overflowing_sub(2), (3, false));
/// assert_eq!(i32::MIN.overflowing_sub(1), (i32::MAX, true));
/// ```
#[inline]
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
pub fn overflowing_sub(self, rhs: Self) -> (Self, bool) {
unsafe {
let (a, b) = $sub_with_overflow(self as $ActualT,
@@ -852,13 +836,11 @@ macro_rules! int_impl {
/// Basic usage
///
/// ```
/// #![feature(wrapping)]
///
/// assert_eq!(5i32.overflowing_mul(2), (10, false));
/// assert_eq!(1_000_000_000i32.overflowing_mul(10), (1410065408, true));
/// ```
#[inline]
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
pub fn overflowing_mul(self, rhs: Self) -> (Self, bool) {
unsafe {
let (a, b) = $mul_with_overflow(self as $ActualT,
@@ -882,15 +864,13 @@ macro_rules! int_impl {
/// Basic usage
///
/// ```
/// #![feature(wrapping)]
///
/// use std::i32;
///
/// assert_eq!(5i32.overflowing_div(2), (2, false));
/// assert_eq!(i32::MIN.overflowing_div(-1), (i32::MIN, true));
/// ```
#[inline]
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
pub fn overflowing_div(self, rhs: Self) -> (Self, bool) {
if self == Self::min_value() && rhs == -1 {
(self, true)
@@ -914,15 +894,13 @@ macro_rules! int_impl {
/// Basic usage
///
/// ```
/// #![feature(wrapping)]
///
/// use std::i32;
///
/// assert_eq!(5i32.overflowing_rem(2), (1, false));
/// assert_eq!(i32::MIN.overflowing_rem(-1), (0, true));
/// ```
#[inline]
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
pub fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
if self == Self::min_value() && rhs == -1 {
(0, true)
@@ -944,15 +922,13 @@ macro_rules! int_impl {
/// Basic usage
///
/// ```
/// #![feature(wrapping)]
///
/// use std::i32;
///
/// assert_eq!(2i32.overflowing_neg(), (-2, false));
/// assert_eq!(i32::MIN.overflowing_neg(), (i32::MIN, true));
/// ```
#[inline]
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
pub fn overflowing_neg(self) -> (Self, bool) {
if self == Self::min_value() {
(Self::min_value(), true)
@@ -974,13 +950,11 @@ macro_rules! int_impl {
/// Basic usage
///
/// ```
/// #![feature(wrapping)]
///
/// assert_eq!(0x10i32.overflowing_shl(4), (0x100, false));
/// assert_eq!(0x10i32.overflowing_shl(36), (0x100, true));
/// ```
#[inline]
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
pub fn overflowing_shl(self, rhs: u32) -> (Self, bool) {
(self << (rhs & ($BITS - 1)), (rhs > ($BITS - 1)))
}
@@ -998,13 +972,11 @@ macro_rules! int_impl {
/// Basic usage
///
/// ```
/// #![feature(wrapping)]
///
/// assert_eq!(0x10i32.overflowing_shr(4), (0x1, false));
/// assert_eq!(0x10i32.overflowing_shr(36), (0x1, true));
/// ```
#[inline]
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
pub fn overflowing_shr(self, rhs: u32) -> (Self, bool) {
(self >> (rhs & ($BITS - 1)), (rhs > ($BITS - 1)))
}
@@ -1542,12 +1514,10 @@ macro_rules! uint_impl {
/// Basic usage:
///
/// ```
/// #![feature(wrapping)]
///
/// assert_eq!(5u32.checked_rem(2), Some(1));
/// assert_eq!(5u32.checked_rem(0), None);
/// ```
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
#[inline]
pub fn checked_rem(self, other: Self) -> Option<Self> {
if other == 0 {
@@ -1557,6 +1527,26 @@ macro_rules! uint_impl {
}
}
/// Checked negation. Computes `-self`, returning `None` unless `self ==
/// 0`.
///
/// Note that negating any positive integer will overflow.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// assert_eq!(0u32.checked_neg(), Some(0));
/// assert_eq!(1u32.checked_neg(), None);
/// ```
#[stable(feature = "wrapping", since = "1.7.0")]
#[inline]
pub fn checked_neg(self) -> Option<Self> {
let (a, b) = self.overflowing_neg();
if b {None} else {Some(a)}
}
/// Checked shift left. Computes `self << rhs`, returning `None`
/// if `rhs` is larger than or equal to the number of bits in `self`.
///
@@ -1565,12 +1555,10 @@ macro_rules! uint_impl {
/// Basic usage:
///
/// ```
/// #![feature(wrapping)]
///
/// assert_eq!(0x10u32.checked_shl(4), Some(0x100));
/// assert_eq!(0x10u32.checked_shl(33), None);
/// ```
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
#[inline]
pub fn checked_shl(self, rhs: u32) -> Option<Self> {
let (a, b) = self.overflowing_shl(rhs);
@@ -1585,12 +1573,10 @@ macro_rules! uint_impl {
/// Basic usage:
///
/// ```
/// #![feature(wrapping)]
///
/// assert_eq!(0x10u32.checked_shr(4), Some(0x1));
/// assert_eq!(0x10u32.checked_shr(33), None);
/// ```
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
#[inline]
pub fn checked_shr(self, rhs: u32) -> Option<Self> {
let (a, b) = self.overflowing_shr(rhs);
@@ -1647,14 +1633,12 @@ macro_rules! uint_impl {
/// Basic usage:
///
/// ```
/// #![feature(wrapping)]
///
/// use std::u32;
///
/// assert_eq!(100u32.saturating_mul(127), 12700);
/// assert_eq!((1u32 << 23).saturating_mul(1 << 23), u32::MAX);
/// ```
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
#[inline]
pub fn saturating_mul(self, other: Self) -> Self {
self.checked_mul(other).unwrap_or(Self::max_value())
@@ -1833,15 +1817,13 @@ macro_rules! uint_impl {
/// Basic usage
///
/// ```
/// #![feature(wrapping)]
///
/// use std::u32;
///
/// assert_eq!(5u32.overflowing_add(2), (7, false));
/// assert_eq!(u32::MAX.overflowing_add(1), (0, true));
/// ```
#[inline]
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
pub fn overflowing_add(self, rhs: Self) -> (Self, bool) {
unsafe {
let (a, b) = $add_with_overflow(self as $ActualT,
@@ -1861,15 +1843,13 @@ macro_rules! uint_impl {
/// Basic usage
///
/// ```
/// #![feature(wrapping)]
///
/// use std::u32;
///
/// assert_eq!(5u32.overflowing_sub(2), (3, false));
/// assert_eq!(0u32.overflowing_sub(1), (u32::MAX, true));
/// ```
#[inline]
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
pub fn overflowing_sub(self, rhs: Self) -> (Self, bool) {
unsafe {
let (a, b) = $sub_with_overflow(self as $ActualT,
@@ -1889,13 +1869,11 @@ macro_rules! uint_impl {
/// Basic usage
///
/// ```
/// #![feature(wrapping)]
///
/// assert_eq!(5u32.overflowing_mul(2), (10, false));
/// assert_eq!(1_000_000_000u32.overflowing_mul(10), (1410065408, true));
/// ```
#[inline]
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
pub fn overflowing_mul(self, rhs: Self) -> (Self, bool) {
unsafe {
let (a, b) = $mul_with_overflow(self as $ActualT,
@@ -1920,12 +1898,10 @@ macro_rules! uint_impl {
/// Basic usage
///
/// ```
/// #![feature(wrapping)]
///
/// assert_eq!(5u32.overflowing_div(2), (2, false));
/// ```
#[inline]
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
pub fn overflowing_div(self, rhs: Self) -> (Self, bool) {
(self / rhs, false)
}
@@ -1946,12 +1922,10 @@ macro_rules! uint_impl {
/// Basic usage
///
/// ```
/// #![feature(wrapping)]
///
/// assert_eq!(5u32.overflowing_rem(2), (1, false));
/// ```
#[inline]
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
pub fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
(self % rhs, false)
}
@@ -1968,13 +1942,11 @@ macro_rules! uint_impl {
/// Basic usage
///
/// ```
/// #![feature(wrapping)]
///
/// assert_eq!(0u32.overflowing_neg(), (0, false));
/// assert_eq!(2u32.overflowing_neg(), (-2i32 as u32, true));
/// ```
#[inline]
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
pub fn overflowing_neg(self) -> (Self, bool) {
((!self).wrapping_add(1), self != 0)
}
@@ -1992,13 +1964,11 @@ macro_rules! uint_impl {
/// Basic usage
///
/// ```
/// #![feature(wrapping)]
///
/// assert_eq!(0x10u32.overflowing_shl(4), (0x100, false));
/// assert_eq!(0x10u32.overflowing_shl(36), (0x100, true));
/// ```
#[inline]
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
pub fn overflowing_shl(self, rhs: u32) -> (Self, bool) {
(self << (rhs & ($BITS - 1)), (rhs > ($BITS - 1)))
}
@@ -2016,13 +1986,11 @@ macro_rules! uint_impl {
/// Basic usage
///
/// ```
/// #![feature(wrapping)]
///
/// assert_eq!(0x10u32.overflowing_shr(4), (0x1, false));
/// assert_eq!(0x10u32.overflowing_shr(36), (0x1, true));
/// ```
#[inline]
#[unstable(feature = "wrapping", issue = "27755")]
#[stable(feature = "wrapping", since = "1.7.0")]
pub fn overflowing_shr(self, rhs: u32) -> (Self, bool) {
(self >> (rhs & ($BITS - 1)), (rhs > ($BITS - 1)))
}

View File

@@ -15,11 +15,15 @@ macro_rules! uint_module { ($T:ty, $T_SIGNED:ty, $bits:expr) => (
#[unstable(feature = "num_bits_bytes",
reason = "may want to be an associated function",
issue = "27753")]
#[rustc_deprecated(since = "1.7.0",
reason = "will be replaced via const fn or associated constants")]
#[allow(missing_docs)]
pub const BITS : usize = $bits;
#[unstable(feature = "num_bits_bytes",
reason = "may want to be an associated function",
issue = "27753")]
#[rustc_deprecated(since = "1.7.0",
reason = "will be replaced via const fn or associated constants")]
#[allow(missing_docs)]
pub const BYTES : usize = ($bits / 8);

View File

@@ -14,4 +14,7 @@
#![stable(feature = "rust1", since = "1.0.0")]
uint_module! { usize, isize, ::isize::BITS }
#[cfg(target_pointer_width = "32")]
uint_module! { usize, isize, 32 }
#[cfg(target_pointer_width = "64")]
uint_module! { usize, isize, 64 }

View File

@@ -9,7 +9,7 @@
// except according to those terms.
#![allow(missing_docs)]
#![unstable(feature = "wrapping", reason = "may be removed or relocated",
#![unstable(feature = "old_wrapping", reason = "may be removed or relocated",
issue = "27755")]
use intrinsics::{add_with_overflow, sub_with_overflow, mul_with_overflow};
@@ -20,6 +20,9 @@ use ops::*;
use ::{i8, i16, i32, i64, isize};
#[unstable(feature = "old_wrapping", reason = "may be removed or relocated",
issue = "27755")]
#[rustc_deprecated(since = "1.7.0", reason = "moved to inherent methods")]
pub trait OverflowingOps {
fn overflowing_add(self, rhs: Self) -> (Self, bool);
fn overflowing_sub(self, rhs: Self) -> (Self, bool);
@@ -331,6 +334,7 @@ mod shift_max {
macro_rules! signed_overflowing_impl {
($($t:ident)*) => ($(
#[allow(deprecated)]
impl OverflowingOps for $t {
#[inline(always)]
fn overflowing_add(self, rhs: $t) -> ($t, bool) {
@@ -393,6 +397,7 @@ macro_rules! signed_overflowing_impl {
macro_rules! unsigned_overflowing_impl {
($($t:ident)*) => ($(
#[allow(deprecated)]
impl OverflowingOps for $t {
#[inline(always)]
fn overflowing_add(self, rhs: $t) -> ($t, bool) {

View File

@@ -49,7 +49,6 @@ use result::Result::{Ok, Err};
use ptr;
use mem;
use marker::{Send, Sync, self};
use num::wrapping::OverflowingOps;
use raw::Repr;
// Avoid conflicts with *both* the Slice trait (buggy) and the `slice::raw` module.
use raw::Slice as RawSlice;
@@ -151,8 +150,8 @@ pub trait SliceExt {
#[stable(feature = "core", since = "1.6.0")]
fn ends_with(&self, needle: &[Self::Item]) -> bool where Self::Item: PartialEq;
#[unstable(feature = "clone_from_slice", issue= "27750")]
fn clone_from_slice(&mut self, &[Self::Item]) -> usize where Self::Item: Clone;
#[stable(feature = "clone_from_slice", since = "1.7.0")]
fn clone_from_slice(&mut self, &[Self::Item]) where Self::Item: Clone;
}
// Use macros to be generic over const/mut
@@ -476,14 +475,12 @@ impl<T> SliceExt for [T] {
}
#[inline]
fn clone_from_slice(&mut self, src: &[T]) -> usize where T: Clone {
let min = cmp::min(self.len(), src.len());
let dst = &mut self[.. min];
let src = &src[.. min];
for i in 0..min {
dst[i].clone_from(&src[i]);
fn clone_from_slice(&mut self, src: &[T]) where T: Clone {
assert!(self.len() == src.len(),
"destination and source slices have different lengths");
for (dst, src) in self.iter_mut().zip(src) {
dst.clone_from(src);
}
min
}
}

View File

@@ -32,7 +32,6 @@ use option::Option::{self, None, Some};
use raw::{Repr, Slice};
use result::Result::{self, Ok, Err};
use slice::{self, SliceExt};
use usize;
pub mod pattern;
@@ -1160,15 +1159,16 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
// Ascii case, try to skip forward quickly.
// When the pointer is aligned, read 2 words of data per iteration
// until we find a word containing a non-ascii byte.
const BYTES_PER_ITERATION: usize = 2 * usize::BYTES;
let usize_bytes = mem::size_of::<usize>();
let bytes_per_iteration = 2 * usize_bytes;
let ptr = v.as_ptr();
let align = (ptr as usize + offset) & (usize::BYTES - 1);
let align = (ptr as usize + offset) & (usize_bytes - 1);
if align == 0 {
if len >= BYTES_PER_ITERATION {
while offset <= len - BYTES_PER_ITERATION {
if len >= bytes_per_iteration {
while offset <= len - bytes_per_iteration {
unsafe {
let u = *(ptr.offset(offset as isize) as *const usize);
let v = *(ptr.offset((offset + usize::BYTES) as isize) as *const usize);
let v = *(ptr.offset((offset + usize_bytes) as isize) as *const usize);
// break if there is a nonascii byte
let zu = contains_nonascii(u);
@@ -1177,7 +1177,7 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
break;
}
}
offset += BYTES_PER_ITERATION;
offset += bytes_per_iteration;
}
}
// step from the point where the wordwise loop stopped