diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-03-31 11:34:17 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-31 15:54:44 -0700 |
| commit | 554946c81eeb4fcfceda782f6c5af394ab3fe8d3 (patch) | |
| tree | 26908e2779beed76296fbe7292bdf6af12dd46f7 /src/libcore | |
| parent | e10ee2c8572421c056ea68e6656fee936e0330d8 (diff) | |
| parent | d4a2c941809f303b97d153e06ba07e95cd245f88 (diff) | |
| download | rust-554946c81eeb4fcfceda782f6c5af394ab3fe8d3.tar.gz rust-554946c81eeb4fcfceda782f6c5af394ab3fe8d3.zip | |
rollup merge of #23873: alexcrichton/remove-deprecated
Conflicts: src/libcollectionstest/fmt.rs src/libcollectionstest/lib.rs src/libcollectionstest/str.rs src/libcore/error.rs src/libstd/fs.rs src/libstd/io/cursor.rs src/libstd/os.rs src/libstd/process.rs src/libtest/lib.rs src/test/run-pass-fulldeps/compiler-calls.rs
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/atomic.rs | 141 | ||||
| -rw-r--r-- | src/libcore/cell.rs | 34 | ||||
| -rw-r--r-- | src/libcore/finally.rs | 111 | ||||
| -rw-r--r-- | src/libcore/hash/sip.rs | 5 | ||||
| -rw-r--r-- | src/libcore/iter.rs | 166 | ||||
| -rw-r--r-- | src/libcore/lib.rs | 1 | ||||
| -rw-r--r-- | src/libcore/macros.rs | 2 | ||||
| -rw-r--r-- | src/libcore/marker.rs | 36 | ||||
| -rw-r--r-- | src/libcore/option.rs | 21 | ||||
| -rw-r--r-- | src/libcore/prelude.rs | 11 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 15 | ||||
| -rw-r--r-- | src/libcore/raw.rs | 13 | ||||
| -rw-r--r-- | src/libcore/slice.rs | 58 | ||||
| -rw-r--r-- | src/libcore/str/mod.rs | 98 | ||||
| -rw-r--r-- | src/libcore/str/pattern.rs | 168 |
15 files changed, 145 insertions, 735 deletions
diff --git a/src/libcore/atomic.rs b/src/libcore/atomic.rs index 91b4b46ac39..8c396a4e7fb 100644 --- a/src/libcore/atomic.rs +++ b/src/libcore/atomic.rs @@ -1062,144 +1062,3 @@ pub fn fence(order: Ordering) { } } } - -#[unstable(feature = "core")] -#[deprecated(since = "1.0.0", - reason = "renamed to AtomicIsize")] -#[allow(missing_docs)] -pub struct AtomicInt { - v: UnsafeCell<isize>, -} - -#[allow(deprecated)] -unsafe impl Sync for AtomicInt {} - -#[unstable(feature = "core")] -#[deprecated(since = "1.0.0", - reason = "renamed to AtomicUsize")] -#[allow(missing_docs)] -pub struct AtomicUint { - v: UnsafeCell<usize>, -} - -#[allow(deprecated)] -unsafe impl Sync for AtomicUint {} - -#[unstable(feature = "core")] -#[deprecated(since = "1.0.0", - reason = "use ATOMIC_ISIZE_INIT instead")] -#[allow(missing_docs, deprecated)] -pub const ATOMIC_INT_INIT: AtomicInt = - AtomicInt { v: UnsafeCell { value: 0 } }; -#[unstable(feature = "core")] -#[deprecated(since = "1.0.0", - reason = "use ATOMIC_USIZE_INIT instead")] -#[allow(missing_docs, deprecated)] -pub const ATOMIC_UINT_INIT: AtomicUint = - AtomicUint { v: UnsafeCell { value: 0, } }; - -#[allow(missing_docs, deprecated)] -impl AtomicInt { - #[inline] - pub fn new(v: isize) -> AtomicInt { - AtomicInt {v: UnsafeCell::new(v)} - } - - #[inline] - pub fn load(&self, order: Ordering) -> isize { - unsafe { atomic_load(self.v.get(), order) } - } - - #[inline] - pub fn store(&self, val: isize, order: Ordering) { - unsafe { atomic_store(self.v.get(), val, order); } - } - - #[inline] - pub fn swap(&self, val: isize, order: Ordering) -> isize { - unsafe { atomic_swap(self.v.get(), val, order) } - } - - #[inline] - pub fn compare_and_swap(&self, old: isize, new: isize, order: Ordering) -> isize { - unsafe { atomic_compare_and_swap(self.v.get(), old, new, order) } - } - - #[inline] - pub fn fetch_add(&self, val: isize, order: Ordering) -> isize { - unsafe { atomic_add(self.v.get(), val, order) } - } - - #[inline] - pub fn fetch_sub(&self, val: isize, order: Ordering) -> isize { - unsafe { atomic_sub(self.v.get(), val, order) } - } - - #[inline] - pub fn fetch_and(&self, val: isize, order: Ordering) -> isize { - unsafe { atomic_and(self.v.get(), val, order) } - } - - #[inline] - pub fn fetch_or(&self, val: isize, order: Ordering) -> isize { - unsafe { atomic_or(self.v.get(), val, order) } - } - - #[inline] - pub fn fetch_xor(&self, val: isize, order: Ordering) -> isize { - unsafe { atomic_xor(self.v.get(), val, order) } - } -} - -#[allow(missing_docs, deprecated)] -impl AtomicUint { - #[inline] - pub fn new(v: usize) -> AtomicUint { - AtomicUint { v: UnsafeCell::new(v) } - } - - #[inline] - pub fn load(&self, order: Ordering) -> usize { - unsafe { atomic_load(self.v.get(), order) } - } - - #[inline] - pub fn store(&self, val: usize, order: Ordering) { - unsafe { atomic_store(self.v.get(), val, order); } - } - - #[inline] - pub fn swap(&self, val: usize, order: Ordering) -> usize { - unsafe { atomic_swap(self.v.get(), val, order) } - } - - #[inline] - pub fn compare_and_swap(&self, old: usize, new: usize, order: Ordering) -> usize { - unsafe { atomic_compare_and_swap(self.v.get(), old, new, order) } - } - - #[inline] - pub fn fetch_add(&self, val: usize, order: Ordering) -> usize { - unsafe { atomic_add(self.v.get(), val, order) } - } - - #[inline] - pub fn fetch_sub(&self, val: usize, order: Ordering) -> usize { - unsafe { atomic_sub(self.v.get(), val, order) } - } - - #[inline] - pub fn fetch_and(&self, val: usize, order: Ordering) -> usize { - unsafe { atomic_and(self.v.get(), val, order) } - } - - #[inline] - pub fn fetch_or(&self, val: usize, order: Ordering) -> usize { - unsafe { atomic_or(self.v.get(), val, order) } - } - - #[inline] - pub fn fetch_xor(&self, val: usize, order: Ordering) -> usize { - unsafe { atomic_xor(self.v.get(), val, order) } - } -} diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 9e6dbce0325..906c87f3ffd 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -343,23 +343,6 @@ impl<T> RefCell<T> { } } - /// Attempts to immutably borrow the wrapped value. - /// - /// The borrow lasts until the returned `Ref` exits scope. Multiple - /// immutable borrows can be taken out at the same time. - /// - /// Returns `None` if the value is currently mutably borrowed. - #[unstable(feature = "core", reason = "may be renamed or removed")] - #[deprecated(since = "1.0.0", - reason = "dispatch on `cell.borrow_state()` instead")] - #[inline] - pub fn try_borrow<'a>(&'a self) -> Option<Ref<'a, T>> { - match BorrowRef::new(&self.borrow) { - Some(b) => Some(Ref { _value: unsafe { &*self.value.get() }, _borrow: b }), - None => None, - } - } - /// Immutably borrows the wrapped value. /// /// The borrow lasts until the returned `Ref` exits scope. Multiple @@ -412,23 +395,6 @@ impl<T> RefCell<T> { /// The borrow lasts until the returned `RefMut` exits scope. The value /// cannot be borrowed while this borrow is active. /// - /// Returns `None` if the value is currently borrowed. - #[unstable(feature = "core", reason = "may be renamed or removed")] - #[deprecated(since = "1.0.0", - reason = "dispatch on `cell.borrow_state()` instead")] - #[inline] - pub fn try_borrow_mut<'a>(&'a self) -> Option<RefMut<'a, T>> { - match BorrowRefMut::new(&self.borrow) { - Some(b) => Some(RefMut { _value: unsafe { &mut *self.value.get() }, _borrow: b }), - None => None, - } - } - - /// Mutably borrows the wrapped value. - /// - /// The borrow lasts until the returned `RefMut` exits scope. The value - /// cannot be borrowed while this borrow is active. - /// /// # Panics /// /// Panics if the value is currently borrowed. diff --git a/src/libcore/finally.rs b/src/libcore/finally.rs deleted file mode 100644 index 93a7d2bb17b..00000000000 --- a/src/libcore/finally.rs +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! The Finally trait provides a method, `finally` on -//! stack closures that emulates Java-style try/finally blocks. -//! -//! Using the `finally` method is sometimes convenient, but the type rules -//! prohibit any shared, mutable state between the "try" case and the -//! "finally" case. For advanced cases, the `try_finally` function can -//! also be used. See that function for more details. -//! -//! # Examples -//! -//! ``` -//! # #![feature(core)] -//! # #![feature(unboxed_closures)] -//! -//! use std::finally::Finally; -//! -//! (|| { -//! // ... -//! }).finally(|| { -//! // this code is always run -//! }) -//! ``` - -#![unstable(feature = "core")] -#![deprecated(since = "1.0.0", - reason = "It is unclear if this module is more robust than implementing \ - Drop on a custom type, and this module is being removed with no \ - replacement. Use a custom Drop implementation to regain existing \ - functionality.")] -#![allow(deprecated)] - -use ops::{Drop, FnMut, FnOnce}; - -/// A trait for executing a destructor unconditionally after a block of code, -/// regardless of whether the blocked fails. -pub trait Finally<T> { - /// Executes this object, unconditionally running `dtor` after this block of - /// code has run. - fn finally<F>(&mut self, dtor: F) -> T where F: FnMut(); -} - -impl<T, F> Finally<T> for F where F: FnMut() -> T { - fn finally<G>(&mut self, mut dtor: G) -> T where G: FnMut() { - try_finally(&mut (), self, |_, f| (*f)(), |_| dtor()) - } -} - -/// The most general form of the `finally` functions. The function -/// `try_fn` will be invoked first; whether or not it panics, the -/// function `finally_fn` will be invoked next. The two parameters -/// `mutate` and `drop` are used to thread state through the two -/// closures. `mutate` is used for any shared, mutable state that both -/// closures require access to; `drop` is used for any state that the -/// `try_fn` requires ownership of. -/// -/// **WARNING:** While shared, mutable state between the try and finally -/// function is often necessary, one must be very careful; the `try` -/// function could have panicked at any point, so the values of the shared -/// state may be inconsistent. -/// -/// # Examples -/// -/// ``` -/// # #![feature(core)] -/// use std::finally::try_finally; -/// -/// struct State<'a> { buffer: &'a mut [u8], len: usize } -/// # let mut buf = []; -/// let mut state = State { buffer: &mut buf, len: 0 }; -/// try_finally( -/// &mut state, (), -/// |state, ()| { -/// // use state.buffer, state.len -/// }, -/// |state| { -/// // use state.buffer, state.len to cleanup -/// }) -/// ``` -pub fn try_finally<T, U, R, F, G>(mutate: &mut T, drop: U, try_fn: F, finally_fn: G) -> R where - F: FnOnce(&mut T, U) -> R, - G: FnMut(&mut T), -{ - let f = Finallyalizer { - mutate: mutate, - dtor: finally_fn, - }; - try_fn(&mut *f.mutate, drop) -} - -struct Finallyalizer<'a, A:'a, F> where F: FnMut(&mut A) { - mutate: &'a mut A, - dtor: F, -} - -#[unsafe_destructor] -impl<'a, A, F> Drop for Finallyalizer<'a, A, F> where F: FnMut(&mut A) { - #[inline] - fn drop(&mut self) { - (self.dtor)(self.mutate); - } -} diff --git a/src/libcore/hash/sip.rs b/src/libcore/hash/sip.rs index e65fbac926b..6820a7025fc 100644 --- a/src/libcore/hash/sip.rs +++ b/src/libcore/hash/sip.rs @@ -114,11 +114,6 @@ impl SipHasher { state } - /// Returns the computed hash. - #[unstable(feature = "hash")] - #[deprecated(since = "1.0.0", reason = "renamed to finish")] - pub fn result(&self) -> u64 { self.finish() } - fn reset(&mut self) { self.length = 0; self.v0 = self.k0 ^ 0x736f6d6570736575; diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 7e6789c3da1..6440c654be7 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -66,8 +66,7 @@ use marker; use mem; use num::{Int, Zero, One, ToPrimitive}; use ops::{Add, Sub, FnMut, RangeFrom}; -use option::Option; -use option::Option::{Some, None}; +use option::Option::{self, Some, None}; use marker::Sized; use usize; @@ -433,7 +432,7 @@ pub trait Iterator { /// # #![feature(core)] /// let xs = [2, 3]; /// let ys = [0, 1, 0, 1, 2]; - /// let it = xs.iter().flat_map(|&x| std::iter::count(0, 1).take(x)); + /// let it = xs.iter().flat_map(|&x| (0..).take(x)); /// // Check that `it` has the same elements as `ys` /// for (i, x) in it.enumerate() { /// assert_eq!(x, ys[i]); @@ -1256,10 +1255,10 @@ pub trait MultiplicativeIterator<A> { /// /// ``` /// # #![feature(core)] - /// use std::iter::{count, MultiplicativeIterator}; + /// use std::iter::MultiplicativeIterator; /// /// fn factorial(n: usize) -> usize { - /// count(1, 1).take_while(|&i| i <= n).product() + /// (1..).take_while(|&i| i <= n).product() /// } /// assert!(factorial(0) == 1); /// assert!(factorial(1) == 1); @@ -2556,26 +2555,6 @@ impl<A: Step> ::ops::Range<A> { } } -/// An infinite iterator starting at `start` and advancing by `step` with each -/// iteration -#[unstable(feature = "core", - reason = "may be renamed or replaced by range notation adapters")] -#[deprecated(since = "1.0.0-beta", reason = "use range notation and step_by")] -pub type Counter<A> = StepBy<A, RangeFrom<A>>; - -/// Deprecated: use `(start..).step_by(step)` instead. -#[inline] -#[unstable(feature = "core", - reason = "may be renamed or replaced by range notation adapters")] -#[deprecated(since = "1.0.0-beta", reason = "use (start..).step_by(step) instead")] -#[allow(deprecated)] -pub fn count<A>(start: A, step: A) -> Counter<A> { - StepBy { - range: RangeFrom { start: start }, - step_by: step, - } -} - #[stable(feature = "rust1", since = "1.0.0")] impl<A> Iterator for StepBy<A, RangeFrom<A>> where A: Clone, @@ -2596,108 +2575,12 @@ impl<A> Iterator for StepBy<A, RangeFrom<A>> where } } -/// An iterator over the range [start, stop) -#[allow(deprecated)] -#[derive(Clone)] -#[unstable(feature = "core", - reason = "will be replaced by range notation")] -#[deprecated(since = "1.0.0-beta", reason = "use range notation")] -pub struct Range<A> { - state: A, - stop: A, - one: A, -} - -/// Deprecated: use `(start..stop)` instead. -#[inline] -#[unstable(feature = "core", reason = "will be replaced by range notation")] -#[deprecated(since = "1.0.0-beta", reason = "use (start..stop) instead")] -#[allow(deprecated)] -pub fn range<A: Int>(start: A, stop: A) -> Range<A> { - Range { - state: start, - stop: stop, - one: Int::one(), - } -} - -// FIXME: #10414: Unfortunate type bound -#[unstable(feature = "core", - reason = "will be replaced by range notation")] -#[deprecated(since = "1.0.0-beta", reason = "use range notation")] -#[allow(deprecated)] -impl<A: Int + ToPrimitive> Iterator for Range<A> { - type Item = A; - - #[inline] - fn next(&mut self) -> Option<A> { - if self.state < self.stop { - let result = self.state.clone(); - self.state = self.state + self.one; - Some(result) - } else { - None - } - } - - #[inline] - fn size_hint(&self) -> (usize, Option<usize>) { - // This first checks if the elements are representable as i64. If they aren't, try u64 (to - // handle cases like range(huge, huger)). We don't use usize/isize because the difference of - // the i64/u64 might lie within their range. - let bound = match self.state.to_i64() { - Some(a) => { - let sz = self.stop.to_i64().map(|b| b.checked_sub(a)); - match sz { - Some(Some(bound)) => bound.to_usize(), - _ => None, - } - }, - None => match self.state.to_u64() { - Some(a) => { - let sz = self.stop.to_u64().map(|b| b.checked_sub(a)); - match sz { - Some(Some(bound)) => bound.to_usize(), - _ => None - } - }, - None => None - } - }; - - match bound { - Some(b) => (b, Some(b)), - // Standard fallback for unbounded/unrepresentable bounds - None => (0, None) - } - } -} - -/// `Int` is required to ensure the range will be the same regardless of -/// the direction it is consumed. -#[unstable(feature = "core", - reason = "will be replaced by range notation")] -#[deprecated(since = "1.0.0-beta", reason = "use range notation")] -#[allow(deprecated)] -impl<A: Int + ToPrimitive> DoubleEndedIterator for Range<A> { - #[inline] - fn next_back(&mut self) -> Option<A> { - if self.stop > self.state { - self.stop = self.stop - self.one; - Some(self.stop.clone()) - } else { - None - } - } -} - /// An iterator over the range [start, stop] #[derive(Clone)] #[unstable(feature = "core", reason = "likely to be replaced by range notation and adapters")] -#[allow(deprecated)] pub struct RangeInclusive<A> { - range: Range<A>, + range: ops::Range<A>, done: bool, } @@ -2705,17 +2588,15 @@ pub struct RangeInclusive<A> { #[inline] #[unstable(feature = "core", reason = "likely to be replaced by range notation and adapters")] -#[allow(deprecated)] pub fn range_inclusive<A: Int>(start: A, stop: A) -> RangeInclusive<A> { RangeInclusive { - range: range(start, stop), + range: start..stop, done: false, } } #[unstable(feature = "core", reason = "likely to be replaced by range notation and adapters")] -#[allow(deprecated)] impl<A: Int + ToPrimitive> Iterator for RangeInclusive<A> { type Item = A; @@ -2724,9 +2605,9 @@ impl<A: Int + ToPrimitive> Iterator for RangeInclusive<A> { match self.range.next() { Some(x) => Some(x), None => { - if !self.done && self.range.state == self.range.stop { + if !self.done && self.range.start == self.range.end { self.done = true; - Some(self.range.stop.clone()) + Some(self.range.end.clone()) } else { None } @@ -2752,43 +2633,22 @@ impl<A: Int + ToPrimitive> Iterator for RangeInclusive<A> { #[unstable(feature = "core", reason = "likely to be replaced by range notation and adapters")] -#[allow(deprecated)] impl<A: Int + ToPrimitive> DoubleEndedIterator for RangeInclusive<A> { #[inline] fn next_back(&mut self) -> Option<A> { - if self.range.stop > self.range.state { - let result = self.range.stop.clone(); - self.range.stop = self.range.stop - self.range.one; + if self.range.end > self.range.start { + let result = self.range.end.clone(); + self.range.end = self.range.end - A::one(); Some(result) - } else if !self.done && self.range.state == self.range.stop { + } else if !self.done && self.range.start == self.range.end { self.done = true; - Some(self.range.stop.clone()) + Some(self.range.end.clone()) } else { None } } } -/// An iterator over the range [start, stop) by `step`. It handles overflow by stopping. -#[unstable(feature = "core", - reason = "likely to be replaced by range notation and adapters")] -#[deprecated(since = "1.0.0-beta", reason = "use range notation and step_by")] -pub type RangeStep<A> = StepBy<A, ::ops::Range<A>>; - -/// Deprecated: use `(start..stop).step_by(step)` instead. -#[inline] -#[unstable(feature = "core", - reason = "likely to be replaced by range notation and adapters")] -#[deprecated(since = "1.0.0-beta", - reason = "use `(start..stop).step_by(step)` instead")] -#[allow(deprecated)] -pub fn range_step<A: Int>(start: A, stop: A, step: A) -> RangeStep<A> { - StepBy { - step_by: step, - range: ::ops::Range { start: start, end: stop }, - } -} - #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated)] impl<A: Step + Zero + Clone> Iterator for StepBy<A, ::ops::Range<A>> { diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index cf5cb0c2f5e..5e8b7fba1f1 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -136,7 +136,6 @@ pub mod atomic; pub mod cell; pub mod char; pub mod panicking; -pub mod finally; pub mod iter; pub mod option; pub mod raw; diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 19626aa5056..fb64cbfbc79 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -233,7 +233,7 @@ macro_rules! writeln { /// ``` /// # #![feature(core)] /// fn divide_by_three(x: u32) -> u32 { // one of the poorest implementations of x/3 -/// for i in std::iter::count(0, 1) { +/// for i in 0.. { /// if 3*i < i { panic!("u32 overflow"); } /// if x < 3*i { return i-1; } /// } diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index 277b98f0523..f755c912fcd 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -415,42 +415,6 @@ mod impls { unsafe impl<'a, T: Send + ?Sized> Send for &'a mut T {} } -/// Old-style marker trait. Deprecated. -#[unstable(feature = "core", reason = "deprecated")] -#[deprecated(since = "1.0.0", reason = "Replace with `PhantomData<&'a ()>`")] -#[lang="contravariant_lifetime"] -pub struct ContravariantLifetime<'a>; - -/// Old-style marker trait. Deprecated. -#[unstable(feature = "core", reason = "deprecated")] -#[deprecated(since = "1.0.0", reason = "Replace with `PhantomData<fn(&'a ())>`")] -#[lang="covariant_lifetime"] -pub struct CovariantLifetime<'a>; - -/// Old-style marker trait. Deprecated. -#[unstable(feature = "core", reason = "deprecated")] -#[deprecated(since = "1.0.0", reason = "Replace with `PhantomData<Cell<&'a ()>>`")] -#[lang="invariant_lifetime"] -pub struct InvariantLifetime<'a>; - -/// Old-style marker trait. Deprecated. -#[unstable(feature = "core", reason = "deprecated")] -#[deprecated(since = "1.0.0", reason = "Replace with `PhantomData<fn(T)>`")] -#[lang="contravariant_type"] -pub struct ContravariantType<T>; - -/// Old-style marker trait. Deprecated. -#[unstable(feature = "core", reason = "deprecated")] -#[deprecated(since = "1.0.0", reason = "Replace with `PhantomData<T>`")] -#[lang="covariant_type"] -pub struct CovariantType<T>; - -/// Old-style marker trait. Deprecated. -#[unstable(feature = "core", reason = "deprecated")] -#[deprecated(since = "1.0.0", reason = "Replace with `PhantomData<Cell<T>>`")] -#[lang="invariant_type"] -pub struct InvariantType<T>; - /// A marker trait indicates a type that can be reflected over. This /// trait is implemented for all types. Its purpose is to ensure that /// when you write a generic function that will employ reflection, diff --git a/src/libcore/option.rs b/src/libcore/option.rs index c5102ede29f..6db7c9bd99d 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -154,8 +154,6 @@ use mem; use ops::FnOnce; use result::Result::{Ok, Err}; use result::Result; -#[allow(deprecated)] -use slice::AsSlice; use slice; // Note that this is not a lang item per se, but it has a hidden dependency on @@ -765,25 +763,6 @@ impl<T: Default> Option<T> { // Trait implementations ///////////////////////////////////////////////////////////////////////////// -#[unstable(feature = "core", - reason = "waiting on the stability of the trait itself")] -#[deprecated(since = "1.0.0", - reason = "use the inherent method instead")] -#[allow(deprecated)] -impl<T> AsSlice<T> for Option<T> { - /// Convert from `Option<T>` to `&[T]` (without copying) - #[inline] - fn as_slice<'a>(&'a self) -> &'a [T] { - match *self { - Some(ref x) => slice::ref_slice(x), - None => { - let result: &[_] = &[]; - result - } - } - } -} - #[stable(feature = "rust1", since = "1.0.0")] impl<T> Default for Option<T> { #[inline] diff --git a/src/libcore/prelude.rs b/src/libcore/prelude.rs index 448b90c0dbd..e60bc494081 100644 --- a/src/libcore/prelude.rs +++ b/src/libcore/prelude.rs @@ -37,10 +37,11 @@ pub use char::CharExt; pub use clone::Clone; pub use cmp::{PartialEq, PartialOrd, Eq, Ord}; pub use convert::{AsRef, AsMut, Into, From}; -pub use iter::Extend; -pub use iter::{Iterator, DoubleEndedIterator}; -pub use iter::{ExactSizeIterator}; +pub use iter::{Iterator, DoubleEndedIterator, Extend, ExactSizeIterator}; pub use option::Option::{self, Some, None}; pub use result::Result::{self, Ok, Err}; -pub use slice::{AsSlice, SliceExt}; -pub use str::{Str, StrExt}; +pub use slice::SliceExt; +pub use str::StrExt; + +#[allow(deprecated)] pub use slice::AsSlice; +#[allow(deprecated)] pub use str::Str; diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 41a70ef708f..ff51e25fcbf 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -157,21 +157,6 @@ pub fn null<T>() -> *const T { 0 as *const T } #[stable(feature = "rust1", since = "1.0.0")] pub fn null_mut<T>() -> *mut T { 0 as *mut T } -/// Zeroes out `count * size_of::<T>` bytes of memory at `dst`. `count` may be -/// `0`. -/// -/// # Safety -/// -/// Beyond accepting a raw pointer, this is unsafe because it will not drop the -/// contents of `dst`, and may be used to create invalid instances of `T`. -#[inline] -#[unstable(feature = "core", - reason = "may play a larger role in std::ptr future extensions")] -#[deprecated(since = "1.0.0", reason = "use `write_bytes` instead")] -pub unsafe fn zero_memory<T>(dst: *mut T, count: usize) { - write_bytes(dst, 0, count); -} - /// Swaps the values at two mutable locations of the same type, without /// deinitialising either. They may overlap, unlike `mem::swap` which is /// otherwise equivalent. diff --git a/src/libcore/raw.rs b/src/libcore/raw.rs index 8502a9c53c4..47d1f3a1a3c 100644 --- a/src/libcore/raw.rs +++ b/src/libcore/raw.rs @@ -64,19 +64,6 @@ pub struct Slice<T> { impl<T> Copy for Slice<T> {} -/// The representation of an old closure. -#[repr(C)] -#[derive(Copy)] -#[unstable(feature = "core")] -#[deprecated(reason = "unboxed new closures do not have a universal representation; \ - `&Fn` (etc) trait objects should use `TraitObject` instead", - since= "1.0.0")] -#[allow(deprecated) /* for deriving Copy impl */] -pub struct Closure { - pub code: *mut (), - pub env: *mut (), -} - /// The representation of a trait object like `&SomeTrait`. /// /// This struct has the same layout as types like `&SomeTrait` and diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 223a0bdae36..d8856130fab 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -88,10 +88,6 @@ pub trait SliceExt { fn len(&self) -> usize; fn is_empty(&self) -> bool { self.len() == 0 } fn get_mut<'a>(&'a mut self, index: usize) -> Option<&'a mut Self::Item>; - #[unstable(feature = "core", - reason = "will be replaced by slice syntax")] - #[deprecated(since = "1.0.0", reason = "use &mut s[..] instead")] - fn as_mut_slice<'a>(&'a mut self) -> &'a mut [Self::Item]; fn iter_mut<'a>(&'a mut self) -> IterMut<'a, Self::Item>; fn first_mut<'a>(&'a mut self) -> Option<&'a mut Self::Item>; fn tail_mut<'a>(&'a mut self) -> &'a mut [Self::Item]; @@ -264,12 +260,6 @@ impl<T> SliceExt for [T] { } #[inline] - #[unstable(feature = "core", - reason = "will be replaced by slice syntax")] - #[deprecated(since = "1.0.0", reason = "use &mut s[..] instead")] - fn as_mut_slice(&mut self) -> &mut [T] { self } - - #[inline] fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]) { unsafe { let self2: &mut [T] = mem::transmute_copy(&self); @@ -1502,54 +1492,6 @@ pub unsafe fn from_raw_parts_mut<'a, T>(p: *mut T, len: usize) -> &'a mut [T] { transmute(RawSlice { data: p, len: len }) } -/// Forms a slice from a pointer and a length. -/// -/// The pointer given is actually a reference to the base of the slice. This -/// reference is used to give a concrete lifetime to tie the returned slice to. -/// Typically this should indicate that the slice is valid for as long as the -/// pointer itself is valid. -/// -/// The `len` argument is the number of **elements**, not the number of bytes. -/// -/// This function is unsafe as there is no guarantee that the given pointer is -/// valid for `len` elements, nor whether the lifetime provided is a suitable -/// lifetime for the returned slice. -/// -/// # Examples -/// -/// ``` -/// #![feature(core)] -/// use std::slice; -/// -/// // manifest a slice out of thin air! -/// let ptr = 0x1234 as *const usize; -/// let amt = 10; -/// unsafe { -/// let slice = slice::from_raw_buf(&ptr, amt); -/// } -/// ``` -#[inline] -#[unstable(feature = "core")] -#[deprecated(since = "1.0.0", - reason = "use from_raw_parts")] -pub unsafe fn from_raw_buf<'a, T>(p: &'a *const T, len: usize) -> &'a [T] { - transmute(RawSlice { data: *p, len: len }) -} - -/// Performs the same functionality as `from_raw_buf`, except that a mutable -/// slice is returned. -/// -/// This function is unsafe for the same reasons as `from_raw_buf`, as well as -/// not being able to provide a non-aliasing guarantee of the returned mutable -/// slice. -#[inline] -#[unstable(feature = "core")] -#[deprecated(since = "1.0.0", - reason = "use from_raw_parts_mut")] -pub unsafe fn from_raw_mut_buf<'a, T>(p: &'a *mut T, len: usize) -> &'a mut [T] { - transmute(RawSlice { data: *p, len: len }) -} - // // Submodules // diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index f9e2b47d9b6..934c4515614 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -28,8 +28,6 @@ use iter::ExactSizeIterator; use iter::{Map, Iterator, DoubleEndedIterator}; use marker::Sized; use mem; -#[allow(deprecated)] -use num::Int; use ops::{Fn, FnMut, FnOnce}; use option::Option::{self, None, Some}; use raw::{Repr, Slice}; @@ -243,78 +241,6 @@ pub unsafe fn from_utf8_unchecked<'a>(v: &'a [u8]) -> &'a str { mem::transmute(v) } -/// Constructs a static string slice from a given raw pointer. -/// -/// This function will read memory starting at `s` until it finds a 0, and then -/// transmute the memory up to that point as a string slice, returning the -/// corresponding `&'static str` value. -/// -/// This function is unsafe because the caller must ensure the C string itself -/// has the static lifetime and that the memory `s` is valid up to and including -/// the first null byte. -/// -/// # Panics -/// -/// This function will panic if the string pointed to by `s` is not valid UTF-8. -#[unstable(feature = "core")] -#[deprecated(since = "1.0.0", - reason = "use std::ffi::c_str_to_bytes + str::from_utf8")] -pub unsafe fn from_c_str(s: *const i8) -> &'static str { - let s = s as *const u8; - let mut len: usize = 0; - while *s.offset(len as isize) != 0 { - len += 1; - } - let v: &'static [u8] = ::mem::transmute(Slice { data: s, len: len }); - from_utf8(v).ok().expect("from_c_str passed invalid utf-8 data") -} - -/// Something that can be used to compare against a character -#[unstable(feature = "core")] -#[deprecated(since = "1.0.0", - reason = "use `Pattern` instead")] -// NB: Rather than removing it, make it private and move it into self::pattern -pub trait CharEq { - /// Determine if the splitter should split at the given character - fn matches(&mut self, char) -> bool; - /// Indicate if this is only concerned about ASCII characters, - /// which can allow for a faster implementation. - fn only_ascii(&self) -> bool; -} - -#[allow(deprecated) /* for CharEq */ ] -impl CharEq for char { - #[inline] - fn matches(&mut self, c: char) -> bool { *self == c } - - #[inline] - fn only_ascii(&self) -> bool { (*self as u32) < 128 } -} - -#[allow(deprecated) /* for CharEq */ ] -impl<F> CharEq for F where F: FnMut(char) -> bool { - #[inline] - fn matches(&mut self, c: char) -> bool { (*self)(c) } - - #[inline] - fn only_ascii(&self) -> bool { false } -} - -#[allow(deprecated) /* for CharEq */ ] -impl<'a> CharEq for &'a [char] { - #[inline] - #[allow(deprecated) /* for CharEq */ ] - fn matches(&mut self, c: char) -> bool { - self.iter().any(|&m| { let mut m = m; m.matches(c) }) - } - - #[inline] - #[allow(deprecated) /* for CharEq */ ] - fn only_ascii(&self) -> bool { - self.iter().all(|m| m.only_ascii()) - } -} - #[stable(feature = "rust1", since = "1.0.0")] impl Error for Utf8Error { fn description(&self) -> &str { @@ -1047,22 +973,6 @@ impl<'a, P: Pattern<'a>> Iterator for MatchIndices<'a, P> { } } -/// An iterator over the substrings of a string separated by a given -/// search string -#[unstable(feature = "core")] -#[deprecated(since = "1.0.0", reason = "use `Split` with a `&str`")] -pub struct SplitStr<'a, P: Pattern<'a>>(Split<'a, P>); -#[allow(deprecated)] -impl<'a, P: Pattern<'a>> Iterator for SplitStr<'a, P> { - type Item = &'a str; - - #[inline] - #[allow(deprecated)] - fn next(&mut self) -> Option<&'a str> { - Iterator::next(&mut self.0) - } -} - impl<'a, 'b> OldMatchIndices<'a, 'b> { #[inline] #[allow(dead_code)] @@ -1444,8 +1354,6 @@ pub trait StrExt { fn rsplitn<'a, P: Pattern<'a>>(&'a self, count: usize, pat: P) -> RSplitN<'a, P> where P::Searcher: ReverseSearcher<'a>; fn match_indices<'a, P: Pattern<'a>>(&'a self, pat: P) -> MatchIndices<'a, P>; - #[allow(deprecated) /* for SplitStr */] - fn split_str<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitStr<'a, P>; fn lines<'a>(&'a self) -> Lines<'a>; fn lines_any<'a>(&'a self) -> LinesAny<'a>; fn char_len(&self) -> usize; @@ -1566,12 +1474,6 @@ impl StrExt for str { } #[inline] - #[allow(deprecated) /* for SplitStr */ ] - fn split_str<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitStr<'a, P> { - SplitStr(self.split(pat)) - } - - #[inline] fn lines(&self) -> Lines { Lines { inner: self.split_terminator('\n').0 } } diff --git a/src/libcore/str/pattern.rs b/src/libcore/str/pattern.rs index 98b6533980d..922ab2c14a6 100644 --- a/src/libcore/str/pattern.rs +++ b/src/libcore/str/pattern.rs @@ -8,10 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(deprecated) /* for CharEq */ ] - use prelude::*; -use super::CharEq; // Pattern @@ -228,6 +225,40 @@ pub trait DoubleEndedSearcher<'a>: ReverseSearcher<'a> {} // Impl for a CharEq wrapper +#[doc(hidden)] +trait CharEq { + fn matches(&mut self, char) -> bool; + fn only_ascii(&self) -> bool; +} + +impl CharEq for char { + #[inline] + fn matches(&mut self, c: char) -> bool { *self == c } + + #[inline] + fn only_ascii(&self) -> bool { (*self as u32) < 128 } +} + +impl<F> CharEq for F where F: FnMut(char) -> bool { + #[inline] + fn matches(&mut self, c: char) -> bool { (*self)(c) } + + #[inline] + fn only_ascii(&self) -> bool { false } +} + +impl<'a> CharEq for &'a [char] { + #[inline] + fn matches(&mut self, c: char) -> bool { + self.iter().any(|&m| { let mut m = m; m.matches(c) }) + } + + #[inline] + fn only_ascii(&self) -> bool { + self.iter().all(|m| m.only_ascii()) + } +} + struct CharEqPattern<C: CharEq>(C); struct CharEqSearcher<'a, C: CharEq> { @@ -425,65 +456,116 @@ fn str_search_step<F, G>(mut m: &mut StrSearcher, } } -macro_rules! associated_items { - ($t:ty, $s:ident, $e:expr) => { - // FIXME: #22463 - //type Searcher = $t; - - fn into_searcher(self, haystack: &'a str) -> $t { - let $s = self; - $e.into_searcher(haystack) +macro_rules! char_eq_pattern_impl { + ($wrapper:ty, $wrapper_ident:ident) => { + fn into_searcher(self, haystack: &'a str) -> $wrapper { + $wrapper_ident(CharEqPattern(self).into_searcher(haystack)) } - #[inline] fn is_contained_in(self, haystack: &'a str) -> bool { - let $s = self; - $e.is_contained_in(haystack) + CharEqPattern(self).is_contained_in(haystack) } - #[inline] fn is_prefix_of(self, haystack: &'a str) -> bool { - let $s = self; - $e.is_prefix_of(haystack) + CharEqPattern(self).is_prefix_of(haystack) } - - // FIXME: #21750 - /*#[inline] + #[inline] fn is_suffix_of(self, haystack: &'a str) -> bool - where $t: ReverseSearcher<'a> + where $wrapper: ReverseSearcher<'a> { - let $s = self; - $e.is_suffix_of(haystack) - }*/ + CharEqPattern(self).is_suffix_of(haystack) + } } } -// CharEq delegation impls +// Pattern for char -/// Searches for chars that are equal to a given char impl<'a> Pattern<'a> for char { - type Searcher = <CharEqPattern<Self> as Pattern<'a>>::Searcher; - associated_items!(<CharEqPattern<Self> as Pattern<'a>>::Searcher, - s, CharEqPattern(s)); + type Searcher = CharSearcher<'a>; + char_eq_pattern_impl!(CharSearcher<'a>, CharSearcher); +} + +pub struct CharSearcher<'a>(CharEqSearcher<'a, char>); + +unsafe impl<'a> Searcher<'a> for CharSearcher<'a> { + #[inline] + fn haystack(&self) -> &'a str { self.0.haystack() } + #[inline] + fn next(&mut self) -> SearchStep { self.0.next() } +} +unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> { + #[inline] + fn next_back(&mut self) -> SearchStep { self.0.next_back() } } +impl<'a> DoubleEndedSearcher<'a> for CharSearcher<'a> {} + +// Pattern for &[char] -/// Searches for chars that are equal to any of the chars in the array impl<'a, 'b> Pattern<'a> for &'b [char] { - type Searcher = <CharEqPattern<Self> as Pattern<'a>>::Searcher; - associated_items!(<CharEqPattern<Self> as Pattern<'a>>::Searcher, - s, CharEqPattern(s)); + type Searcher = CharSliceSearcher<'a, 'b>; + char_eq_pattern_impl!(CharSliceSearcher<'a, 'b>, CharSliceSearcher); } -/// A convenience impl that delegates to the impl for `&str` -impl<'a, 'b> Pattern<'a> for &'b &'b str { - type Searcher = <&'b str as Pattern<'a>>::Searcher; - associated_items!(<&'b str as Pattern<'a>>::Searcher, - s, (*s)); +pub struct CharSliceSearcher<'a, 'b>(CharEqSearcher<'a, &'b [char]>); + +unsafe impl<'a, 'b> Searcher<'a> for CharSliceSearcher<'a, 'b> { + #[inline] + fn haystack(&self) -> &'a str { self.0.haystack() } + #[inline] + fn next(&mut self) -> SearchStep { self.0.next() } +} +unsafe impl<'a, 'b> ReverseSearcher<'a> for CharSliceSearcher<'a, 'b> { + #[inline] + fn next_back(&mut self) -> SearchStep { self.0.next_back() } +} +impl<'a, 'b> DoubleEndedSearcher<'a> for CharSliceSearcher<'a, 'b> {} + +// Pattern for predicates + +impl<'a, F: FnMut(char) -> bool> Pattern<'a> for F { + type Searcher = CharPredSearcher<'a, F>; + char_eq_pattern_impl!(CharPredSearcher<'a, F>, CharPredSearcher); +} + +pub struct CharPredSearcher<'a, F: FnMut(char) -> bool>(CharEqSearcher<'a, F>); + +unsafe impl<'a, F> Searcher<'a> for CharPredSearcher<'a, F> + where F: FnMut(char) -> bool +{ + #[inline] + fn haystack(&self) -> &'a str { self.0.haystack() } + #[inline] + fn next(&mut self) -> SearchStep { self.0.next() } +} +unsafe impl<'a, F> ReverseSearcher<'a> for CharPredSearcher<'a, F> + where F: FnMut(char) -> bool +{ + #[inline] + fn next_back(&mut self) -> SearchStep { self.0.next_back() } } +impl<'a, F> DoubleEndedSearcher<'a> for CharPredSearcher<'a, F> + where F: FnMut(char) -> bool +{} -/// Searches for chars that match the given predicate -impl<'a, F> Pattern<'a> for F where F: FnMut(char) -> bool { - type Searcher = <CharEqPattern<Self> as Pattern<'a>>::Searcher; - associated_items!(<CharEqPattern<Self> as Pattern<'a>>::Searcher, - s, CharEqPattern(s)); +// Pattern for &&str + +impl<'a, 'b> Pattern<'a> for &'b &'b str { + type Searcher = <&'b str as Pattern<'a>>::Searcher; + #[inline] + fn into_searcher(self, haystack: &'a str) + -> <&'b str as Pattern<'a>>::Searcher { + (*self).into_searcher(haystack) + } + #[inline] + fn is_contained_in(self, haystack: &'a str) -> bool { + (*self).is_contained_in(haystack) + } + #[inline] + fn is_prefix_of(self, haystack: &'a str) -> bool { + (*self).is_prefix_of(haystack) + } + #[inline] + fn is_suffix_of(self, haystack: &'a str) -> bool { + (*self).is_suffix_of(haystack) + } } |
