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
This commit is contained in:
commit
554946c81e
|
@ -166,7 +166,7 @@ $(foreach file,$(wildcard $(S)src/doc/trpl/*.md), \
|
|||
######################################################################
|
||||
|
||||
# The main testing target. Tests lots of stuff.
|
||||
check: cleantmptestlogs cleantestlibs all check-stage2 tidy
|
||||
check: check-sanitycheck cleantmptestlogs cleantestlibs all check-stage2 tidy
|
||||
$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
|
||||
|
||||
# As above but don't bother running tidy.
|
||||
|
@ -193,6 +193,11 @@ check-docs: cleantestlibs cleantmptestlogs check-stage2-docs
|
|||
# Not run as part of the normal test suite, but tested by bors on checkin.
|
||||
check-secondary: check-build-compiletest check-build-lexer-verifier check-lexer check-pretty
|
||||
|
||||
.PHONY: check-sanitycheck
|
||||
|
||||
check-sanitycheck:
|
||||
$(Q)$(CFG_PYTHON) $(S)src/etc/check-sanitycheck.py
|
||||
|
||||
# check + check-secondary.
|
||||
#
|
||||
# Issue #17883: build check-secondary first so hidden dependencies in
|
||||
|
|
|
@ -977,7 +977,6 @@ An example of `use` declarations:
|
|||
|
||||
```
|
||||
# #![feature(core)]
|
||||
use std::iter::range_step;
|
||||
use std::option::Option::{Some, None};
|
||||
use std::collections::hash_map::{self, HashMap};
|
||||
|
||||
|
@ -985,9 +984,6 @@ fn foo<T>(_: T){}
|
|||
fn bar(map1: HashMap<String, usize>, map2: hash_map::HashMap<String, usize>){}
|
||||
|
||||
fn main() {
|
||||
// Equivalent to 'std::iter::range_step(0, 10, 2);'
|
||||
range_step(0, 10, 2);
|
||||
|
||||
// Equivalent to 'foo(vec![std::option::Option::Some(1.0f64),
|
||||
// std::option::Option::None]);'
|
||||
foo(vec![Some(1.0f64), None]);
|
||||
|
|
|
@ -243,11 +243,12 @@ for num in nums.iter() {
|
|||
```
|
||||
|
||||
These two basic iterators should serve you well. There are some more
|
||||
advanced iterators, including ones that are infinite. Like `count`:
|
||||
advanced iterators, including ones that are infinite. Like using range syntax
|
||||
and `step_by`:
|
||||
|
||||
```rust
|
||||
# #![feature(core)]
|
||||
std::iter::count(1, 5);
|
||||
# #![feature(step_by)]
|
||||
(1..).step_by(5);
|
||||
```
|
||||
|
||||
This iterator counts up from one, adding five each time. It will give
|
||||
|
@ -292,11 +293,11 @@ just use `for` instead.
|
|||
There are tons of interesting iterator adapters. `take(n)` will return an
|
||||
iterator over the next `n` elements of the original iterator, note that this
|
||||
has no side effect on the original iterator. Let's try it out with our infinite
|
||||
iterator from before, `count()`:
|
||||
iterator from before:
|
||||
|
||||
```rust
|
||||
# #![feature(core)]
|
||||
for i in std::iter::count(1, 5).take(5) {
|
||||
# #![feature(step_by)]
|
||||
for i in (1..).step_by(5).take(5) {
|
||||
println!("{}", i);
|
||||
}
|
||||
```
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2012-2014 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.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import functools
|
||||
import resource
|
||||
|
||||
STATUS = 0
|
||||
|
||||
|
||||
def error_unless_permitted(env_var, message):
|
||||
global STATUS
|
||||
if not os.getenv(env_var):
|
||||
sys.stderr.write(message)
|
||||
STATUS = 1
|
||||
|
||||
|
||||
def only_on(platforms):
|
||||
def decorator(func):
|
||||
@functools.wraps(func)
|
||||
def inner():
|
||||
if any(map(lambda x: sys.platform.startswith(x), platforms)):
|
||||
func()
|
||||
return inner
|
||||
return decorator
|
||||
|
||||
|
||||
@only_on(('linux', 'darwin', 'freebsd', 'openbsd'))
|
||||
def check_rlimit_core():
|
||||
soft, hard = resource.getrlimit(resource.RLIMIT_CORE)
|
||||
if soft > 0:
|
||||
error_unless_permitted('ALLOW_NONZERO_RLIMIT_CORE', """\
|
||||
RLIMIT_CORE is set to a nonzero value (%d). During debuginfo, the test suite
|
||||
will segfault many rustc's, creating many potentially large core files.
|
||||
set ALLOW_NONZERO_RLIMIT_CORE to ignore this warning
|
||||
""" % (soft))
|
||||
|
||||
|
||||
def main():
|
||||
check_rlimit_core()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
sys.exit(STATUS)
|
|
@ -38,7 +38,7 @@
|
|||
//! [sieve]: http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
|
||||
//!
|
||||
//! ```
|
||||
//! # #![feature(collections, core)]
|
||||
//! # #![feature(collections, core, step_by)]
|
||||
//! use std::collections::{BitSet, BitVec};
|
||||
//! use std::num::Float;
|
||||
//! use std::iter;
|
||||
|
@ -60,7 +60,7 @@
|
|||
//! if bv[i] {
|
||||
//! // Mark all multiples of i as non-prime (any multiples below i * i
|
||||
//! // will have been marked as non-prime previously)
|
||||
//! for j in iter::range_step(i * i, max_prime, i) { bv.set(j, false) }
|
||||
//! for j in (i * i..max_prime).step_by(i) { bv.set(j, false) }
|
||||
//! }
|
||||
//! }
|
||||
//! BitSet::from_bit_vec(bv)
|
||||
|
@ -1264,14 +1264,6 @@ impl BitSet {
|
|||
BitSet { bit_vec: bit_vec }
|
||||
}
|
||||
|
||||
/// Deprecated: use `from_bit_vec`.
|
||||
#[inline]
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to from_bit_vec")]
|
||||
#[unstable(feature = "collections")]
|
||||
pub fn from_bitv(bit_vec: BitVec) -> BitSet {
|
||||
BitSet { bit_vec: bit_vec }
|
||||
}
|
||||
|
||||
/// Returns the capacity in bits for this bit vector. Inserting any
|
||||
/// element less than this amount will not trigger a resizing.
|
||||
///
|
||||
|
|
|
@ -248,26 +248,6 @@ impl<'a, B: ?Sized> Cow<'a, B> where B: ToOwned {
|
|||
Owned(owned) => owned
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if this `Cow` wraps a borrowed value
|
||||
#[deprecated(since = "1.0.0", reason = "match on the enum instead")]
|
||||
#[unstable(feature = "std_misc")]
|
||||
pub fn is_borrowed(&self) -> bool {
|
||||
match *self {
|
||||
Borrowed(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if this `Cow` wraps an owned value
|
||||
#[deprecated(since = "1.0.0", reason = "match on the enum instead")]
|
||||
#[unstable(feature = "std_misc")]
|
||||
pub fn is_owned(&self) -> bool {
|
||||
match *self {
|
||||
Owned(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
|
|
@ -67,22 +67,6 @@ pub use string::String;
|
|||
pub use vec::Vec;
|
||||
pub use vec_map::VecMap;
|
||||
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to vec_deque")]
|
||||
#[unstable(feature = "collections")]
|
||||
pub use vec_deque as ring_buf;
|
||||
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to linked_list")]
|
||||
#[unstable(feature = "collections")]
|
||||
pub use linked_list as dlist;
|
||||
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to bit_vec")]
|
||||
#[unstable(feature = "collections")]
|
||||
pub use bit_vec as bitv;
|
||||
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to bit_set")]
|
||||
#[unstable(feature = "collections")]
|
||||
pub use bit_set as bitv_set;
|
||||
|
||||
// Needed for the vec! macro
|
||||
pub use alloc::boxed;
|
||||
|
||||
|
@ -107,10 +91,6 @@ pub mod vec_map;
|
|||
reason = "RFC 509")]
|
||||
pub mod bit_vec {
|
||||
pub use bit::{BitVec, Iter};
|
||||
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to BitVec")]
|
||||
#[unstable(feature = "collections")]
|
||||
pub use bit::BitVec as Bitv;
|
||||
}
|
||||
|
||||
#[unstable(feature = "collections",
|
||||
|
@ -118,10 +98,6 @@ pub mod bit_vec {
|
|||
pub mod bit_set {
|
||||
pub use bit::{BitSet, Union, Intersection, Difference, SymmetricDifference};
|
||||
pub use bit::SetIter as Iter;
|
||||
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to BitSet")]
|
||||
#[unstable(feature = "collections")]
|
||||
pub use bit::BitSet as BitvSet;
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
|
|
@ -32,10 +32,6 @@ use core::iter::{self, FromIterator, IntoIterator};
|
|||
use core::mem;
|
||||
use core::ptr;
|
||||
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to LinkedList")]
|
||||
#[unstable(feature = "collections")]
|
||||
pub use LinkedList as DList;
|
||||
|
||||
/// A doubly-linked list.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct LinkedList<T> {
|
||||
|
@ -844,7 +840,7 @@ impl<A> ExactSizeIterator for IntoIter<A> {}
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<A> FromIterator<A> for LinkedList<A> {
|
||||
fn from_iter<T: IntoIterator<Item=A>>(iter: T) -> LinkedList<A> {
|
||||
let mut ret = DList::new();
|
||||
let mut ret = LinkedList::new();
|
||||
ret.extend(iter);
|
||||
ret
|
||||
}
|
||||
|
|
|
@ -105,7 +105,6 @@ pub use core::slice::{IntSliceExt, SplitMut, ChunksMut, Split};
|
|||
pub use core::slice::{SplitN, RSplitN, SplitNMut, RSplitNMut};
|
||||
pub use core::slice::{bytes, mut_ref_slice, ref_slice};
|
||||
pub use core::slice::{from_raw_parts, from_raw_parts_mut};
|
||||
pub use core::slice::{from_raw_buf, from_raw_mut_buf};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Basic slice extension methods
|
||||
|
@ -279,33 +278,6 @@ impl<T> [T] {
|
|||
cmp::min(self.len(), end-start)
|
||||
}
|
||||
|
||||
/// Deprecated: use `&s[start .. end]` notation instead.
|
||||
#[unstable(feature = "collections",
|
||||
reason = "will be replaced by slice syntax")]
|
||||
#[deprecated(since = "1.0.0", reason = "use &s[start .. end] instead")]
|
||||
#[inline]
|
||||
pub fn slice(&self, start: usize, end: usize) -> &[T] {
|
||||
&self[start .. end]
|
||||
}
|
||||
|
||||
/// Deprecated: use `&s[start..]` notation instead.
|
||||
#[unstable(feature = "collections",
|
||||
reason = "will be replaced by slice syntax")]
|
||||
#[deprecated(since = "1.0.0", reason = "use &s[start..] instead")]
|
||||
#[inline]
|
||||
pub fn slice_from(&self, start: usize) -> &[T] {
|
||||
&self[start ..]
|
||||
}
|
||||
|
||||
/// Deprecated: use `&s[..end]` notation instead.
|
||||
#[unstable(feature = "collections",
|
||||
reason = "will be replaced by slice syntax")]
|
||||
#[deprecated(since = "1.0.0", reason = "use &s[..end] instead")]
|
||||
#[inline]
|
||||
pub fn slice_to(&self, end: usize) -> &[T] {
|
||||
&self[.. end]
|
||||
}
|
||||
|
||||
/// Divides one slice into two at an index.
|
||||
///
|
||||
/// The first will contain all indices from `[0, mid)` (excluding
|
||||
|
@ -608,42 +580,6 @@ impl<T> [T] {
|
|||
core_slice::SliceExt::get_mut(self, index)
|
||||
}
|
||||
|
||||
/// Deprecated: use `&mut s[..]` instead.
|
||||
#[unstable(feature = "collections",
|
||||
reason = "will be replaced by slice syntax")]
|
||||
#[deprecated(since = "1.0.0", reason = "use &mut s[..] instead")]
|
||||
#[allow(deprecated)]
|
||||
pub fn as_mut_slice(&mut self) -> &mut [T] {
|
||||
core_slice::SliceExt::as_mut_slice(self)
|
||||
}
|
||||
|
||||
/// Deprecated: use `&mut s[start .. end]` instead.
|
||||
#[unstable(feature = "collections",
|
||||
reason = "will be replaced by slice syntax")]
|
||||
#[deprecated(since = "1.0.0", reason = "use &mut s[start .. end] instead")]
|
||||
#[inline]
|
||||
pub fn slice_mut(&mut self, start: usize, end: usize) -> &mut [T] {
|
||||
&mut self[start .. end]
|
||||
}
|
||||
|
||||
/// Deprecated: use `&mut s[start ..]` instead.
|
||||
#[unstable(feature = "collections",
|
||||
reason = "will be replaced by slice syntax")]
|
||||
#[deprecated(since = "1.0.0", reason = "use &mut s[start ..] instead")]
|
||||
#[inline]
|
||||
pub fn slice_from_mut(&mut self, start: usize) -> &mut [T] {
|
||||
&mut self[start ..]
|
||||
}
|
||||
|
||||
/// Deprecated: use `&mut s[.. end]` instead.
|
||||
#[unstable(feature = "collections",
|
||||
reason = "will be replaced by slice syntax")]
|
||||
#[deprecated(since = "1.0.0", reason = "use &mut s[.. end] instead")]
|
||||
#[inline]
|
||||
pub fn slice_to_mut(&mut self, end: usize) -> &mut [T] {
|
||||
&mut self[.. end]
|
||||
}
|
||||
|
||||
/// Returns an iterator that allows modifying each value
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
|
@ -933,13 +869,6 @@ impl<T> [T] {
|
|||
core_slice::SliceExt::binary_search(self, x)
|
||||
}
|
||||
|
||||
/// Deprecated: use `binary_search` instead.
|
||||
#[unstable(feature = "collections")]
|
||||
#[deprecated(since = "1.0.0", reason = "use binary_search instead")]
|
||||
pub fn binary_search_elem(&self, x: &T) -> Result<usize, usize> where T: Ord {
|
||||
self.binary_search(x)
|
||||
}
|
||||
|
||||
/// Mutates the slice to the next lexicographic permutation.
|
||||
///
|
||||
/// Returns `true` if successful and `false` if the slice is at the
|
||||
|
|
|
@ -70,11 +70,11 @@ use vec::Vec;
|
|||
use slice::SliceConcatExt;
|
||||
|
||||
pub use core::str::{FromStr, Utf8Error, Str};
|
||||
pub use core::str::{Lines, LinesAny, MatchIndices, SplitStr, CharRange};
|
||||
pub use core::str::{Lines, LinesAny, MatchIndices, CharRange};
|
||||
pub use core::str::{Split, SplitTerminator, SplitN};
|
||||
pub use core::str::{RSplit, RSplitN};
|
||||
pub use core::str::{from_utf8, CharEq, Chars, CharIndices, Bytes};
|
||||
pub use core::str::{from_utf8_unchecked, from_c_str, ParseBoolError};
|
||||
pub use core::str::{from_utf8, Chars, CharIndices, Bytes};
|
||||
pub use core::str::{from_utf8_unchecked, ParseBoolError};
|
||||
pub use unicode::str::{Words, Graphemes, GraphemeIndices};
|
||||
pub use core::str::Pattern;
|
||||
pub use core::str::{Searcher, ReverseSearcher, DoubleEndedSearcher, SearchStep};
|
||||
|
@ -536,22 +536,6 @@ impl str {
|
|||
core_str::StrExt::contains(&self[..], pat)
|
||||
}
|
||||
|
||||
/// Returns `true` if `self` contains a `char`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #![feature(collections)]
|
||||
/// assert!("hello".contains_char('e'));
|
||||
///
|
||||
/// assert!(!"hello".contains_char('z'));
|
||||
/// ```
|
||||
#[unstable(feature = "collections")]
|
||||
#[deprecated(since = "1.0.0", reason = "use `contains()` with a char")]
|
||||
pub fn contains_char<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool {
|
||||
core_str::StrExt::contains_char(&self[..], pat)
|
||||
}
|
||||
|
||||
/// An iterator over the codepoints of `self`.
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -778,25 +762,6 @@ impl str {
|
|||
core_str::StrExt::match_indices(&self[..], pat)
|
||||
}
|
||||
|
||||
/// An iterator over the substrings of `self` separated by a `&str`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #![feature(collections)]
|
||||
/// let v: Vec<&str> = "abcXXXabcYYYabc".split_str("abc").collect();
|
||||
/// assert_eq!(v, ["", "XXX", "YYY", ""]);
|
||||
///
|
||||
/// let v: Vec<&str> = "1abcabc2".split_str("abc").collect();
|
||||
/// assert_eq!(v, ["1", "", "2"]);
|
||||
/// ```
|
||||
#[unstable(feature = "collections")]
|
||||
#[deprecated(since = "1.0.0", reason = "use `split()` with a `&str`")]
|
||||
#[allow(deprecated) /* for SplitStr */]
|
||||
pub fn split_str<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitStr<'a, P> {
|
||||
core_str::StrExt::split_str(&self[..], pat)
|
||||
}
|
||||
|
||||
/// An iterator over the lines of a string, separated by `\n`.
|
||||
///
|
||||
/// This does not include the empty string after a trailing `\n`.
|
||||
|
@ -848,31 +813,6 @@ impl str {
|
|||
pub fn lines_any(&self) -> LinesAny {
|
||||
core_str::StrExt::lines_any(&self[..])
|
||||
}
|
||||
|
||||
/// Deprecated: use `s[a .. b]` instead.
|
||||
#[unstable(feature = "collections",
|
||||
reason = "use slice notation [a..b] instead")]
|
||||
#[deprecated(since = "1.0.0", reason = "use slice notation [a..b] instead")]
|
||||
pub fn slice(&self, begin: usize, end: usize) -> &str {
|
||||
&self[begin..end]
|
||||
}
|
||||
|
||||
/// Deprecated: use `s[a..]` instead.
|
||||
#[unstable(feature = "collections",
|
||||
reason = "use slice notation [a..b] instead")]
|
||||
#[deprecated(since = "1.0.0", reason = "use slice notation [a..] instead")]
|
||||
pub fn slice_from(&self, begin: usize) -> &str {
|
||||
&self[begin..]
|
||||
}
|
||||
|
||||
/// Deprecated: use `s[..a]` instead.
|
||||
#[unstable(feature = "collections",
|
||||
reason = "use slice notation [a..b] instead")]
|
||||
#[deprecated(since = "1.0.0", reason = "use slice notation [..a] instead")]
|
||||
pub fn slice_to(&self, end: usize) -> &str {
|
||||
&self[..end]
|
||||
}
|
||||
|
||||
/// Returns a slice of the string from the character range [`begin`..`end`).
|
||||
///
|
||||
/// That is, start at the `begin`-th code point of the string and continue
|
||||
|
@ -1306,27 +1246,6 @@ impl str {
|
|||
core_str::StrExt::rfind(&self[..], pat)
|
||||
}
|
||||
|
||||
/// Returns the byte index of the first matching substring if it exists.
|
||||
///
|
||||
/// Returns `None` if it doesn't exist.
|
||||
///
|
||||
/// The pattern can be a simple `&str`, or a closure that determines the split.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #![feature(collections)]
|
||||
/// let s = "Löwe 老虎 Léopard";
|
||||
///
|
||||
/// assert_eq!(s.find_str("老虎 L"), Some(6));
|
||||
/// assert_eq!(s.find_str("muffin man"), None);
|
||||
/// ```
|
||||
#[unstable(feature = "collections")]
|
||||
#[deprecated(since = "1.0.0", reason = "use `find()` with a `&str`")]
|
||||
pub fn find_str<'a, P: Pattern<'a>>(&'a self, needle: P) -> Option<usize> {
|
||||
core_str::StrExt::find_str(&self[..], needle)
|
||||
}
|
||||
|
||||
/// Retrieves the first character from a `&str` and returns it.
|
||||
///
|
||||
/// This does not allocate a new string; instead, it returns a slice that points one character
|
||||
|
|
|
@ -1079,11 +1079,6 @@ impl<'a> Str for Cow<'a, str> {
|
|||
}
|
||||
}
|
||||
|
||||
/// A clone-on-write string
|
||||
#[deprecated(since = "1.0.0", reason = "use Cow<'a, str> instead")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub type CowString<'a> = Cow<'a, str>;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl fmt::Write for String {
|
||||
#[inline]
|
||||
|
|
|
@ -1679,11 +1679,6 @@ impl<'a> From<&'a str> for Vec<u8> {
|
|||
// Clone-on-write
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// A clone-on-write vector
|
||||
#[deprecated(since = "1.0.0", reason = "use Cow<'a, [T]> instead")]
|
||||
#[unstable(feature = "collections")]
|
||||
pub type CowVec<'a, T> = Cow<'a, [T]>;
|
||||
|
||||
#[unstable(feature = "collections")]
|
||||
impl<'a, T> FromIterator<T> for Cow<'a, [T]> where T: Clone {
|
||||
fn from_iter<I: IntoIterator<Item=T>>(it: I) -> Cow<'a, [T]> {
|
||||
|
|
|
@ -34,10 +34,6 @@ use core::cmp;
|
|||
|
||||
use alloc::heap;
|
||||
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to VecDeque")]
|
||||
#[unstable(feature = "collections")]
|
||||
pub use VecDeque as RingBuf;
|
||||
|
||||
const INITIAL_CAPACITY: usize = 7; // 2^3 - 1
|
||||
const MINIMUM_CAPACITY: usize = 1; // 2 - 1
|
||||
|
||||
|
@ -1901,7 +1897,7 @@ mod test {
|
|||
// len is the length *after* insertion
|
||||
for len in 1..cap {
|
||||
// 0, 1, 2, .., len - 1
|
||||
let expected = iter::count(0, 1).take(len).collect();
|
||||
let expected = (0..).take(len).collect();
|
||||
for tail_pos in 0..cap {
|
||||
for to_insert in 0..len {
|
||||
tester.tail = tail_pos;
|
||||
|
@ -1934,7 +1930,7 @@ mod test {
|
|||
// len is the length *after* removal
|
||||
for len in 0..cap - 1 {
|
||||
// 0, 1, 2, .., len - 1
|
||||
let expected = iter::count(0, 1).take(len).collect();
|
||||
let expected = (0..).take(len).collect();
|
||||
for tail_pos in 0..cap {
|
||||
for to_remove in 0..len + 1 {
|
||||
tester.tail = tail_pos;
|
||||
|
@ -1972,7 +1968,7 @@ mod test {
|
|||
|
||||
for len in 0..cap + 1 {
|
||||
// 0, 1, 2, .., len - 1
|
||||
let expected = iter::count(0, 1).take(len).collect();
|
||||
let expected = (0..).take(len).collect();
|
||||
for tail_pos in 0..max_cap + 1 {
|
||||
tester.tail = tail_pos;
|
||||
tester.head = tail_pos;
|
||||
|
@ -2005,9 +2001,9 @@ mod test {
|
|||
// index to split at
|
||||
for at in 0..len + 1 {
|
||||
// 0, 1, 2, .., at - 1 (may be empty)
|
||||
let expected_self = iter::count(0, 1).take(at).collect();
|
||||
let expected_self = (0..).take(at).collect();
|
||||
// at, at + 1, .., len - 1 (may be empty)
|
||||
let expected_other = iter::count(at, 1).take(len - at).collect();
|
||||
let expected_other = (at..).take(len - at).collect();
|
||||
|
||||
for tail_pos in 0..cap {
|
||||
tester.tail = tail_pos;
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
use std::cmp::Ordering::{Equal, Greater, Less};
|
||||
use std::collections::{BitSet, BitVec};
|
||||
use std::iter::range_step;
|
||||
|
||||
#[test]
|
||||
fn test_bit_set_show() {
|
||||
|
@ -42,7 +41,7 @@ fn test_bit_set_iterator() {
|
|||
assert_eq!(idxs, [0, 2, 3]);
|
||||
|
||||
let long: BitSet = (0..10000).filter(|&n| n % 2 == 0).collect();
|
||||
let real: Vec<_> = range_step(0, 10000, 2).collect();
|
||||
let real: Vec<_> = (0..10000).step_by(2).collect();
|
||||
|
||||
let idxs: Vec<_> = long.iter().collect();
|
||||
assert_eq!(idxs, real);
|
||||
|
|
|
@ -13,5 +13,5 @@ use std::fmt;
|
|||
#[test]
|
||||
fn test_format() {
|
||||
let s = fmt::format(format_args!("Hello, {}!", "world"));
|
||||
assert_eq!(&s[..], "Hello, world!");
|
||||
assert_eq!(s, "Hello, world!");
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![allow(deprecated)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(collections)]
|
||||
#![feature(core)]
|
||||
|
@ -21,7 +20,7 @@
|
|||
#![feature(unicode)]
|
||||
#![feature(unsafe_destructor)]
|
||||
#![feature(into_cow)]
|
||||
#![feature(convert)]
|
||||
#![feature(step_by)]
|
||||
#![cfg_attr(test, feature(str_char))]
|
||||
|
||||
#[macro_use] extern crate log;
|
||||
|
|
|
@ -685,7 +685,7 @@ fn test_capacity() {
|
|||
#[test]
|
||||
fn test_slice_2() {
|
||||
let v = vec![1, 2, 3, 4, 5];
|
||||
let v = v.slice(1, 3);
|
||||
let v = &v[1..3];
|
||||
assert_eq!(v.len(), 2);
|
||||
assert_eq!(v[0], 2);
|
||||
assert_eq!(v[1], 3);
|
||||
|
|
|
@ -89,32 +89,32 @@ fn test_into_bytes() {
|
|||
#[test]
|
||||
fn test_find_str() {
|
||||
// byte positions
|
||||
assert_eq!("".find_str(""), Some(0));
|
||||
assert!("banana".find_str("apple pie").is_none());
|
||||
assert_eq!("".find(""), Some(0));
|
||||
assert!("banana".find("apple pie").is_none());
|
||||
|
||||
let data = "abcabc";
|
||||
assert_eq!(data[0..6].find_str("ab"), Some(0));
|
||||
assert_eq!(data[2..6].find_str("ab"), Some(3 - 2));
|
||||
assert!(data[2..4].find_str("ab").is_none());
|
||||
assert_eq!(data[0..6].find("ab"), Some(0));
|
||||
assert_eq!(data[2..6].find("ab"), Some(3 - 2));
|
||||
assert!(data[2..4].find("ab").is_none());
|
||||
|
||||
let string = "ประเทศไทย中华Việt Nam";
|
||||
let mut data = String::from_str(string);
|
||||
data.push_str(string);
|
||||
assert!(data.find_str("ไท华").is_none());
|
||||
assert_eq!(data[0..43].find_str(""), Some(0));
|
||||
assert_eq!(data[6..43].find_str(""), Some(6 - 6));
|
||||
assert!(data.find("ไท华").is_none());
|
||||
assert_eq!(data[0..43].find(""), Some(0));
|
||||
assert_eq!(data[6..43].find(""), Some(6 - 6));
|
||||
|
||||
assert_eq!(data[0..43].find_str("ประ"), Some( 0));
|
||||
assert_eq!(data[0..43].find_str("ทศไ"), Some(12));
|
||||
assert_eq!(data[0..43].find_str("ย中"), Some(24));
|
||||
assert_eq!(data[0..43].find_str("iệt"), Some(34));
|
||||
assert_eq!(data[0..43].find_str("Nam"), Some(40));
|
||||
assert_eq!(data[0..43].find("ประ"), Some( 0));
|
||||
assert_eq!(data[0..43].find("ทศไ"), Some(12));
|
||||
assert_eq!(data[0..43].find("ย中"), Some(24));
|
||||
assert_eq!(data[0..43].find("iệt"), Some(34));
|
||||
assert_eq!(data[0..43].find("Nam"), Some(40));
|
||||
|
||||
assert_eq!(data[43..86].find_str("ประ"), Some(43 - 43));
|
||||
assert_eq!(data[43..86].find_str("ทศไ"), Some(55 - 43));
|
||||
assert_eq!(data[43..86].find_str("ย中"), Some(67 - 43));
|
||||
assert_eq!(data[43..86].find_str("iệt"), Some(77 - 43));
|
||||
assert_eq!(data[43..86].find_str("Nam"), Some(83 - 43));
|
||||
assert_eq!(data[43..86].find("ประ"), Some(43 - 43));
|
||||
assert_eq!(data[43..86].find("ทศไ"), Some(55 - 43));
|
||||
assert_eq!(data[43..86].find("ย中"), Some(67 - 43));
|
||||
assert_eq!(data[43..86].find("iệt"), Some(77 - 43));
|
||||
assert_eq!(data[43..86].find("Nam"), Some(83 - 43));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -297,16 +297,16 @@ fn test_replace_2d() {
|
|||
|
||||
#[test]
|
||||
fn test_slice() {
|
||||
assert_eq!("ab", "abc".slice(0, 2));
|
||||
assert_eq!("bc", "abc".slice(1, 3));
|
||||
assert_eq!("", "abc".slice(1, 1));
|
||||
assert_eq!("\u{65e5}", "\u{65e5}\u{672c}".slice(0, 3));
|
||||
assert_eq!("ab", &"abc"[0..2]);
|
||||
assert_eq!("bc", &"abc"[1..3]);
|
||||
assert_eq!("", &"abc"[1..1]);
|
||||
assert_eq!("\u{65e5}", &"\u{65e5}\u{672c}"[0..3]);
|
||||
|
||||
let data = "ประเทศไทย中华";
|
||||
assert_eq!("ป", data.slice(0, 3));
|
||||
assert_eq!("ร", data.slice(3, 6));
|
||||
assert_eq!("", data.slice(3, 3));
|
||||
assert_eq!("华", data.slice(30, 33));
|
||||
assert_eq!("ป", &data[0..3]);
|
||||
assert_eq!("ร", &data[3..6]);
|
||||
assert_eq!("", &data[3..3]);
|
||||
assert_eq!("华", &data[30..33]);
|
||||
|
||||
fn a_million_letter_x() -> String {
|
||||
let mut i = 0;
|
||||
|
@ -328,23 +328,23 @@ fn test_slice() {
|
|||
}
|
||||
let letters = a_million_letter_x();
|
||||
assert!(half_a_million_letter_x() ==
|
||||
String::from_str(letters.slice(0, 3 * 500000)));
|
||||
String::from_str(&letters[0..3 * 500000]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_slice_2() {
|
||||
let ss = "中华Việt Nam";
|
||||
|
||||
assert_eq!("华", ss.slice(3, 6));
|
||||
assert_eq!("Việt Nam", ss.slice(6, 16));
|
||||
assert_eq!("华", &ss[3..6]);
|
||||
assert_eq!("Việt Nam", &ss[6..16]);
|
||||
|
||||
assert_eq!("ab", "abc".slice(0, 2));
|
||||
assert_eq!("bc", "abc".slice(1, 3));
|
||||
assert_eq!("", "abc".slice(1, 1));
|
||||
assert_eq!("ab", &"abc"[0..2]);
|
||||
assert_eq!("bc", &"abc"[1..3]);
|
||||
assert_eq!("", &"abc"[1..1]);
|
||||
|
||||
assert_eq!("中", ss.slice(0, 3));
|
||||
assert_eq!("华V", ss.slice(3, 7));
|
||||
assert_eq!("", ss.slice(3, 3));
|
||||
assert_eq!("中", &ss[0..3]);
|
||||
assert_eq!("华V", &ss[3..7]);
|
||||
assert_eq!("", &ss[3..3]);
|
||||
/*0: 中
|
||||
3: 华
|
||||
6: V
|
||||
|
@ -360,20 +360,20 @@ fn test_slice_2() {
|
|||
#[test]
|
||||
#[should_panic]
|
||||
fn test_slice_fail() {
|
||||
"中华Việt Nam".slice(0, 2);
|
||||
&"中华Việt Nam"[0..2];
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_slice_from() {
|
||||
assert_eq!("abcd".slice_from(0), "abcd");
|
||||
assert_eq!("abcd".slice_from(2), "cd");
|
||||
assert_eq!("abcd".slice_from(4), "");
|
||||
assert_eq!(&"abcd"[0..], "abcd");
|
||||
assert_eq!(&"abcd"[2..], "cd");
|
||||
assert_eq!(&"abcd"[4..], "");
|
||||
}
|
||||
#[test]
|
||||
fn test_slice_to() {
|
||||
assert_eq!("abcd".slice_to(0), "");
|
||||
assert_eq!("abcd".slice_to(2), "ab");
|
||||
assert_eq!("abcd".slice_to(4), "abcd");
|
||||
assert_eq!(&"abcd"[..0], "");
|
||||
assert_eq!(&"abcd"[..2], "ab");
|
||||
assert_eq!(&"abcd"[..4], "abcd");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -660,10 +660,10 @@ fn test_contains() {
|
|||
|
||||
#[test]
|
||||
fn test_contains_char() {
|
||||
assert!("abc".contains_char('b'));
|
||||
assert!("a".contains_char('a'));
|
||||
assert!(!"abc".contains_char('d'));
|
||||
assert!(!"".contains_char('a'));
|
||||
assert!("abc".contains('b'));
|
||||
assert!("a".contains('a'));
|
||||
assert!(!"abc".contains('d'));
|
||||
assert!(!"".contains('a'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1445,9 +1445,9 @@ fn test_graphemes() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_split_strator() {
|
||||
fn test_splitator() {
|
||||
fn t(s: &str, sep: &str, u: &[&str]) {
|
||||
let v: Vec<&str> = s.split_str(sep).collect();
|
||||
let v: Vec<&str> = s.split(sep).collect();
|
||||
assert_eq!(v, u);
|
||||
}
|
||||
t("--1233345--", "12345", &["--1233345--"]);
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::borrow::IntoCow;
|
||||
use std::borrow::{IntoCow, Cow};
|
||||
use std::iter::repeat;
|
||||
use std::str::Utf8Error;
|
||||
use std::string::{CowString, as_string};
|
||||
use std::string::as_string;
|
||||
|
||||
use test::Bencher;
|
||||
|
||||
|
@ -52,11 +52,11 @@ fn test_from_utf8() {
|
|||
#[test]
|
||||
fn test_from_utf8_lossy() {
|
||||
let xs = b"hello";
|
||||
let ys: CowString = "hello".into_cow();
|
||||
let ys: Cow<str> = "hello".into_cow();
|
||||
assert_eq!(String::from_utf8_lossy(xs), ys);
|
||||
|
||||
let xs = "ศไทย中华Việt Nam".as_bytes();
|
||||
let ys: CowString = "ศไทย中华Việt Nam".into_cow();
|
||||
let ys: Cow<str> = "ศไทย中华Việt Nam".into_cow();
|
||||
assert_eq!(String::from_utf8_lossy(xs), ys);
|
||||
|
||||
let xs = b"Hello\xC2 There\xFF Goodbye";
|
||||
|
|
|
@ -18,7 +18,6 @@ use self::Taggy::*;
|
|||
use self::Taggypar::*;
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn test_simple() {
|
||||
let mut d = VecDeque::new();
|
||||
assert_eq!(d.len(), 0);
|
||||
|
@ -545,7 +544,7 @@ fn test_from_iter() {
|
|||
let u: Vec<_> = deq.iter().cloned().collect();
|
||||
assert_eq!(u, v);
|
||||
|
||||
let seq = iter::count(0, 2).take(256);
|
||||
let seq = (0..).step_by(2).take(256);
|
||||
let deq: VecDeque<_> = seq.collect();
|
||||
for (i, &x) in deq.iter().enumerate() {
|
||||
assert_eq!(2*i, x);
|
||||
|
|
|
@ -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) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -407,23 +390,6 @@ impl<T> RefCell<T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Mutably borrows the wrapped value.
|
||||
///
|
||||
/// 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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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>> {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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; }
|
||||
/// }
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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];
|
||||
|
@ -263,12 +259,6 @@ impl<T> SliceExt for [T] {
|
|||
if index < self.len() { Some(&mut self[index]) } else { None }
|
||||
}
|
||||
|
||||
#[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 {
|
||||
|
@ -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
|
||||
//
|
||||
|
|
|
@ -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;
|
||||
|
@ -1565,12 +1473,6 @@ impl StrExt for str {
|
|||
MatchIndices(pat.into_searcher(self))
|
||||
}
|
||||
|
||||
#[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 }
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/// Searches for chars that are equal to any of the chars in the array
|
||||
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]
|
||||
|
||||
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`
|
||||
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
|
||||
{}
|
||||
|
||||
// Pattern 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));
|
||||
}
|
||||
|
||||
/// 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));
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ fn double_imm_borrow() {
|
|||
fn no_mut_then_imm_borrow() {
|
||||
let x = RefCell::new(0);
|
||||
let _b1 = x.borrow_mut();
|
||||
assert!(x.try_borrow().is_none());
|
||||
assert_eq!(x.borrow_state(), BorrowState::Writing);
|
||||
}
|
||||
|
||||
|
@ -67,7 +66,6 @@ fn no_mut_then_imm_borrow() {
|
|||
fn no_imm_then_borrow_mut() {
|
||||
let x = RefCell::new(0);
|
||||
let _b1 = x.borrow();
|
||||
assert!(x.try_borrow_mut().is_none());
|
||||
assert_eq!(x.borrow_state(), BorrowState::Reading);
|
||||
}
|
||||
|
||||
|
@ -76,7 +74,6 @@ fn no_double_borrow_mut() {
|
|||
let x = RefCell::new(0);
|
||||
assert_eq!(x.borrow_state(), BorrowState::Unused);
|
||||
let _b1 = x.borrow_mut();
|
||||
assert!(x.try_borrow_mut().is_none());
|
||||
assert_eq!(x.borrow_state(), BorrowState::Writing);
|
||||
}
|
||||
|
||||
|
@ -105,7 +102,7 @@ fn double_borrow_single_release_no_borrow_mut() {
|
|||
{
|
||||
let _b2 = x.borrow();
|
||||
}
|
||||
assert!(x.try_borrow_mut().is_none());
|
||||
assert_eq!(x.borrow_state(), BorrowState::Reading);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -122,14 +119,14 @@ fn clone_ref_updates_flag() {
|
|||
let x = RefCell::new(0);
|
||||
{
|
||||
let b1 = x.borrow();
|
||||
assert!(x.try_borrow_mut().is_none());
|
||||
assert_eq!(x.borrow_state(), BorrowState::Reading);
|
||||
{
|
||||
let _b2 = clone_ref(&b1);
|
||||
assert!(x.try_borrow_mut().is_none());
|
||||
assert_eq!(x.borrow_state(), BorrowState::Reading);
|
||||
}
|
||||
assert!(x.try_borrow_mut().is_none());
|
||||
assert_eq!(x.borrow_state(), BorrowState::Reading);
|
||||
}
|
||||
assert!(x.try_borrow_mut().is_some());
|
||||
assert_eq!(x.borrow_state(), BorrowState::Unused);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
// Copyright 2014 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.
|
||||
|
||||
#![allow(deprecated)]
|
||||
|
||||
use core::finally::{try_finally, Finally};
|
||||
use std::thread;
|
||||
|
||||
#[test]
|
||||
fn test_success() {
|
||||
let mut i = 0;
|
||||
try_finally(
|
||||
&mut i, (),
|
||||
|i, ()| {
|
||||
*i = 10;
|
||||
},
|
||||
|i| {
|
||||
assert!(!thread::panicking());
|
||||
assert_eq!(*i, 10);
|
||||
*i = 20;
|
||||
});
|
||||
assert_eq!(i, 20);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_fail() {
|
||||
let mut i = 0;
|
||||
try_finally(
|
||||
&mut i, (),
|
||||
|i, ()| {
|
||||
*i = 10;
|
||||
panic!();
|
||||
},
|
||||
|i| {
|
||||
assert!(thread::panicking());
|
||||
assert_eq!(*i, 10);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_retval() {
|
||||
let mut closure = || 10;
|
||||
// FIXME(#16640) `: i32` annotation shouldn't be necessary
|
||||
let i: i32 = closure.finally(|| { });
|
||||
assert_eq!(i, 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_compact() {
|
||||
fn do_some_fallible_work() {}
|
||||
fn but_always_run_this_function() { }
|
||||
let mut f = do_some_fallible_work;
|
||||
f.finally(but_always_run_this_function);
|
||||
}
|
|
@ -72,7 +72,7 @@ fn test_multi_iter() {
|
|||
|
||||
#[test]
|
||||
fn test_counter_from_iter() {
|
||||
let it = count(0, 5).take(10);
|
||||
let it = (0..).step_by(5).take(10);
|
||||
let xs: Vec<isize> = FromIterator::from_iter(it);
|
||||
assert_eq!(xs, [0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ fn test_iterator_chain() {
|
|||
}
|
||||
assert_eq!(i, expected.len());
|
||||
|
||||
let ys = count(30, 10).take(4);
|
||||
let ys = (30..).step_by(10).take(4);
|
||||
let it = xs.iter().cloned().chain(ys);
|
||||
let mut i = 0;
|
||||
for x in it {
|
||||
|
@ -102,7 +102,7 @@ fn test_iterator_chain() {
|
|||
|
||||
#[test]
|
||||
fn test_filter_map() {
|
||||
let it = count(0, 1).take(10)
|
||||
let it = (0..).step_by(1).take(10)
|
||||
.filter_map(|x| if x % 2 == 0 { Some(x*x) } else { None });
|
||||
assert_eq!(it.collect::<Vec<usize>>(), [0*0, 2*2, 4*4, 6*6, 8*8]);
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ fn test_iterator_scan() {
|
|||
fn test_iterator_flat_map() {
|
||||
let xs = [0, 3, 6];
|
||||
let ys = [0, 1, 2, 3, 4, 5, 6, 7, 8];
|
||||
let it = xs.iter().flat_map(|&x| count(x, 1).take(3));
|
||||
let it = xs.iter().flat_map(|&x| (x..).step_by(1).take(3));
|
||||
let mut i = 0;
|
||||
for x in it {
|
||||
assert_eq!(x, ys[i]);
|
||||
|
@ -291,13 +291,13 @@ fn test_unfoldr() {
|
|||
#[test]
|
||||
fn test_cycle() {
|
||||
let cycle_len = 3;
|
||||
let it = count(0, 1).take(cycle_len).cycle();
|
||||
let it = (0..).step_by(1).take(cycle_len).cycle();
|
||||
assert_eq!(it.size_hint(), (usize::MAX, None));
|
||||
for (i, x) in it.take(100).enumerate() {
|
||||
assert_eq!(i % cycle_len, x);
|
||||
}
|
||||
|
||||
let mut it = count(0, 1).take(0).cycle();
|
||||
let mut it = (0..).step_by(1).take(0).cycle();
|
||||
assert_eq!(it.size_hint(), (0, Some(0)));
|
||||
assert_eq!(it.next(), None);
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ fn test_iterator_min() {
|
|||
|
||||
#[test]
|
||||
fn test_iterator_size_hint() {
|
||||
let c = count(0, 1);
|
||||
let c = (0..).step_by(1);
|
||||
let v: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
let v2 = &[10, 11, 12];
|
||||
let vi = v.iter();
|
||||
|
|
|
@ -39,7 +39,6 @@ mod atomic;
|
|||
mod cell;
|
||||
mod char;
|
||||
mod cmp;
|
||||
mod finally;
|
||||
mod fmt;
|
||||
mod hash;
|
||||
mod iter;
|
||||
|
|
|
@ -163,9 +163,9 @@ fn starts_short_long() {
|
|||
|
||||
#[test]
|
||||
fn contains_weird_cases() {
|
||||
assert!("* \t".contains_char(' '));
|
||||
assert!(!"* \t".contains_char('?'));
|
||||
assert!(!"* \t".contains_char('\u{1F4A9}'));
|
||||
assert!("* \t".contains(' '));
|
||||
assert!(!"* \t".contains('?'));
|
||||
assert!(!"* \t".contains('\u{1F4A9}'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -347,11 +347,11 @@ malesuada sollicitudin quam eu fermentum!");
|
|||
make_test!(chars_count, s, s.chars().count());
|
||||
|
||||
make_test!(contains_bang_str, s, s.contains("!"));
|
||||
make_test!(contains_bang_char, s, s.contains_char('!'));
|
||||
make_test!(contains_bang_char, s, s.contains('!'));
|
||||
|
||||
make_test!(match_indices_a_str, s, s.match_indices("a").count());
|
||||
|
||||
make_test!(split_str_a_str, s, s.split_str("a").count());
|
||||
make_test!(split_a_str, s, s.split("a").count());
|
||||
|
||||
make_test!(trim_ascii_char, s, {
|
||||
use std::ascii::AsciiExt;
|
||||
|
@ -368,11 +368,11 @@ malesuada sollicitudin quam eu fermentum!");
|
|||
|
||||
make_test!(find_underscore_char, s, s.find('_'));
|
||||
make_test!(rfind_underscore_char, s, s.rfind('_'));
|
||||
make_test!(find_underscore_str, s, s.find_str("_"));
|
||||
make_test!(find_underscore_str, s, s.find("_"));
|
||||
|
||||
make_test!(find_zzz_char, s, s.find('\u{1F4A4}'));
|
||||
make_test!(rfind_zzz_char, s, s.rfind('\u{1F4A4}'));
|
||||
make_test!(find_zzz_str, s, s.find_str("\u{1F4A4}"));
|
||||
make_test!(find_zzz_str, s, s.find("\u{1F4A4}"));
|
||||
|
||||
make_test!(split_space_char, s, s.split(' ').count());
|
||||
make_test!(split_terminator_space_char, s, s.split_terminator(' ').count());
|
||||
|
@ -380,6 +380,6 @@ malesuada sollicitudin quam eu fermentum!");
|
|||
make_test!(splitn_space_char, s, s.splitn(10, ' ').count());
|
||||
make_test!(rsplitn_space_char, s, s.rsplitn(10, ' ').count());
|
||||
|
||||
make_test!(split_str_space_str, s, s.split_str(" ").count());
|
||||
make_test!(split_str_ad_str, s, s.split_str("ad").count());
|
||||
make_test!(split_space_str, s, s.split(" ").count());
|
||||
make_test!(split_ad_str, s, s.split("ad").count());
|
||||
}
|
||||
|
|
|
@ -228,8 +228,9 @@ pub fn memoized<T, U, S, F>(cache: &RefCell<HashMap<T, U, S>>, arg: T, f: F) ->
|
|||
#[cfg(unix)]
|
||||
pub fn path2cstr(p: &Path) -> CString {
|
||||
use std::os::unix::prelude::*;
|
||||
use std::ffi::AsOsStr;
|
||||
CString::new(p.as_os_str().as_bytes()).unwrap()
|
||||
use std::ffi::OsStr;
|
||||
let p: &OsStr = p.as_ref();
|
||||
CString::new(p.as_bytes()).unwrap()
|
||||
}
|
||||
#[cfg(windows)]
|
||||
pub fn path2cstr(p: &Path) -> CString {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
use std::io;
|
||||
use std::env;
|
||||
#[allow(deprecated)] use std::old_path::{self, GenericPath};
|
||||
#[allow(deprecated)] use std::old_io;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
@ -29,9 +30,9 @@ pub fn realpath(original: &Path) -> io::Result<PathBuf> {
|
|||
#[allow(deprecated)]
|
||||
fn old_realpath(original: &old_path::Path) -> old_io::IoResult<old_path::Path> {
|
||||
use std::old_io::fs;
|
||||
use std::os;
|
||||
const MAX_LINKS_FOLLOWED: usize = 256;
|
||||
let original = try!(os::getcwd()).join(original);
|
||||
let original = old_path::Path::new(env::current_dir().unwrap()
|
||||
.to_str().unwrap()).join(original);
|
||||
|
||||
// Right now lstat on windows doesn't work quite well
|
||||
if cfg!(windows) {
|
||||
|
|
|
@ -39,12 +39,10 @@
|
|||
#![feature(io)]
|
||||
#![feature(old_io)]
|
||||
#![feature(old_path)]
|
||||
#![feature(os)]
|
||||
#![feature(rustc_private)]
|
||||
#![feature(staged_api)]
|
||||
#![feature(rand)]
|
||||
#![feature(path_ext)]
|
||||
#![feature(std_misc)]
|
||||
#![feature(step_by)]
|
||||
#![cfg_attr(test, feature(test, rand))]
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#![allow(deprecated)] // to_be32
|
||||
|
||||
use std::iter::{range_step, repeat};
|
||||
use std::iter::repeat;
|
||||
use std::num::Int;
|
||||
use std::slice::bytes::{MutableByteVector, copy_memory};
|
||||
use serialize::hex::ToHex;
|
||||
|
@ -368,7 +368,7 @@ impl Engine256State {
|
|||
|
||||
// Putting the message schedule inside the same loop as the round calculations allows for
|
||||
// the compiler to generate better code.
|
||||
for t in range_step(0, 48, 8) {
|
||||
for t in (0..48).step_by(8) {
|
||||
schedule_round!(t + 16);
|
||||
schedule_round!(t + 17);
|
||||
schedule_round!(t + 18);
|
||||
|
@ -388,7 +388,7 @@ impl Engine256State {
|
|||
sha2_round!(b, c, d, e, f, g, h, a, K32, t + 7);
|
||||
}
|
||||
|
||||
for t in range_step(48, 64, 8) {
|
||||
for t in (48..64).step_by(8) {
|
||||
sha2_round!(a, b, c, d, e, f, g, h, K32, t);
|
||||
sha2_round!(h, a, b, c, d, e, f, g, K32, t + 1);
|
||||
sha2_round!(g, h, a, b, c, d, e, f, K32, t + 2);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
use std::env;
|
||||
use std::io::{self, Error, ErrorKind};
|
||||
use std::fs;
|
||||
use std::path::{self, PathBuf, AsPath};
|
||||
use std::path::{self, PathBuf, Path};
|
||||
use std::rand::{thread_rng, Rng};
|
||||
|
||||
/// A wrapper for a path to temporary directory implementing automatic
|
||||
|
@ -36,10 +36,10 @@ impl TempDir {
|
|||
///
|
||||
/// If no directory can be created, `Err` is returned.
|
||||
#[allow(deprecated)] // rand usage
|
||||
pub fn new_in<P: AsPath + ?Sized>(tmpdir: &P, prefix: &str)
|
||||
-> io::Result<TempDir> {
|
||||
pub fn new_in<P: AsRef<Path>>(tmpdir: P, prefix: &str)
|
||||
-> io::Result<TempDir> {
|
||||
let storage;
|
||||
let mut tmpdir = tmpdir.as_path();
|
||||
let mut tmpdir = tmpdir.as_ref();
|
||||
if !tmpdir.is_absolute() {
|
||||
let cur_dir = try!(env::current_dir());
|
||||
storage = cur_dir.join(tmpdir);
|
||||
|
|
|
@ -42,8 +42,9 @@ impl ArchiveRO {
|
|||
#[cfg(unix)]
|
||||
fn path2cstr(p: &Path) -> CString {
|
||||
use std::os::unix::prelude::*;
|
||||
use std::ffi::AsOsStr;
|
||||
CString::new(p.as_os_str().as_bytes()).unwrap()
|
||||
use std::ffi::OsStr;
|
||||
let p: &OsStr = p.as_ref();
|
||||
CString::new(p.as_bytes()).unwrap()
|
||||
}
|
||||
#[cfg(windows)]
|
||||
fn path2cstr(p: &Path) -> CString {
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#![feature(libc)]
|
||||
#![feature(link_args)]
|
||||
#![feature(staged_api)]
|
||||
#![cfg_attr(unix, feature(std_misc))]
|
||||
#![cfg_attr(unix, feature(convert))]
|
||||
|
||||
extern crate libc;
|
||||
#[macro_use] #[no_link] extern crate rustc_bitflags;
|
||||
|
|
|
@ -20,7 +20,7 @@ pub use self::imp::Lock;
|
|||
|
||||
#[cfg(unix)]
|
||||
mod imp {
|
||||
use std::ffi::{AsOsStr, CString};
|
||||
use std::ffi::{CString, OsStr};
|
||||
use std::os::unix::prelude::*;
|
||||
use std::path::Path;
|
||||
use std::io;
|
||||
|
@ -116,7 +116,8 @@ mod imp {
|
|||
|
||||
impl Lock {
|
||||
pub fn new(p: &Path) -> Lock {
|
||||
let buf = CString::new(p.as_os_str().as_bytes()).unwrap();
|
||||
let os: &OsStr = p.as_ref();
|
||||
let buf = CString::new(os.as_bytes()).unwrap();
|
||||
let fd = unsafe {
|
||||
libc::open(buf.as_ptr(), libc::O_RDWR | libc::O_CREAT,
|
||||
libc::S_IRWXU)
|
||||
|
@ -164,9 +165,9 @@ mod imp {
|
|||
#[cfg(windows)]
|
||||
mod imp {
|
||||
use libc;
|
||||
use std::ffi::AsOsStr;
|
||||
use std::io;
|
||||
use std::mem;
|
||||
use std::ffi::OsStr;
|
||||
use std::os::windows::prelude::*;
|
||||
use std::path::Path;
|
||||
use std::ptr;
|
||||
|
@ -194,7 +195,8 @@ mod imp {
|
|||
|
||||
impl Lock {
|
||||
pub fn new(p: &Path) -> Lock {
|
||||
let mut p_16: Vec<_> = p.as_os_str().encode_wide().collect();
|
||||
let p: &OsStr = p.as_ref();
|
||||
let mut p_16: Vec<_> = p.encode_wide().collect();
|
||||
p_16.push(0);
|
||||
let handle = unsafe {
|
||||
libc::CreateFileW(p_16.as_ptr(),
|
||||
|
|
|
@ -15,7 +15,7 @@ use self::BucketState::*;
|
|||
use clone::Clone;
|
||||
use cmp;
|
||||
use hash::{Hash, Hasher};
|
||||
use iter::{Iterator, ExactSizeIterator, count};
|
||||
use iter::{Iterator, ExactSizeIterator};
|
||||
use marker::{Copy, Send, Sync, Sized, self};
|
||||
use mem::{min_align_of, size_of};
|
||||
use mem;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
use prelude::v1::*;
|
||||
|
||||
use env;
|
||||
use ffi::{AsOsStr, CString, OsString};
|
||||
use ffi::{CString, OsString};
|
||||
use mem;
|
||||
use path::{Path, PathBuf};
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ use prelude::v1::*;
|
|||
|
||||
use iter::IntoIterator;
|
||||
use error::Error;
|
||||
use ffi::{OsString, AsOsStr};
|
||||
use ffi::{OsStr, OsString};
|
||||
use fmt;
|
||||
use io;
|
||||
use path::{Path, PathBuf};
|
||||
|
@ -176,7 +176,7 @@ impl Iterator for VarsOs {
|
|||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "env", since = "1.0.0")]
|
||||
pub fn var<K: ?Sized>(key: &K) -> Result<String, VarError> where K: AsOsStr {
|
||||
pub fn var<K: ?Sized>(key: &K) -> Result<String, VarError> where K: AsRef<OsStr> {
|
||||
match var_os(key) {
|
||||
Some(s) => s.into_string().map_err(VarError::NotUnicode),
|
||||
None => Err(VarError::NotPresent)
|
||||
|
@ -198,9 +198,9 @@ pub fn var<K: ?Sized>(key: &K) -> Result<String, VarError> where K: AsOsStr {
|
|||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "env", since = "1.0.0")]
|
||||
pub fn var_os<K: ?Sized>(key: &K) -> Option<OsString> where K: AsOsStr {
|
||||
pub fn var_os<K: ?Sized>(key: &K) -> Option<OsString> where K: AsRef<OsStr> {
|
||||
let _g = ENV_LOCK.lock();
|
||||
os_imp::getenv(key.as_os_str())
|
||||
os_imp::getenv(key.as_ref())
|
||||
}
|
||||
|
||||
/// Possible errors from the `env::var` method.
|
||||
|
@ -255,10 +255,10 @@ impl Error for VarError {
|
|||
/// ```
|
||||
#[stable(feature = "env", since = "1.0.0")]
|
||||
pub fn set_var<K: ?Sized, V: ?Sized>(k: &K, v: &V)
|
||||
where K: AsOsStr, V: AsOsStr
|
||||
where K: AsRef<OsStr>, V: AsRef<OsStr>
|
||||
{
|
||||
let _g = ENV_LOCK.lock();
|
||||
os_imp::setenv(k.as_os_str(), v.as_os_str())
|
||||
os_imp::setenv(k.as_ref(), v.as_ref())
|
||||
}
|
||||
|
||||
/// Remove an environment variable from the environment of the currently running process.
|
||||
|
@ -276,9 +276,9 @@ pub fn set_var<K: ?Sized, V: ?Sized>(k: &K, v: &V)
|
|||
/// assert!(env::var(key).is_err());
|
||||
/// ```
|
||||
#[stable(feature = "env", since = "1.0.0")]
|
||||
pub fn remove_var<K: ?Sized>(k: &K) where K: AsOsStr {
|
||||
pub fn remove_var<K: ?Sized>(k: &K) where K: AsRef<OsStr> {
|
||||
let _g = ENV_LOCK.lock();
|
||||
os_imp::unsetenv(k.as_os_str())
|
||||
os_imp::unsetenv(k.as_ref())
|
||||
}
|
||||
|
||||
/// An iterator over `Path` instances for parsing an environment variable
|
||||
|
@ -309,8 +309,8 @@ pub struct SplitPaths<'a> { inner: os_imp::SplitPaths<'a> }
|
|||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "env", since = "1.0.0")]
|
||||
pub fn split_paths<T: AsOsStr + ?Sized>(unparsed: &T) -> SplitPaths {
|
||||
SplitPaths { inner: os_imp::split_paths(unparsed.as_os_str()) }
|
||||
pub fn split_paths<T: AsRef<OsStr> + ?Sized>(unparsed: &T) -> SplitPaths {
|
||||
SplitPaths { inner: os_imp::split_paths(unparsed.as_ref()) }
|
||||
}
|
||||
|
||||
#[stable(feature = "env", since = "1.0.0")]
|
||||
|
@ -352,7 +352,7 @@ pub struct JoinPathsError {
|
|||
/// ```
|
||||
#[stable(feature = "env", since = "1.0.0")]
|
||||
pub fn join_paths<I, T>(paths: I) -> Result<OsString, JoinPathsError>
|
||||
where I: IntoIterator<Item=T>, T: AsOsStr
|
||||
where I: IntoIterator<Item=T>, T: AsRef<OsStr>
|
||||
{
|
||||
os_imp::join_paths(paths.into_iter()).map_err(|e| {
|
||||
JoinPathsError { inner: e }
|
||||
|
@ -766,7 +766,7 @@ mod tests {
|
|||
let mut rng = rand::thread_rng();
|
||||
let n = format!("TEST{}", rng.gen_ascii_chars().take(10)
|
||||
.collect::<String>());
|
||||
let n = OsString::from_string(n);
|
||||
let n = OsString::from(n);
|
||||
assert!(var_os(&n).is_none());
|
||||
n
|
||||
}
|
||||
|
|
|
@ -132,15 +132,6 @@ pub struct CStr {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct NulError(usize, Vec<u8>);
|
||||
|
||||
/// A conversion trait used by the constructor of `CString` for types that can
|
||||
/// be converted to a vector of bytes.
|
||||
#[deprecated(since = "1.0.0", reason = "use std::convert::Into<Vec<u8>> instead")]
|
||||
#[unstable(feature = "std_misc")]
|
||||
pub trait IntoBytes {
|
||||
/// Consumes this container, returning a vector of bytes.
|
||||
fn into_bytes(self) -> Vec<u8>;
|
||||
}
|
||||
|
||||
impl CString {
|
||||
/// Create a new C-compatible string from a container of bytes.
|
||||
///
|
||||
|
@ -178,57 +169,6 @@ impl CString {
|
|||
}
|
||||
}
|
||||
|
||||
/// Create a new C-compatible string from a byte slice.
|
||||
///
|
||||
/// This method will copy the data of the slice provided into a new
|
||||
/// allocation, ensuring that there is a trailing 0 byte.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// # #![feature(libc)]
|
||||
/// extern crate libc;
|
||||
/// use std::ffi::CString;
|
||||
///
|
||||
/// extern { fn puts(s: *const libc::c_char); }
|
||||
///
|
||||
/// fn main() {
|
||||
/// let to_print = CString::new("Hello!").unwrap();
|
||||
/// unsafe {
|
||||
/// puts(to_print.as_ptr());
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic if the provided slice contains any
|
||||
/// interior nul bytes.
|
||||
#[unstable(feature = "std_misc")]
|
||||
#[deprecated(since = "1.0.0", reason = "use CString::new instead")]
|
||||
#[allow(deprecated)]
|
||||
pub fn from_slice(v: &[u8]) -> CString {
|
||||
CString::from_vec(v.to_vec())
|
||||
}
|
||||
|
||||
/// Create a C-compatible string from a byte vector.
|
||||
///
|
||||
/// This method will consume ownership of the provided vector, appending a 0
|
||||
/// byte to the end after verifying that there are no interior 0 bytes.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic if the provided slice contains any
|
||||
/// interior nul bytes.
|
||||
#[unstable(feature = "std_misc")]
|
||||
#[deprecated(since = "1.0.0", reason = "use CString::new instead")]
|
||||
pub fn from_vec(v: Vec<u8>) -> CString {
|
||||
match v.iter().position(|x| *x == 0) {
|
||||
Some(i) => panic!("null byte found in slice at: {}", i),
|
||||
None => unsafe { CString::from_vec_unchecked(v) },
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a C-compatible string from a byte vector without checking for
|
||||
/// interior 0 bytes.
|
||||
///
|
||||
|
@ -424,41 +364,6 @@ impl Ord for CStr {
|
|||
}
|
||||
}
|
||||
|
||||
/// Deprecated in favor of `CStr`
|
||||
#[unstable(feature = "std_misc")]
|
||||
#[deprecated(since = "1.0.0", reason = "use CStr::from_ptr(p).to_bytes() instead")]
|
||||
pub unsafe fn c_str_to_bytes<'a>(raw: &'a *const libc::c_char) -> &'a [u8] {
|
||||
let len = libc::strlen(*raw);
|
||||
slice::from_raw_parts(*(raw as *const _ as *const *const u8), len as usize)
|
||||
}
|
||||
|
||||
/// Deprecated in favor of `CStr`
|
||||
#[unstable(feature = "std_misc")]
|
||||
#[deprecated(since = "1.0.0",
|
||||
reason = "use CStr::from_ptr(p).to_bytes_with_nul() instead")]
|
||||
pub unsafe fn c_str_to_bytes_with_nul<'a>(raw: &'a *const libc::c_char)
|
||||
-> &'a [u8] {
|
||||
let len = libc::strlen(*raw) + 1;
|
||||
slice::from_raw_parts(*(raw as *const _ as *const *const u8), len as usize)
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
impl<'a> IntoBytes for &'a str {
|
||||
fn into_bytes(self) -> Vec<u8> { self.as_bytes().to_vec() }
|
||||
}
|
||||
#[allow(deprecated)]
|
||||
impl<'a> IntoBytes for &'a [u8] {
|
||||
fn into_bytes(self) -> Vec<u8> { self.to_vec() }
|
||||
}
|
||||
#[allow(deprecated)]
|
||||
impl IntoBytes for String {
|
||||
fn into_bytes(self) -> Vec<u8> { self.into_bytes() }
|
||||
}
|
||||
#[allow(deprecated)]
|
||||
impl IntoBytes for Vec<u8> {
|
||||
fn into_bytes(self) -> Vec<u8> { self }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use prelude::v1::*;
|
||||
|
|
|
@ -13,17 +13,10 @@
|
|||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub use self::c_str::{CString, CStr};
|
||||
pub use self::c_str::{NulError, IntoBytes};
|
||||
#[allow(deprecated)]
|
||||
pub use self::c_str::c_str_to_bytes;
|
||||
#[allow(deprecated)]
|
||||
pub use self::c_str::c_str_to_bytes_with_nul;
|
||||
pub use self::c_str::{CString, CStr, NulError};
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub use self::os_str::OsString;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub use self::os_str::OsStr;
|
||||
pub use self::os_str::{OsString, OsStr};
|
||||
|
||||
mod c_str;
|
||||
mod os_str;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
//! for conversion to/from various other string types. Eventually these types
|
||||
//! will offer a full-fledged string API.
|
||||
|
||||
#![unstable(feature = "os",
|
||||
#![unstable(feature = "os_str",
|
||||
reason = "recently added as part of path/io reform")]
|
||||
|
||||
use core::prelude::*;
|
||||
|
@ -63,22 +63,6 @@ pub struct OsStr {
|
|||
}
|
||||
|
||||
impl OsString {
|
||||
/// Constructs an `OsString` at no cost by consuming a `String`.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[deprecated(since = "1.0.0", reason = "use `from` instead")]
|
||||
pub fn from_string(s: String) -> OsString {
|
||||
OsString::from(s)
|
||||
}
|
||||
|
||||
/// Constructs an `OsString` by copying from a `&str` slice.
|
||||
///
|
||||
/// Equivalent to: `OsString::from_string(String::from_str(s))`.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[deprecated(since = "1.0.0", reason = "use `from` instead")]
|
||||
pub fn from_str(s: &str) -> OsString {
|
||||
OsString::from(s)
|
||||
}
|
||||
|
||||
/// Constructs a new empty `OsString`.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn new() -> OsString {
|
||||
|
@ -124,13 +108,6 @@ impl OsString {
|
|||
self.inner.into_string().map_err(|buf| OsString { inner: buf} )
|
||||
}
|
||||
|
||||
/// Extend the string with the given `&OsStr` slice.
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to `push`")]
|
||||
#[unstable(feature = "os")]
|
||||
pub fn push_os_str(&mut self, s: &OsStr) {
|
||||
self.inner.push_slice(&s.inner)
|
||||
}
|
||||
|
||||
/// Extend the string with the given `&OsStr` slice.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn push<T: AsRef<OsStr>>(&mut self, s: T) {
|
||||
|
|
|
@ -25,11 +25,6 @@ use sys::fs2 as fs_imp;
|
|||
use sys_common::{AsInnerMut, FromInner, AsInner};
|
||||
use vec::Vec;
|
||||
|
||||
#[allow(deprecated)]
|
||||
pub use self::tempdir::TempDir;
|
||||
|
||||
mod tempdir;
|
||||
|
||||
/// A reference to an open file on the filesystem.
|
||||
///
|
||||
/// An instance of a `File` can be read and/or written depending on what options
|
||||
|
@ -1333,7 +1328,7 @@ mod tests {
|
|||
check!(fs::copy(&input, &out));
|
||||
let mut v = Vec::new();
|
||||
check!(check!(File::open(&out)).read_to_end(&mut v));
|
||||
assert_eq!(&v[..], b"hello");
|
||||
assert_eq!(v, b"hello");
|
||||
|
||||
assert_eq!(check!(input.metadata()).permissions(),
|
||||
check!(out.metadata()).permissions());
|
|
@ -1,127 +0,0 @@
|
|||
// Copyright 2015 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.
|
||||
|
||||
#![unstable(feature = "tempdir", reason = "needs an RFC before stabilization")]
|
||||
#![deprecated(since = "1.0.0",
|
||||
reason = "use the `tempdir` crate from crates.io instead")]
|
||||
#![allow(deprecated)]
|
||||
|
||||
use prelude::v1::*;
|
||||
|
||||
use env;
|
||||
use io::{self, Error, ErrorKind};
|
||||
use fs;
|
||||
use path::{self, PathBuf};
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
/// A wrapper for a path to temporary directory implementing automatic
|
||||
/// scope-based deletion.
|
||||
pub struct TempDir {
|
||||
path: Option<PathBuf>,
|
||||
}
|
||||
|
||||
// How many times should we (re)try finding an unused random name? It should be
|
||||
// enough that an attacker will run out of luck before we run out of patience.
|
||||
const NUM_RETRIES: u32 = 1 << 31;
|
||||
// How many characters should we include in a random file name? It needs to
|
||||
// be enough to dissuade an attacker from trying to preemptively create names
|
||||
// of that length, but not so huge that we unnecessarily drain the random number
|
||||
// generator of entropy.
|
||||
const NUM_RAND_CHARS: usize = 12;
|
||||
|
||||
impl TempDir {
|
||||
/// Attempts to make a temporary directory inside of `tmpdir` whose name
|
||||
/// will have the prefix `prefix`. The directory will be automatically
|
||||
/// deleted once the returned wrapper is destroyed.
|
||||
///
|
||||
/// If no directory can be created, `Err` is returned.
|
||||
#[allow(deprecated)] // rand usage
|
||||
pub fn new_in<P: AsRef<path::Path>>(tmpdir: P, prefix: &str) -> io::Result<TempDir> {
|
||||
let storage;
|
||||
let mut tmpdir = tmpdir.as_ref();
|
||||
if !tmpdir.is_absolute() {
|
||||
let cur_dir = try!(env::current_dir());
|
||||
storage = cur_dir.join(tmpdir);
|
||||
tmpdir = &storage;
|
||||
// return TempDir::new_in(&cur_dir.join(tmpdir), prefix);
|
||||
}
|
||||
|
||||
let mut rng = thread_rng();
|
||||
for _ in 0..NUM_RETRIES {
|
||||
let suffix: String = rng.gen_ascii_chars().take(NUM_RAND_CHARS).collect();
|
||||
let leaf = if prefix.len() > 0 {
|
||||
format!("{}.{}", prefix, suffix)
|
||||
} else {
|
||||
// If we're given an empty string for a prefix, then creating a
|
||||
// directory starting with "." would lead to it being
|
||||
// semi-invisible on some systems.
|
||||
suffix
|
||||
};
|
||||
let path = tmpdir.join(&leaf);
|
||||
match fs::create_dir(&path) {
|
||||
Ok(_) => return Ok(TempDir { path: Some(path) }),
|
||||
Err(ref e) if e.kind() == ErrorKind::AlreadyExists => {}
|
||||
Err(e) => return Err(e)
|
||||
}
|
||||
}
|
||||
|
||||
Err(Error::new(ErrorKind::AlreadyExists,
|
||||
"too many temporary directories already exist",
|
||||
None))
|
||||
}
|
||||
|
||||
/// Attempts to make a temporary directory inside of `env::temp_dir()` whose
|
||||
/// name will have the prefix `prefix`. The directory will be automatically
|
||||
/// deleted once the returned wrapper is destroyed.
|
||||
///
|
||||
/// If no directory can be created, `Err` is returned.
|
||||
#[allow(deprecated)]
|
||||
pub fn new(prefix: &str) -> io::Result<TempDir> {
|
||||
TempDir::new_in(&env::temp_dir(), prefix)
|
||||
}
|
||||
|
||||
/// Unwrap the wrapped `std::path::Path` from the `TempDir` wrapper.
|
||||
/// This discards the wrapper so that the automatic deletion of the
|
||||
/// temporary directory is prevented.
|
||||
pub fn into_path(mut self) -> PathBuf {
|
||||
self.path.take().unwrap()
|
||||
}
|
||||
|
||||
/// Access the wrapped `std::path::Path` to the temporary directory.
|
||||
pub fn path(&self) -> &path::Path {
|
||||
self.path.as_ref().unwrap()
|
||||
}
|
||||
|
||||
/// Close and remove the temporary directory
|
||||
///
|
||||
/// Although `TempDir` removes the directory on drop, in the destructor
|
||||
/// any errors are ignored. To detect errors cleaning up the temporary
|
||||
/// directory, call `close` instead.
|
||||
pub fn close(mut self) -> io::Result<()> {
|
||||
self.cleanup_dir()
|
||||
}
|
||||
|
||||
fn cleanup_dir(&mut self) -> io::Result<()> {
|
||||
match self.path {
|
||||
Some(ref p) => fs::remove_dir_all(p),
|
||||
None => Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TempDir {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.cleanup_dir();
|
||||
}
|
||||
}
|
||||
|
||||
// the tests for this module need to change the path using change_dir,
|
||||
// and this doesn't play nicely with other tests so these unit tests are located
|
||||
// in src/test/run-pass/tempfile.rs
|
|
@ -288,12 +288,12 @@ mod tests {
|
|||
assert_eq!(reader.read(&mut buf), Ok(1));
|
||||
assert_eq!(reader.len(), 7);
|
||||
let b: &[_] = &[0];
|
||||
assert_eq!(buf, b);
|
||||
assert_eq!(&buf[..], b);
|
||||
let mut buf = [0; 4];
|
||||
assert_eq!(reader.read(&mut buf), Ok(4));
|
||||
assert_eq!(reader.len(), 3);
|
||||
let b: &[_] = &[1, 2, 3, 4];
|
||||
assert_eq!(buf, b);
|
||||
assert_eq!(&buf[..], b);
|
||||
assert_eq!(reader.read(&mut buf), Ok(3));
|
||||
let b: &[_] = &[5, 6, 7];
|
||||
assert_eq!(&buf[..3], b);
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
// except according to those terms.
|
||||
|
||||
use boxed::Box;
|
||||
use clone::Clone;
|
||||
use error;
|
||||
use fmt;
|
||||
use option::Option::{self, Some, None};
|
||||
|
@ -179,27 +178,6 @@ impl Error {
|
|||
Repr::Custom(ref c) => c.kind,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a short description for this error message
|
||||
#[unstable(feature = "io")]
|
||||
#[deprecated(since = "1.0.0", reason = "use the Error trait's description \
|
||||
method instead")]
|
||||
pub fn description(&self) -> &str {
|
||||
match self.repr {
|
||||
Repr::Os(..) => "os error",
|
||||
Repr::Custom(ref c) => c.desc,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a detailed error message for this error (if one is available)
|
||||
#[unstable(feature = "io")]
|
||||
#[deprecated(since = "1.0.0", reason = "use the to_string() method instead")]
|
||||
pub fn detail(&self) -> Option<String> {
|
||||
match self.repr {
|
||||
Repr::Os(code) => Some(sys::os::error_string(code)),
|
||||
Repr::Custom(ref s) => s.detail.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
|
|
@ -172,8 +172,6 @@ pub use core::clone;
|
|||
#[cfg(not(test))] pub use core::cmp;
|
||||
pub use core::convert;
|
||||
pub use core::default;
|
||||
#[allow(deprecated)]
|
||||
pub use core::finally;
|
||||
pub use core::hash;
|
||||
pub use core::intrinsics;
|
||||
pub use core::iter;
|
||||
|
|
|
@ -100,13 +100,6 @@ impl TcpStream {
|
|||
self.0.peer_addr()
|
||||
}
|
||||
|
||||
/// Returns the socket address of the local half of this TCP connection.
|
||||
#[unstable(feature = "net")]
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to local_addr")]
|
||||
pub fn socket_addr(&self) -> io::Result<SocketAddr> {
|
||||
self.0.socket_addr()
|
||||
}
|
||||
|
||||
/// Returns the socket address of the local half of this TCP connection.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn local_addr(&self) -> io::Result<SocketAddr> {
|
||||
|
@ -199,13 +192,6 @@ impl TcpListener {
|
|||
self.0.socket_addr()
|
||||
}
|
||||
|
||||
/// Deprecated, renamed to local_addr
|
||||
#[unstable(feature = "net")]
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to local_addr")]
|
||||
pub fn socket_addr(&self) -> io::Result<SocketAddr> {
|
||||
self.0.socket_addr()
|
||||
}
|
||||
|
||||
/// Create a new independently owned handle to the underlying socket.
|
||||
///
|
||||
/// The returned `TcpListener` is a reference to the same socket that this
|
||||
|
@ -359,7 +345,7 @@ mod tests {
|
|||
let _t = thread::spawn(move|| {
|
||||
let mut stream = t!(TcpStream::connect(&addr));
|
||||
t!(stream.write(&[99]));
|
||||
tx.send(t!(stream.socket_addr())).unwrap();
|
||||
tx.send(t!(stream.local_addr())).unwrap();
|
||||
});
|
||||
|
||||
let (mut stream, addr) = t!(acceptor.accept());
|
||||
|
@ -509,7 +495,7 @@ mod tests {
|
|||
fn socket_and_peer_name_ip4() {
|
||||
each_ip(&mut |addr| {
|
||||
let listener = t!(TcpListener::bind(&addr));
|
||||
let so_name = t!(listener.socket_addr());
|
||||
let so_name = t!(listener.local_addr());
|
||||
assert_eq!(addr, so_name);
|
||||
let _t = thread::spawn(move|| {
|
||||
t!(listener.accept());
|
||||
|
|
|
@ -80,13 +80,6 @@ impl UdpSocket {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the socket address that this socket was created from.
|
||||
#[unstable(feature = "net")]
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to local_addr")]
|
||||
pub fn socket_addr(&self) -> io::Result<SocketAddr> {
|
||||
self.0.socket_addr()
|
||||
}
|
||||
|
||||
/// Returns the socket address that this socket was created from.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn local_addr(&self) -> io::Result<SocketAddr> {
|
||||
|
@ -207,7 +200,7 @@ mod tests {
|
|||
fn socket_name_ip4() {
|
||||
each_ip(&mut |addr, _| {
|
||||
let server = t!(UdpSocket::bind(&addr));
|
||||
assert_eq!(addr, t!(server.socket_addr()));
|
||||
assert_eq!(addr, t!(server.local_addr()));
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -951,7 +951,8 @@ mod test {
|
|||
pub fn tmpdir() -> TempDir {
|
||||
use os;
|
||||
use rand;
|
||||
let ret = os::tmpdir().join(format!("rust-{}", rand::random::<u32>()));
|
||||
let temp = Path::new(::env::temp_dir().to_str().unwrap());
|
||||
let ret = temp.join(format!("rust-{}", rand::random::<u32>()));
|
||||
check!(old_io::fs::mkdir(&ret, old_io::USER_RWX));
|
||||
TempDir(ret)
|
||||
}
|
||||
|
|
|
@ -399,7 +399,7 @@ impl<'a> Buffer for BufReader<'a> {
|
|||
mod test {
|
||||
extern crate test as test_crate;
|
||||
use old_io::{SeekSet, SeekCur, SeekEnd, Reader, Writer, Seek, Buffer};
|
||||
use prelude::v1::{Ok, Err, Vec, AsSlice};
|
||||
use prelude::v1::{Ok, Err, Vec};
|
||||
use prelude::v1::Iterator;
|
||||
use old_io;
|
||||
use iter::repeat;
|
||||
|
|
|
@ -274,7 +274,7 @@ use mem::transmute;
|
|||
use ops::FnOnce;
|
||||
use option::Option;
|
||||
use option::Option::{Some, None};
|
||||
use os;
|
||||
use sys::os;
|
||||
use boxed::Box;
|
||||
use result::Result;
|
||||
use result::Result::{Ok, Err};
|
||||
|
|
|
@ -124,9 +124,9 @@ mod test {
|
|||
use os;
|
||||
use old_io::pipe::PipeStream;
|
||||
|
||||
let os::Pipe { reader, writer } = unsafe { os::pipe().unwrap() };
|
||||
let out = PipeStream::open(writer);
|
||||
let mut input = PipeStream::open(reader);
|
||||
let (reader, writer) = unsafe { ::sys::os::pipe().unwrap() };
|
||||
let out = PipeStream::open(writer.unwrap());
|
||||
let mut input = PipeStream::open(reader.unwrap());
|
||||
let (tx, rx) = channel();
|
||||
let _t = thread::spawn(move|| {
|
||||
let mut out = out;
|
||||
|
|
|
@ -246,7 +246,7 @@ impl Command {
|
|||
None => {
|
||||
// if the env is currently just inheriting from the parent's,
|
||||
// materialize the parent's env into a hashtable.
|
||||
self.env = Some(os::env_as_bytes().into_iter().map(|(k, v)| {
|
||||
self.env = Some(::env::vars().map(|(k, v)| {
|
||||
(EnvKey(CString::new(k).unwrap()),
|
||||
CString::new(v).unwrap())
|
||||
}).collect());
|
||||
|
@ -764,11 +764,9 @@ impl Drop for Process {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use prelude::v1::*;
|
||||
use old_io::{Truncate, Write, TimedOut, timer, process, FileNotFound};
|
||||
use old_io::{Reader, Writer};
|
||||
use prelude::v1::{Ok, Err, drop, Some, None, Vec};
|
||||
use prelude::v1::{String, Clone};
|
||||
use prelude::v1::{Str, AsSlice, ToString};
|
||||
use old_path::{GenericPath, Path};
|
||||
use old_io::fs::PathExtensions;
|
||||
use old_io::timer::*;
|
||||
|
@ -1003,7 +1001,7 @@ mod tests {
|
|||
let prog = pwd_cmd().spawn().unwrap();
|
||||
|
||||
let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap();
|
||||
let parent_dir = os::getcwd().unwrap();
|
||||
let parent_dir = Path::new(::env::current_dir().unwrap().to_str().unwrap());
|
||||
let child_dir = Path::new(output.trim());
|
||||
|
||||
let parent_stat = parent_dir.stat().unwrap();
|
||||
|
@ -1018,7 +1016,7 @@ mod tests {
|
|||
use os;
|
||||
// test changing to the parent of os::getcwd() because we know
|
||||
// the path exists (and os::getcwd() is not expected to be root)
|
||||
let parent_dir = os::getcwd().unwrap().dir_path();
|
||||
let parent_dir = Path::new(::env::current_dir().unwrap().to_str().unwrap());
|
||||
let prog = pwd_cmd().cwd(&parent_dir).spawn().unwrap();
|
||||
|
||||
let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap();
|
||||
|
@ -1058,11 +1056,11 @@ mod tests {
|
|||
let prog = env_cmd().spawn().unwrap();
|
||||
let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap();
|
||||
|
||||
let r = os::env();
|
||||
for &(ref k, ref v) in &r {
|
||||
let r = ::env::vars();
|
||||
for (k, v) in r {
|
||||
// don't check windows magical empty-named variables
|
||||
assert!(k.is_empty() ||
|
||||
output.contains(&format!("{}={}", *k, *v)),
|
||||
output.contains(&format!("{}={}", k, v)),
|
||||
"output doesn't contain `{}={}`\n{}",
|
||||
k, v, output);
|
||||
}
|
||||
|
@ -1076,16 +1074,12 @@ mod tests {
|
|||
let mut prog = env_cmd().spawn().unwrap();
|
||||
let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap();
|
||||
|
||||
let r = os::env();
|
||||
for &(ref k, ref v) in &r {
|
||||
let r = env::vars();
|
||||
for (k, v) in r {
|
||||
// don't check android RANDOM variables
|
||||
if *k != "RANDOM".to_string() {
|
||||
assert!(output.contains(&format!("{}={}",
|
||||
*k,
|
||||
*v)) ||
|
||||
output.contains(&format!("{}=\'{}\'",
|
||||
*k,
|
||||
*v)));
|
||||
if k != "RANDOM".to_string() {
|
||||
assert!(output.contains(&format!("{}={}", k, v)) ||
|
||||
output.contains(&format!("{}=\'{}\'", k, v)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1100,9 +1094,9 @@ mod tests {
|
|||
// PATH to our sub-process.
|
||||
let path_val: String;
|
||||
let mut new_env = vec![("RUN_TEST_NEW_ENV", "123")];
|
||||
match os::getenv("PATH") {
|
||||
None => {}
|
||||
Some(val) => {
|
||||
match ::env::var("PATH") {
|
||||
Err(..) => {}
|
||||
Ok(val) => {
|
||||
path_val = val;
|
||||
new_env.push(("PATH", &path_val))
|
||||
}
|
||||
|
|
|
@ -100,7 +100,8 @@ impl TempDir {
|
|||
#[allow(deprecated)]
|
||||
pub fn new_in(tmpdir: &Path, prefix: &str) -> IoResult<TempDir> {
|
||||
if !tmpdir.is_absolute() {
|
||||
let cur_dir = try!(::os::getcwd());
|
||||
let cur_dir = ::env::current_dir().unwrap();
|
||||
let cur_dir = Path::new(cur_dir.to_str().unwrap());
|
||||
return TempDir::new_in(&cur_dir.join(tmpdir), prefix);
|
||||
}
|
||||
|
||||
|
@ -136,7 +137,8 @@ impl TempDir {
|
|||
/// If no directory can be created, `Err` is returned.
|
||||
#[allow(deprecated)]
|
||||
pub fn new(prefix: &str) -> IoResult<TempDir> {
|
||||
TempDir::new_in(&::os::tmpdir(), prefix)
|
||||
let tmp = Path::new(::env::temp_dir().to_str().unwrap());
|
||||
TempDir::new_in(&tmp, prefix)
|
||||
}
|
||||
|
||||
/// Unwrap the wrapped `std::path::Path` from the `TempDir` wrapper.
|
||||
|
|
|
@ -43,7 +43,7 @@ fn next_test_unix_socket() -> String {
|
|||
pub fn next_test_unix() -> Path {
|
||||
let string = next_test_unix_socket();
|
||||
if cfg!(unix) {
|
||||
::os::tmpdir().join(string)
|
||||
Path::new(::env::temp_dir().to_str().unwrap()).join(string)
|
||||
} else {
|
||||
Path::new(format!("{}{}", r"\\.\pipe\", string))
|
||||
}
|
||||
|
|
|
@ -69,12 +69,13 @@
|
|||
use core::marker::Sized;
|
||||
use ffi::CString;
|
||||
use clone::Clone;
|
||||
use borrow::Cow;
|
||||
use fmt;
|
||||
use iter::Iterator;
|
||||
use option::Option;
|
||||
use option::Option::{None, Some};
|
||||
use str;
|
||||
use string::{String, CowString};
|
||||
use string::String;
|
||||
use vec::Vec;
|
||||
|
||||
/// Typedef for POSIX file paths.
|
||||
|
@ -907,7 +908,7 @@ impl<'a, P: GenericPath> Display<'a, P> {
|
|||
/// If the path is not UTF-8, invalid sequences will be replaced with the
|
||||
/// Unicode replacement char. This involves allocation.
|
||||
#[inline]
|
||||
pub fn as_cow(&self) -> CowString<'a> {
|
||||
pub fn as_cow(&self) -> Cow<'a, str> {
|
||||
String::from_utf8_lossy(if self.filename {
|
||||
match self.path.filename() {
|
||||
None => {
|
||||
|
|
|
@ -20,7 +20,7 @@ use iter::{Iterator, Map};
|
|||
use marker::Sized;
|
||||
use option::Option::{self, Some, None};
|
||||
use result::Result::{self, Ok, Err};
|
||||
use slice::{AsSlice, Split, SliceConcatExt};
|
||||
use slice::{Split, SliceConcatExt};
|
||||
use str::{self, FromStr};
|
||||
use vec::Vec;
|
||||
|
||||
|
@ -339,11 +339,11 @@ impl Path {
|
|||
|
||||
/// Returns a normalized byte vector representation of a path, by removing all empty
|
||||
/// components, and unnecessary . and .. components.
|
||||
fn normalize<V: ?Sized + AsSlice<u8>>(v: &V) -> Vec<u8> {
|
||||
fn normalize(v: &[u8]) -> Vec<u8> {
|
||||
// borrowck is being very picky
|
||||
let val = {
|
||||
let is_abs = !v.as_slice().is_empty() && v.as_slice()[0] == SEP_BYTE;
|
||||
let v_ = if is_abs { &v.as_slice()[1..] } else { v.as_slice() };
|
||||
let is_abs = !v.is_empty() && v[0] == SEP_BYTE;
|
||||
let v_ = if is_abs { &v[1..] } else { v };
|
||||
let comps = normalize_helper(v_, is_abs);
|
||||
match comps {
|
||||
None => None,
|
||||
|
@ -371,7 +371,7 @@ impl Path {
|
|||
}
|
||||
};
|
||||
match val {
|
||||
None => v.as_slice().to_vec(),
|
||||
None => v.to_vec(),
|
||||
Some(val) => val
|
||||
}
|
||||
}
|
||||
|
@ -446,8 +446,7 @@ mod tests {
|
|||
use clone::Clone;
|
||||
use option::Option::{self, Some, None};
|
||||
use old_path::GenericPath;
|
||||
use slice::AsSlice;
|
||||
use str::{self, Str};
|
||||
use str;
|
||||
use string::ToString;
|
||||
use vec::Vec;
|
||||
use iter::Iterator;
|
||||
|
|
|
@ -1129,8 +1129,6 @@ mod tests {
|
|||
use iter::Iterator;
|
||||
use option::Option::{self, Some, None};
|
||||
use old_path::GenericPath;
|
||||
use slice::AsSlice;
|
||||
use str::Str;
|
||||
use string::ToString;
|
||||
use vec::Vec;
|
||||
|
||||
|
|
1821
src/libstd/os.rs
1821
src/libstd/os.rs
File diff suppressed because it is too large
Load Diff
|
@ -1321,7 +1321,7 @@ impl Path {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn file_name(&self) -> Option<&OsStr> {
|
||||
self.components().next_back().and_then(|p| match p {
|
||||
Component::Normal(p) => Some(p.as_os_str()),
|
||||
Component::Normal(p) => Some(p.as_ref()),
|
||||
_ => None
|
||||
})
|
||||
}
|
||||
|
|
|
@ -42,12 +42,11 @@
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[doc(no_inline)] pub use result::Result::{self, Ok, Err};
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(deprecated)]
|
||||
#[doc(no_inline)] pub use slice::{SliceConcatExt, AsSlice};
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(deprecated)]
|
||||
#[doc(no_inline)] pub use str::Str;
|
||||
#[doc(no_inline)] pub use slice::SliceConcatExt;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[doc(no_inline)] pub use string::{String, ToString};
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[doc(no_inline)] pub use vec::Vec;
|
||||
|
||||
#[allow(deprecated)] pub use slice::AsSlice;
|
||||
#[allow(deprecated)] pub use str::Str;
|
||||
|
|
|
@ -16,15 +16,15 @@
|
|||
use prelude::v1::*;
|
||||
use io::prelude::*;
|
||||
|
||||
use ffi::AsOsStr;
|
||||
use ffi::OsStr;
|
||||
use fmt;
|
||||
use io::{self, Error, ErrorKind};
|
||||
use libc;
|
||||
use path;
|
||||
use sync::mpsc::{channel, Receiver};
|
||||
use sys::pipe2::{self, AnonPipe};
|
||||
use sys::process2::Process as ProcessImp;
|
||||
use sys::process2::Command as CommandImp;
|
||||
use sys::process2::Process as ProcessImp;
|
||||
use sys::process2::ExitStatus as ExitStatusImp;
|
||||
use sys_common::{AsInner, AsInnerMut};
|
||||
use thread;
|
||||
|
@ -147,9 +147,9 @@ impl Command {
|
|||
/// Builder methods are provided to change these defaults and
|
||||
/// otherwise configure the process.
|
||||
#[stable(feature = "process", since = "1.0.0")]
|
||||
pub fn new<S: AsOsStr>(program: S) -> Command {
|
||||
pub fn new<S: AsRef<OsStr>>(program: S) -> Command {
|
||||
Command {
|
||||
inner: CommandImp::new(program.as_os_str()),
|
||||
inner: CommandImp::new(program.as_ref()),
|
||||
stdin: None,
|
||||
stdout: None,
|
||||
stderr: None,
|
||||
|
@ -158,15 +158,15 @@ impl Command {
|
|||
|
||||
/// Add an argument to pass to the program.
|
||||
#[stable(feature = "process", since = "1.0.0")]
|
||||
pub fn arg<S: AsOsStr>(&mut self, arg: S) -> &mut Command {
|
||||
self.inner.arg(arg.as_os_str());
|
||||
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Command {
|
||||
self.inner.arg(arg.as_ref());
|
||||
self
|
||||
}
|
||||
|
||||
/// Add multiple arguments to pass to the program.
|
||||
#[stable(feature = "process", since = "1.0.0")]
|
||||
pub fn args<S: AsOsStr>(&mut self, args: &[S]) -> &mut Command {
|
||||
self.inner.args(args.iter().map(AsOsStr::as_os_str));
|
||||
pub fn args<S: AsRef<OsStr>>(&mut self, args: &[S]) -> &mut Command {
|
||||
self.inner.args(args.iter().map(AsRef::as_ref));
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -176,16 +176,16 @@ impl Command {
|
|||
/// and case-sensitive on all other platforms.
|
||||
#[stable(feature = "process", since = "1.0.0")]
|
||||
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Command
|
||||
where K: AsOsStr, V: AsOsStr
|
||||
where K: AsRef<OsStr>, V: AsRef<OsStr>
|
||||
{
|
||||
self.inner.env(key.as_os_str(), val.as_os_str());
|
||||
self.inner.env(key.as_ref(), val.as_ref());
|
||||
self
|
||||
}
|
||||
|
||||
/// Removes an environment variable mapping.
|
||||
#[stable(feature = "process", since = "1.0.0")]
|
||||
pub fn env_remove<K: AsOsStr>(&mut self, key: K) -> &mut Command {
|
||||
self.inner.env_remove(key.as_os_str());
|
||||
pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Command {
|
||||
self.inner.env_remove(key.as_ref());
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ impl Command {
|
|||
/// Set the working directory for the child process.
|
||||
#[stable(feature = "process", since = "1.0.0")]
|
||||
pub fn current_dir<P: AsRef<path::Path>>(&mut self, dir: P) -> &mut Command {
|
||||
self.inner.cwd(dir.as_ref().as_os_str());
|
||||
self.inner.cwd(dir.as_ref().as_ref());
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -378,11 +378,6 @@ enum StdioImp {
|
|||
}
|
||||
|
||||
impl Stdio {
|
||||
/// A new pipe should be arranged to connect the parent and child processes.
|
||||
#[unstable(feature = "process_capture")]
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to `Stdio::piped`")]
|
||||
pub fn capture() -> Stdio { Stdio::piped() }
|
||||
|
||||
/// A new pipe should be arranged to connect the parent and child processes.
|
||||
#[stable(feature = "process", since = "1.0.0")]
|
||||
pub fn piped() -> Stdio { Stdio(StdioImp::Piped) }
|
||||
|
@ -529,11 +524,10 @@ impl Child {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use io::ErrorKind;
|
||||
use prelude::v1::*;
|
||||
use io::prelude::*;
|
||||
use prelude::v1::{Ok, Err, drop, Some, Vec};
|
||||
use prelude::v1::{String, Clone};
|
||||
use prelude::v1::{Str, AsSlice, ToString};
|
||||
|
||||
use io::ErrorKind;
|
||||
use old_path::{self, GenericPath};
|
||||
use old_io::fs::PathExtensions;
|
||||
use rt::running_on_valgrind;
|
||||
|
@ -678,7 +672,7 @@ mod tests {
|
|||
fn test_process_output_output() {
|
||||
let Output {status, stdout, stderr}
|
||||
= Command::new("echo").arg("hello").output().unwrap();
|
||||
let output_str = str::from_utf8(&stdout[..]).unwrap();
|
||||
let output_str = str::from_utf8(&stdout).unwrap();
|
||||
|
||||
assert!(status.success());
|
||||
assert_eq!(output_str.trim().to_string(), "hello");
|
||||
|
@ -720,7 +714,7 @@ mod tests {
|
|||
let prog = Command::new("echo").arg("hello").stdout(Stdio::piped())
|
||||
.spawn().unwrap();
|
||||
let Output {status, stdout, stderr} = prog.wait_with_output().unwrap();
|
||||
let output_str = str::from_utf8(&stdout[..]).unwrap();
|
||||
let output_str = str::from_utf8(&stdout).unwrap();
|
||||
|
||||
assert!(status.success());
|
||||
assert_eq!(output_str.trim().to_string(), "hello");
|
||||
|
@ -755,7 +749,8 @@ mod tests {
|
|||
let prog = pwd_cmd().spawn().unwrap();
|
||||
|
||||
let output = String::from_utf8(prog.wait_with_output().unwrap().stdout).unwrap();
|
||||
let parent_dir = os::getcwd().unwrap();
|
||||
let parent_dir = ::env::current_dir().unwrap().to_str().unwrap().to_string();
|
||||
let parent_dir = old_path::Path::new(parent_dir);
|
||||
let child_dir = old_path::Path::new(output.trim());
|
||||
|
||||
let parent_stat = parent_dir.stat().unwrap();
|
||||
|
@ -770,7 +765,8 @@ mod tests {
|
|||
use os;
|
||||
// test changing to the parent of os::getcwd() because we know
|
||||
// the path exists (and os::getcwd() is not expected to be root)
|
||||
let parent_dir = os::getcwd().unwrap().dir_path();
|
||||
let parent_dir = ::env::current_dir().unwrap().to_str().unwrap().to_string();
|
||||
let parent_dir = old_path::Path::new(parent_dir).dir_path();
|
||||
let result = pwd_cmd().current_dir(parent_dir.as_str().unwrap()).output().unwrap();
|
||||
|
||||
let output = String::from_utf8(result.stdout).unwrap();
|
||||
|
@ -855,7 +851,7 @@ mod tests {
|
|||
cmd.env("PATH", &p);
|
||||
}
|
||||
let result = cmd.output().unwrap();
|
||||
let output = String::from_utf8_lossy(&result.stdout[..]).to_string();
|
||||
let output = String::from_utf8_lossy(&result.stdout).to_string();
|
||||
|
||||
assert!(output.contains("RUN_TEST_NEW_ENV=123"),
|
||||
"didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output);
|
||||
|
@ -864,7 +860,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_add_to_env() {
|
||||
let result = env_cmd().env("RUN_TEST_NEW_ENV", "123").output().unwrap();
|
||||
let output = String::from_utf8_lossy(&result.stdout[..]).to_string();
|
||||
let output = String::from_utf8_lossy(&result.stdout).to_string();
|
||||
|
||||
assert!(output.contains("RUN_TEST_NEW_ENV=123"),
|
||||
"didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output);
|
||||
|
|
|
@ -15,17 +15,16 @@ pub use self::imp::OsRng;
|
|||
|
||||
#[cfg(all(unix, not(target_os = "ios")))]
|
||||
mod imp {
|
||||
extern crate libc;
|
||||
|
||||
use prelude::v1::*;
|
||||
use self::OsRngInner::*;
|
||||
|
||||
use libc;
|
||||
use mem;
|
||||
use old_io::{IoResult, File};
|
||||
use old_path::Path;
|
||||
use rand::Rng;
|
||||
use rand::reader::ReaderRng;
|
||||
use result::Result::Ok;
|
||||
use mem;
|
||||
use os::errno;
|
||||
use sys::os::errno;
|
||||
|
||||
#[cfg(all(target_os = "linux",
|
||||
any(target_arch = "x86_64",
|
||||
|
@ -184,14 +183,13 @@ mod imp {
|
|||
|
||||
#[cfg(target_os = "ios")]
|
||||
mod imp {
|
||||
extern crate libc;
|
||||
use prelude::v1::*;
|
||||
|
||||
use old_io::{IoResult};
|
||||
use old_io::IoResult;
|
||||
use mem;
|
||||
use os;
|
||||
use rand::Rng;
|
||||
use result::Result::{Ok};
|
||||
use self::libc::{c_int, size_t};
|
||||
use libc::{c_int, size_t};
|
||||
|
||||
/// A random number generator that retrieves randomness straight from
|
||||
/// the operating system. Platform sources:
|
||||
|
@ -251,16 +249,15 @@ mod imp {
|
|||
|
||||
#[cfg(windows)]
|
||||
mod imp {
|
||||
extern crate libc;
|
||||
use prelude::v1::*;
|
||||
|
||||
use old_io::{IoResult, IoError};
|
||||
use io;
|
||||
use mem;
|
||||
use ops::Drop;
|
||||
use old_io::{IoResult, IoError};
|
||||
use os;
|
||||
use rand::Rng;
|
||||
use result::Result::{Ok, Err};
|
||||
use self::libc::{DWORD, BYTE, LPCSTR, BOOL};
|
||||
use self::libc::types::os::arch::extra::{LONG_PTR};
|
||||
use libc::types::os::arch::extra::{LONG_PTR};
|
||||
use libc::{DWORD, BYTE, LPCSTR, BOOL};
|
||||
|
||||
type HCRYPTPROV = LONG_PTR;
|
||||
|
||||
|
@ -330,7 +327,8 @@ mod imp {
|
|||
v.as_mut_ptr())
|
||||
};
|
||||
if ret == 0 {
|
||||
panic!("couldn't generate random bytes: {}", os::last_os_error());
|
||||
panic!("couldn't generate random bytes: {}",
|
||||
io::Error::last_os_error());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -341,7 +339,8 @@ mod imp {
|
|||
CryptReleaseContext(self.hcryptprov, 0)
|
||||
};
|
||||
if ret == 0 {
|
||||
panic!("couldn't release context: {}", os::last_os_error());
|
||||
panic!("couldn't release context: {}",
|
||||
io::Error::last_os_error());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,6 @@ mod imp {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use prelude::v1::*;
|
||||
use finally::Finally;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -127,14 +126,11 @@ mod imp {
|
|||
assert!(take() == Some(expected.clone()));
|
||||
assert!(take() == None);
|
||||
|
||||
(|| {
|
||||
}).finally(|| {
|
||||
// Restore the actual global state.
|
||||
match saved_value {
|
||||
Some(ref args) => put(args.clone()),
|
||||
None => ()
|
||||
}
|
||||
})
|
||||
// Restore the actual global state.
|
||||
match saved_value {
|
||||
Some(ref args) => put(args.clone()),
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,8 +31,6 @@ pub use self::barrier::{Barrier, BarrierWaitResult};
|
|||
pub use self::poison::{PoisonError, TryLockError, TryLockResult, LockResult};
|
||||
|
||||
pub use self::future::Future;
|
||||
#[allow(deprecated)]
|
||||
pub use self::task_pool::TaskPool;
|
||||
|
||||
pub mod mpsc;
|
||||
|
||||
|
@ -44,4 +42,3 @@ mod once;
|
|||
mod poison;
|
||||
mod rwlock;
|
||||
mod semaphore;
|
||||
mod task_pool;
|
||||
|
|
|
@ -122,12 +122,6 @@ impl<T> PoisonError<T> {
|
|||
PoisonError { guard: guard }
|
||||
}
|
||||
|
||||
/// Consumes this error indicating that a lock is poisoned, returning the
|
||||
/// underlying guard to allow access regardless.
|
||||
#[unstable(feature = "std_misc")]
|
||||
#[deprecated(since = "1.0.0", reason = "renamed to into_inner")]
|
||||
pub fn into_guard(self) -> T { self.guard }
|
||||
|
||||
/// Consumes this error indicating that a lock is poisoned, returning the
|
||||
/// underlying guard to allow access regardless.
|
||||
#[unstable(feature = "std_misc")]
|
||||
|
|
|
@ -1,217 +0,0 @@
|
|||
// Copyright 2014 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.
|
||||
|
||||
//! Abstraction of a thread pool for basic parallelism.
|
||||
|
||||
#![deprecated(since = "1.0.0",
|
||||
reason = "This kind of API needs some time to bake in \
|
||||
crates.io. This functionality is available through \
|
||||
https://crates.io/crates/threadpool")]
|
||||
#![unstable(feature = "std_misc")]
|
||||
|
||||
#![allow(deprecated)]
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
use sync::{Arc, Mutex};
|
||||
use sync::mpsc::{channel, Sender, Receiver};
|
||||
use thread;
|
||||
use thunk::Thunk;
|
||||
|
||||
struct Sentinel<'a> {
|
||||
jobs: &'a Arc<Mutex<Receiver<Thunk<'static>>>>,
|
||||
active: bool
|
||||
}
|
||||
|
||||
impl<'a> Sentinel<'a> {
|
||||
fn new(jobs: &'a Arc<Mutex<Receiver<Thunk<'static>>>>) -> Sentinel<'a> {
|
||||
Sentinel {
|
||||
jobs: jobs,
|
||||
active: true
|
||||
}
|
||||
}
|
||||
|
||||
// Cancel and destroy this sentinel.
|
||||
fn cancel(mut self) {
|
||||
self.active = false;
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe_destructor]
|
||||
impl<'a> Drop for Sentinel<'a> {
|
||||
fn drop(&mut self) {
|
||||
if self.active {
|
||||
spawn_in_pool(self.jobs.clone())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A thread pool used to execute functions in parallel.
|
||||
///
|
||||
/// Spawns `n` worker threads and replenishes the pool if any worker threads
|
||||
/// panic.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # #![feature(std_misc, core)]
|
||||
/// use std::sync::TaskPool;
|
||||
/// use std::iter::AdditiveIterator;
|
||||
/// use std::sync::mpsc::channel;
|
||||
///
|
||||
/// let pool = TaskPool::new(4);
|
||||
///
|
||||
/// let (tx, rx) = channel();
|
||||
/// for _ in 0..8 {
|
||||
/// let tx = tx.clone();
|
||||
/// pool.execute(move|| {
|
||||
/// tx.send(1_u32).unwrap();
|
||||
/// });
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(rx.iter().take(8).sum(), 8);
|
||||
/// ```
|
||||
pub struct TaskPool {
|
||||
// How the threadpool communicates with subthreads.
|
||||
//
|
||||
// This is the only such Sender, so when it is dropped all subthreads will
|
||||
// quit.
|
||||
jobs: Sender<Thunk<'static>>
|
||||
}
|
||||
|
||||
impl TaskPool {
|
||||
/// Spawns a new thread pool with `threads` threads.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic if `threads` is 0.
|
||||
pub fn new(threads: usize) -> TaskPool {
|
||||
assert!(threads >= 1);
|
||||
|
||||
let (tx, rx) = channel::<Thunk>();
|
||||
let rx = Arc::new(Mutex::new(rx));
|
||||
|
||||
// Threadpool threads
|
||||
for _ in 0..threads {
|
||||
spawn_in_pool(rx.clone());
|
||||
}
|
||||
|
||||
TaskPool { jobs: tx }
|
||||
}
|
||||
|
||||
/// Executes the function `job` on a thread in the pool.
|
||||
pub fn execute<F>(&self, job: F)
|
||||
where F : FnOnce(), F : Send + 'static
|
||||
{
|
||||
self.jobs.send(Thunk::new(job)).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_in_pool(jobs: Arc<Mutex<Receiver<Thunk<'static>>>>) {
|
||||
thread::spawn(move || {
|
||||
// Will spawn a new thread on panic unless it is cancelled.
|
||||
let sentinel = Sentinel::new(&jobs);
|
||||
|
||||
loop {
|
||||
let message = {
|
||||
// Only lock jobs for the time it takes
|
||||
// to get a job, not run it.
|
||||
let lock = jobs.lock().unwrap();
|
||||
lock.recv()
|
||||
};
|
||||
|
||||
match message {
|
||||
Ok(job) => job.invoke(()),
|
||||
|
||||
// The Taskpool was dropped.
|
||||
Err(..) => break
|
||||
}
|
||||
}
|
||||
|
||||
sentinel.cancel();
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use prelude::v1::*;
|
||||
use super::*;
|
||||
use sync::mpsc::channel;
|
||||
|
||||
const TEST_TASKS: usize = 4;
|
||||
|
||||
#[test]
|
||||
fn test_works() {
|
||||
use iter::AdditiveIterator;
|
||||
|
||||
let pool = TaskPool::new(TEST_TASKS);
|
||||
|
||||
let (tx, rx) = channel();
|
||||
for _ in 0..TEST_TASKS {
|
||||
let tx = tx.clone();
|
||||
pool.execute(move|| {
|
||||
tx.send(1).unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
assert_eq!(rx.iter().take(TEST_TASKS).sum(), TEST_TASKS);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_zero_tasks_panic() {
|
||||
TaskPool::new(0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_recovery_from_subtask_panic() {
|
||||
use iter::AdditiveIterator;
|
||||
|
||||
let pool = TaskPool::new(TEST_TASKS);
|
||||
|
||||
// Panic all the existing threads.
|
||||
for _ in 0..TEST_TASKS {
|
||||
pool.execute(move|| -> () { panic!() });
|
||||
}
|
||||
|
||||
// Ensure new threads were spawned to compensate.
|
||||
let (tx, rx) = channel();
|
||||
for _ in 0..TEST_TASKS {
|
||||
let tx = tx.clone();
|
||||
pool.execute(move|| {
|
||||
tx.send(1).unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
assert_eq!(rx.iter().take(TEST_TASKS).sum(), TEST_TASKS);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_should_not_panic_on_drop_if_subtasks_panic_after_drop() {
|
||||
use sync::{Arc, Barrier};
|
||||
|
||||
let pool = TaskPool::new(TEST_TASKS);
|
||||
let waiter = Arc::new(Barrier::new(TEST_TASKS + 1));
|
||||
|
||||
// Panic all the existing threads in a bit.
|
||||
for _ in 0..TEST_TASKS {
|
||||
let waiter = waiter.clone();
|
||||
pool.execute(move|| {
|
||||
waiter.wait();
|
||||
panic!();
|
||||
});
|
||||
}
|
||||
|
||||
drop(pool);
|
||||
|
||||
// Kick off the failure.
|
||||
waiter.wait();
|
||||
}
|
||||
}
|
|
@ -251,7 +251,6 @@ fn print(w: &mut Write, idx: isize, addr: *mut libc::c_void,
|
|||
fn print(w: &mut Write, idx: isize, addr: *mut libc::c_void,
|
||||
symaddr: *mut libc::c_void) -> io::Result<()> {
|
||||
use env;
|
||||
use ffi::AsOsStr;
|
||||
use os::unix::prelude::*;
|
||||
use ptr;
|
||||
|
||||
|
|
|
@ -388,9 +388,7 @@ mod tests {
|
|||
fn test_file_desc() {
|
||||
// Run this test with some pipes so we don't have to mess around with
|
||||
// opening or closing files.
|
||||
let os::Pipe { reader, writer } = unsafe { os::pipe().unwrap() };
|
||||
let mut reader = FileDesc::new(reader, true);
|
||||
let mut writer = FileDesc::new(writer, true);
|
||||
let (mut reader, mut writer) = unsafe { ::sys::os::pipe().unwrap() };
|
||||
|
||||
writer.write(b"test").unwrap();
|
||||
let mut buf = [0; 4];
|
||||
|
|
|
@ -12,7 +12,7 @@ use core::prelude::*;
|
|||
use io::prelude::*;
|
||||
use os::unix::prelude::*;
|
||||
|
||||
use ffi::{CString, CStr, OsString, AsOsStr, OsStr};
|
||||
use ffi::{CString, CStr, OsString, OsStr};
|
||||
use io::{self, Error, SeekFrom};
|
||||
use libc::{self, c_int, size_t, off_t, c_char, mode_t};
|
||||
use mem;
|
||||
|
|
|
@ -11,15 +11,15 @@
|
|||
#![allow(deprecated)]
|
||||
|
||||
use libc;
|
||||
use os;
|
||||
use sys::os;
|
||||
|
||||
use sys::fs::FileDesc;
|
||||
|
||||
pub type signal = libc::c_int;
|
||||
|
||||
pub fn new() -> (signal, signal) {
|
||||
let os::Pipe { reader, writer } = unsafe { os::pipe().unwrap() };
|
||||
(reader, writer)
|
||||
let (a, b) = unsafe { os::pipe().unwrap() };
|
||||
(a.unwrap(), b.unwrap())
|
||||
}
|
||||
|
||||
pub fn signal(fd: libc::c_int) {
|
||||
|
|
|
@ -16,7 +16,7 @@ use prelude::v1::*;
|
|||
use os::unix::prelude::*;
|
||||
|
||||
use error::Error as StdError;
|
||||
use ffi::{CString, CStr, OsString, OsStr, AsOsStr};
|
||||
use ffi::{CString, CStr, OsString, OsStr};
|
||||
use fmt;
|
||||
use io;
|
||||
use iter;
|
||||
|
@ -125,7 +125,8 @@ pub fn getcwd() -> io::Result<PathBuf> {
|
|||
}
|
||||
|
||||
pub fn chdir(p: &path::Path) -> io::Result<()> {
|
||||
let p = try!(CString::new(p.as_os_str().as_bytes()));
|
||||
let p: &OsStr = p.as_ref();
|
||||
let p = try!(CString::new(p.as_bytes()));
|
||||
unsafe {
|
||||
match libc::chdir(p.as_ptr()) == (0 as c_int) {
|
||||
true => Ok(()),
|
||||
|
@ -158,13 +159,13 @@ impl<'a> Iterator for SplitPaths<'a> {
|
|||
pub struct JoinPathsError;
|
||||
|
||||
pub fn join_paths<I, T>(paths: I) -> Result<OsString, JoinPathsError>
|
||||
where I: Iterator<Item=T>, T: AsOsStr
|
||||
where I: Iterator<Item=T>, T: AsRef<OsStr>
|
||||
{
|
||||
let mut joined = Vec::new();
|
||||
let sep = b':';
|
||||
|
||||
for (i, path) in paths.enumerate() {
|
||||
let path = path.as_os_str().as_bytes();
|
||||
let path = path.as_ref().as_bytes();
|
||||
if i > 0 { joined.push(sep) }
|
||||
if path.contains(&sep) {
|
||||
return Err(JoinPathsError)
|
||||
|
@ -464,7 +465,7 @@ pub fn page_size() -> usize {
|
|||
}
|
||||
|
||||
pub fn temp_dir() -> PathBuf {
|
||||
getenv("TMPDIR".as_os_str()).map(os2path).unwrap_or_else(|| {
|
||||
getenv("TMPDIR".as_ref()).map(os2path).unwrap_or_else(|| {
|
||||
if cfg!(target_os = "android") {
|
||||
PathBuf::from("/data/local/tmp")
|
||||
} else {
|
||||
|
@ -474,7 +475,7 @@ pub fn temp_dir() -> PathBuf {
|
|||
}
|
||||
|
||||
pub fn home_dir() -> Option<PathBuf> {
|
||||
return getenv("HOME".as_os_str()).or_else(|| unsafe {
|
||||
return getenv("HOME".as_ref()).or_else(|| unsafe {
|
||||
fallback()
|
||||
}).map(os2path);
|
||||
|
||||
|
|
|
@ -19,8 +19,9 @@ use hash::Hash;
|
|||
use old_io::process::{ProcessExit, ExitStatus, ExitSignal};
|
||||
use old_io::{IoResult, EndOfFile};
|
||||
use libc::{self, pid_t, c_void, c_int};
|
||||
use io;
|
||||
use mem;
|
||||
use os;
|
||||
use sys::os;
|
||||
use old_path::BytesContainer;
|
||||
use ptr;
|
||||
use sync::mpsc::{channel, Sender, Receiver};
|
||||
|
@ -496,7 +497,8 @@ impl Process {
|
|||
n if n > 0 => { ret = true; }
|
||||
0 => return true,
|
||||
-1 if wouldblock() => return ret,
|
||||
n => panic!("bad read {:?} ({:?})", os::last_os_error(), n),
|
||||
n => panic!("bad read {} ({})",
|
||||
io::Error::last_os_error(), n),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,8 @@ use self::Req::*;
|
|||
use old_io::IoResult;
|
||||
use libc;
|
||||
use mem;
|
||||
use os;
|
||||
use sys::os;
|
||||
use io;
|
||||
use ptr;
|
||||
use sync::atomic::{self, Ordering};
|
||||
use sync::mpsc::{channel, Sender, Receiver, TryRecvError};
|
||||
|
@ -209,7 +210,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>, _: ()) {
|
|||
|
||||
-1 if os::errno() == libc::EINTR as i32 => {}
|
||||
n => panic!("helper thread failed in select() with error: {} ({})",
|
||||
n, os::last_os_error())
|
||||
n, io::Error::last_os_error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ use prelude::v1::*;
|
|||
use os::windows::prelude::*;
|
||||
|
||||
use error::Error as StdError;
|
||||
use ffi::{OsString, OsStr, AsOsStr};
|
||||
use ffi::{OsString, OsStr};
|
||||
use fmt;
|
||||
use io;
|
||||
use libc::types::os::arch::extra::LPWCH;
|
||||
|
@ -199,13 +199,13 @@ impl<'a> Iterator for SplitPaths<'a> {
|
|||
pub struct JoinPathsError;
|
||||
|
||||
pub fn join_paths<I, T>(paths: I) -> Result<OsString, JoinPathsError>
|
||||
where I: Iterator<Item=T>, T: AsOsStr
|
||||
where I: Iterator<Item=T>, T: AsRef<OsStr>
|
||||
{
|
||||
let mut joined = Vec::new();
|
||||
let sep = b';' as u16;
|
||||
|
||||
for (i, path) in paths.enumerate() {
|
||||
let path = path.as_os_str();
|
||||
let path = path.as_ref();
|
||||
if i > 0 { joined.push(sep) }
|
||||
let v = path.encode_wide().collect::<Vec<u16>>();
|
||||
if v.contains(&(b'"' as u16)) {
|
||||
|
@ -245,7 +245,8 @@ pub fn getcwd() -> io::Result<PathBuf> {
|
|||
}
|
||||
|
||||
pub fn chdir(p: &path::Path) -> io::Result<()> {
|
||||
let mut p = p.as_os_str().encode_wide().collect::<Vec<_>>();
|
||||
let p: &OsStr = p.as_ref();
|
||||
let mut p = p.encode_wide().collect::<Vec<_>>();
|
||||
p.push(0);
|
||||
|
||||
unsafe {
|
||||
|
@ -361,8 +362,8 @@ pub fn temp_dir() -> PathBuf {
|
|||
}
|
||||
|
||||
pub fn home_dir() -> Option<PathBuf> {
|
||||
getenv("HOME".as_os_str()).or_else(|| {
|
||||
getenv("USERPROFILE".as_os_str())
|
||||
getenv("HOME".as_ref()).or_else(|| {
|
||||
getenv("USERPROFILE".as_ref())
|
||||
}).map(PathBuf::from).or_else(|| unsafe {
|
||||
let me = c::GetCurrentProcess();
|
||||
let mut token = ptr::null_mut();
|
||||
|
|
|
@ -23,6 +23,7 @@ use mem;
|
|||
use old_io::process::{ProcessExit, ExitStatus};
|
||||
use old_io::{IoResult, IoError};
|
||||
use old_io;
|
||||
use fs::PathExt;
|
||||
use os;
|
||||
use old_path::{BytesContainer, GenericPath};
|
||||
use ptr;
|
||||
|
@ -142,14 +143,19 @@ impl Process {
|
|||
let program = cfg.env().and_then(|env| {
|
||||
for (key, v) in env {
|
||||
if b"PATH" != key.container_as_bytes() { continue }
|
||||
let v = match ::str::from_utf8(v.container_as_bytes()) {
|
||||
Ok(s) => s,
|
||||
Err(..) => continue,
|
||||
};
|
||||
|
||||
// Split the value and test each path to see if the
|
||||
// program exists.
|
||||
for path in os::split_paths(v.container_as_bytes()) {
|
||||
let path = path.join(cfg.program().as_bytes())
|
||||
for path in ::env::split_paths(v) {
|
||||
let program = str::from_utf8(cfg.program().as_bytes()).unwrap();
|
||||
let path = path.join(program)
|
||||
.with_extension(env::consts::EXE_EXTENSION);
|
||||
if path.exists() {
|
||||
return Some(CString::from_slice(path.as_vec()))
|
||||
return Some(CString::new(path.to_str().unwrap()).unwrap())
|
||||
}
|
||||
}
|
||||
break
|
||||
|
@ -482,9 +488,9 @@ mod tests {
|
|||
#[test]
|
||||
fn test_make_command_line() {
|
||||
fn test_wrapper(prog: &str, args: &[&str]) -> String {
|
||||
make_command_line(&CString::from_slice(prog.as_bytes()),
|
||||
make_command_line(&CString::new(prog),
|
||||
&args.iter()
|
||||
.map(|a| CString::from_slice(a.as_bytes()))
|
||||
.map(|a| CString::new(a))
|
||||
.collect::<Vec<CString>>())
|
||||
}
|
||||
|
||||
|
|
|
@ -294,12 +294,6 @@ impl<T: 'static> LocalKey<T> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Deprecated
|
||||
#[unstable(feature = "std_misc")]
|
||||
#[deprecated(since = "1.0.0",
|
||||
reason = "function renamed to state() and returns more info")]
|
||||
pub fn destroyed(&'static self) -> bool { self.state() == LocalKeyState::Destroyed }
|
||||
}
|
||||
|
||||
#[cfg(all(any(target_os = "macos", target_os = "linux"), not(target_arch = "aarch64")))]
|
||||
|
|
|
@ -189,8 +189,6 @@ use sys_common::{stack, thread_info};
|
|||
use thunk::Thunk;
|
||||
use time::Duration;
|
||||
|
||||
#[allow(deprecated)] use old_io::Writer;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Thread-local storage
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -243,28 +241,6 @@ impl Builder {
|
|||
self
|
||||
}
|
||||
|
||||
/// Redirect thread-local stdout.
|
||||
#[unstable(feature = "std_misc",
|
||||
reason = "Will likely go away after proc removal")]
|
||||
#[deprecated(since = "1.0.0",
|
||||
reason = "the old I/O module is deprecated and this function \
|
||||
will be removed with no replacement")]
|
||||
#[allow(deprecated)]
|
||||
pub fn stdout(self, _stdout: Box<Writer + Send + 'static>) -> Builder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Redirect thread-local stderr.
|
||||
#[unstable(feature = "std_misc",
|
||||
reason = "Will likely go away after proc removal")]
|
||||
#[deprecated(since = "1.0.0",
|
||||
reason = "the old I/O module is deprecated and this function \
|
||||
will be removed with no replacement")]
|
||||
#[allow(deprecated)]
|
||||
pub fn stderr(self, _stderr: Box<Writer + Send + 'static>) -> Builder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Spawn a new thread, and return a join handle for it.
|
||||
///
|
||||
/// The child thread may outlive the parent (unless the parent thread
|
||||
|
@ -568,71 +544,6 @@ impl Thread {
|
|||
}
|
||||
}
|
||||
|
||||
/// Deprecated: use module-level free function.
|
||||
#[deprecated(since = "1.0.0", reason = "use module-level free function")]
|
||||
#[unstable(feature = "std_misc",
|
||||
reason = "may change with specifics of new Send semantics")]
|
||||
pub fn spawn<F>(f: F) -> Thread where F: FnOnce(), F: Send + 'static {
|
||||
Builder::new().spawn(f).unwrap().thread().clone()
|
||||
}
|
||||
|
||||
/// Deprecated: use module-level free function.
|
||||
#[deprecated(since = "1.0.0", reason = "use module-level free function")]
|
||||
#[unstable(feature = "std_misc",
|
||||
reason = "may change with specifics of new Send semantics")]
|
||||
pub fn scoped<'a, T, F>(f: F) -> JoinGuard<'a, T> where
|
||||
T: Send + 'a, F: FnOnce() -> T, F: Send + 'a
|
||||
{
|
||||
Builder::new().scoped(f).unwrap()
|
||||
}
|
||||
|
||||
/// Deprecated: use module-level free function.
|
||||
#[deprecated(since = "1.0.0", reason = "use module-level free function")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn current() -> Thread {
|
||||
thread_info::current_thread()
|
||||
}
|
||||
|
||||
/// Deprecated: use module-level free function.
|
||||
#[deprecated(since = "1.0.0", reason = "use module-level free function")]
|
||||
#[unstable(feature = "std_misc", reason = "name may change")]
|
||||
pub fn yield_now() {
|
||||
unsafe { imp::yield_now() }
|
||||
}
|
||||
|
||||
/// Deprecated: use module-level free function.
|
||||
#[deprecated(since = "1.0.0", reason = "use module-level free function")]
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn panicking() -> bool {
|
||||
unwind::panicking()
|
||||
}
|
||||
|
||||
/// Deprecated: use module-level free function.
|
||||
#[deprecated(since = "1.0.0", reason = "use module-level free function")]
|
||||
#[unstable(feature = "std_misc", reason = "recently introduced")]
|
||||
pub fn park() {
|
||||
let thread = current();
|
||||
let mut guard = thread.inner.lock.lock().unwrap();
|
||||
while !*guard {
|
||||
guard = thread.inner.cvar.wait(guard).unwrap();
|
||||
}
|
||||
*guard = false;
|
||||
}
|
||||
|
||||
/// Deprecated: use module-level free function.
|
||||
#[deprecated(since = "1.0.0", reason = "use module-level free function")]
|
||||
#[unstable(feature = "std_misc", reason = "recently introduced")]
|
||||
pub fn park_timeout(duration: Duration) {
|
||||
let thread = current();
|
||||
let mut guard = thread.inner.lock.lock().unwrap();
|
||||
if !*guard {
|
||||
let (g, _) = thread.inner.cvar.wait_timeout(guard, duration).unwrap();
|
||||
guard = g;
|
||||
}
|
||||
*guard = false;
|
||||
}
|
||||
|
||||
/// Atomically makes the handle's token available if it is not already.
|
||||
///
|
||||
/// See the module doc for more detail.
|
||||
|
@ -762,8 +673,8 @@ impl<'a, T: Send + 'a> JoinGuard<'a, T> {
|
|||
&self.inner.thread
|
||||
}
|
||||
|
||||
/// Wait for the associated thread to finish, returning the result of the thread's
|
||||
/// calculation.
|
||||
/// Wait for the associated thread to finish, returning the result of the
|
||||
/// thread's calculation.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
|
@ -777,17 +688,6 @@ impl<'a, T: Send + 'a> JoinGuard<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: Send> JoinGuard<'static, T> {
|
||||
/// Detaches the child thread, allowing it to outlive its parent.
|
||||
#[deprecated(since = "1.0.0", reason = "use spawn instead")]
|
||||
#[unstable(feature = "std_misc")]
|
||||
pub fn detach(mut self) {
|
||||
unsafe { imp::detach(self.inner.native) };
|
||||
self.inner.joined = true; // avoid joining in the destructor
|
||||
}
|
||||
}
|
||||
|
||||
#[unsafe_destructor]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a, T: Send + 'a> Drop for JoinGuard<'a, T> {
|
||||
|
|
|
@ -43,7 +43,6 @@
|
|||
#![feature(std_misc)]
|
||||
#![feature(libc)]
|
||||
#![feature(set_stdio)]
|
||||
#![feature(os)]
|
||||
#![cfg_attr(test, feature(old_io))]
|
||||
|
||||
extern crate getopts;
|
||||
|
@ -856,7 +855,8 @@ fn get_concurrency() -> usize {
|
|||
if std::rt::util::limit_thread_creation_due_to_osx_and_valgrind() {
|
||||
1
|
||||
} else {
|
||||
std::os::num_cpus()
|
||||
extern { fn rust_get_num_cpus() -> libc::uintptr_t; }
|
||||
unsafe { rust_get_num_cpus() as usize }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,11 +38,10 @@
|
|||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#![feature(rustc_private, core)]
|
||||
#![feature(rustc_private, core, step_by)]
|
||||
|
||||
extern crate arena;
|
||||
|
||||
use std::iter::range_step;
|
||||
use std::thread;
|
||||
use arena::TypedArena;
|
||||
|
||||
|
@ -109,7 +108,7 @@ fn main() {
|
|||
let long_lived_arena = TypedArena::new();
|
||||
let long_lived_tree = bottom_up_tree(&long_lived_arena, 0, max_depth);
|
||||
|
||||
let messages = range_step(min_depth, max_depth + 1, 2).map(|depth| {
|
||||
let messages = (min_depth..max_depth + 1).step_by(2).map(|depth| {
|
||||
use std::num::Int;
|
||||
let iterations = 2.pow((max_depth - depth + min_depth) as u32);
|
||||
thread::scoped(move || inner(depth, iterations))
|
||||
|
|
|
@ -38,9 +38,9 @@
|
|||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#![feature(core)]
|
||||
#![feature(step_by)]
|
||||
|
||||
use std::{cmp, iter, mem};
|
||||
use std::{cmp, mem};
|
||||
use std::thread;
|
||||
|
||||
fn rotate(x: &mut [i32]) {
|
||||
|
@ -163,7 +163,7 @@ fn fannkuch(n: i32) -> (i32, i32) {
|
|||
let mut futures = vec![];
|
||||
let k = perm.max() / N;
|
||||
|
||||
for (_, j) in (0..N).zip(iter::count(0, k)) {
|
||||
for (_, j) in (0..N).zip((0..).step_by(k)) {
|
||||
let max = cmp::min(j+k, perm.max());
|
||||
|
||||
futures.push(thread::scoped(move|| {
|
||||
|
|
|
@ -193,7 +193,7 @@ fn main() {
|
|||
|
||||
// start processing if this is the one
|
||||
('>', false) => {
|
||||
match line[1..].find_str("THREE") {
|
||||
match line[1..].find("THREE") {
|
||||
Some(_) => { proc_mode = true; }
|
||||
None => { }
|
||||
}
|
||||
|
|
|
@ -118,7 +118,9 @@ fn dot(v: &[f64], u: &[f64]) -> f64 {
|
|||
fn parallel<'a,T, F>(v: &mut [T], ref f: F)
|
||||
where T: Send + Sync + 'a,
|
||||
F: Fn(usize, &mut [T]) + Sync + 'a {
|
||||
let size = v.len() / os::num_cpus() + 1;
|
||||
// FIXME: pick a more appropriate parallel factor
|
||||
let parallelism = 4;
|
||||
let size = v.len() / parallelism + 1;
|
||||
v.chunks_mut(size).enumerate().map(|(i, chunk)| {
|
||||
thread::scoped(move|| {
|
||||
f(i * size, chunk)
|
||||
|
|
|
@ -20,9 +20,9 @@ use id::Id;
|
|||
|
||||
mod s {
|
||||
#![allow(unstable)]
|
||||
use std::sync::atomic::{AtomicUint, ATOMIC_UINT_INIT, Ordering};
|
||||
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
|
||||
|
||||
static S_COUNT: AtomicUint = ATOMIC_UINT_INIT;
|
||||
static S_COUNT: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
|
||||
pub fn next_count() -> usize {
|
||||
S_COUNT.fetch_add(1, Ordering::SeqCst) + 1
|
||||
|
|
|
@ -27,9 +27,9 @@ use id::Id;
|
|||
|
||||
mod s {
|
||||
#![allow(unstable)]
|
||||
use std::sync::atomic::{AtomicUint, ATOMIC_UINT_INIT, Ordering};
|
||||
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
|
||||
|
||||
static S_COUNT: AtomicUint = ATOMIC_UINT_INIT;
|
||||
static S_COUNT: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
|
||||
pub fn next_count() -> usize {
|
||||
S_COUNT.fetch_add(1, Ordering::SeqCst) + 1
|
||||
|
|
|
@ -19,9 +19,9 @@ use id::Id;
|
|||
|
||||
mod s {
|
||||
#![allow(unstable)]
|
||||
use std::sync::atomic::{AtomicUint, ATOMIC_UINT_INIT, Ordering};
|
||||
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
|
||||
|
||||
static S_COUNT: AtomicUint = ATOMIC_UINT_INIT;
|
||||
static S_COUNT: AtomicUsize = ATOMIC_USIZE_INIT;
|
||||
|
||||
pub fn next_count() -> usize {
|
||||
S_COUNT.fetch_add(1, Ordering::SeqCst) + 1
|
||||
|
|
|
@ -18,7 +18,7 @@ fn has_uniq(x: String) {
|
|||
|
||||
fn has_slice(x: &str) {
|
||||
wants_uniq(x); //~ ERROR mismatched types
|
||||
wants_slice(x.as_slice());
|
||||
wants_slice(x);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue