Skip to content

Commit

Permalink
std: Stabilize APIs for the 1.6 release
Browse files Browse the repository at this point in the history
This commit is the standard API stabilization commit for the 1.6 release cycle.
The list of issues and APIs below have all been through their cycle-long FCP and
the libs team decisions are listed below

Stabilized APIs

* `Read::read_exact`
* `ErrorKind::UnexpectedEof` (renamed from `UnexpectedEOF`)
* libcore -- this was a bit of a nuanced stabilization, the crate itself is now
  marked as `#[stable]` and the methods appearing via traits for primitives like
  `char` and `str` are now also marked as stable. Note that the extension traits
  themeselves are marked as unstable as they're imported via the prelude. The
  `try!` macro was also moved from the standard library into libcore to have the
  same interface. Otherwise the functions all have copied stability from the
  standard library now.
* The `#![no_std]` attribute
* `fs::DirBuilder`
* `fs::DirBuilder::new`
* `fs::DirBuilder::recursive`
* `fs::DirBuilder::create`
* `os::unix::fs::DirBuilderExt`
* `os::unix::fs::DirBuilderExt::mode`
* `vec::Drain`
* `vec::Vec::drain`
* `string::Drain`
* `string::String::drain`
* `vec_deque::Drain`
* `vec_deque::VecDeque::drain`
* `collections::hash_map::Drain`
* `collections::hash_map::HashMap::drain`
* `collections::hash_set::Drain`
* `collections::hash_set::HashSet::drain`
* `collections::binary_heap::Drain`
* `collections::binary_heap::BinaryHeap::drain`
* `Vec::extend_from_slice` (renamed from `push_all`)
* `Mutex::get_mut`
* `Mutex::into_inner`
* `RwLock::get_mut`
* `RwLock::into_inner`
* `Iterator::min_by_key` (renamed from `min_by`)
* `Iterator::max_by_key` (renamed from `max_by`)

Deprecated APIs

* `ErrorKind::UnexpectedEOF` (renamed to `UnexpectedEof`)
* `OsString::from_bytes`
* `OsStr::to_cstring`
* `OsStr::to_bytes`
* `fs::walk_dir` and `fs::WalkDir`
* `path::Components::peek`
* `slice::bytes::MutableByteVector`
* `slice::bytes::copy_memory`
* `Vec::push_all` (renamed to `extend_from_slice`)
* `Duration::span`
* `IpAddr`
* `SocketAddr::ip`
* `Read::tee`
* `io::Tee`
* `Write::broadcast`
* `io::Broadcast`
* `Iterator::min_by` (renamed to `min_by_key`)
* `Iterator::max_by` (renamed to `max_by_key`)
* `net::lookup_addr`

New APIs (still unstable)

* `<[T]>::sort_by_key` (added to mirror `min_by_key`)

Closes rust-lang#27585
Closes rust-lang#27704
Closes rust-lang#27707
Closes rust-lang#27710
Closes rust-lang#27711
Closes rust-lang#27727
Closes rust-lang#27740
Closes rust-lang#27744
Closes rust-lang#27799
Closes rust-lang#27801
cc rust-lang#27801 (doesn't close as `Chars` is still unstable)
Closes rust-lang#28968
  • Loading branch information
alexcrichton committed Dec 5, 2015
1 parent ac0e845 commit 464cdff
Show file tree
Hide file tree
Showing 165 changed files with 712 additions and 718 deletions.
2 changes: 0 additions & 2 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#![feature(rustc_private)]
#![feature(str_char)]
#![feature(test)]
#![feature(vec_push_all)]
#![feature(path_components_peek)]

#![deny(warnings)]

Expand Down
17 changes: 7 additions & 10 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,15 +1009,12 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError>,
}
}

fn is_compiler_error_or_warning(mut line: &str) -> bool {
// Remove initial prefix which may contain a colon
let mut components = Path::new(line).components();
if let Some(Component::Prefix(_)) = components.peek() {
components.next();
}

// Safe as path was originally constructed from a &str ^
line = components.as_path().to_str().unwrap();
fn is_compiler_error_or_warning(line: &str) -> bool {
let mut c = Path::new(line).components();
let line = match c.next() {
Some(Component::Prefix(_)) => c.as_path().to_str().unwrap(),
_ => line,
};

let mut i = 0;
return
Expand Down Expand Up @@ -1314,7 +1311,7 @@ fn make_compile_args<F>(config: &Config,
"-L".to_owned(),
config.build_base.to_str().unwrap().to_owned(),
format!("--target={}", target));
args.push_all(&extras);
args.extend_from_slice(&extras);
if !props.no_prefer_dynamic {
args.push("-C".to_owned());
args.push("prefer-dynamic".to_owned());
Expand Down
1 change: 0 additions & 1 deletion src/doc/book/custom-allocators.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ annotated version of `alloc_system`
// Allocators are not allowed to depend on the standard library which in turn
// requires an allocator in order to avoid circular dependencies. This crate,
// however, can use all of libcore.
#![feature(no_std)]
#![no_std]
// Let's give a unique name to our custom allocator
Expand Down
2 changes: 1 addition & 1 deletion src/doc/book/lang-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ and one for deallocation. A freestanding program that uses the `Box`
sugar for dynamic allocations via `malloc` and `free`:

```rust
#![feature(lang_items, box_syntax, start, no_std, libc)]
#![feature(lang_items, box_syntax, start, libc)]
#![no_std]

extern crate libc;
Expand Down
5 changes: 0 additions & 5 deletions src/doc/book/no-stdlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ in the same format as C:
# #![feature(libc)]
#![feature(lang_items)]
#![feature(start)]
#![feature(no_std)]
#![no_std]

// Pull in the system libc library for what crt0.o likely requires
Expand Down Expand Up @@ -46,7 +45,6 @@ compiler's name mangling too:

```rust
# #![feature(libc)]
#![feature(no_std)]
#![feature(lang_items)]
#![feature(start)]
#![no_std]
Expand Down Expand Up @@ -104,9 +102,6 @@ vectors provided from C, using idiomatic Rust practices.
# #![feature(libc)]
#![feature(lang_items)]
#![feature(start)]
#![feature(no_std)]
#![feature(core)]
#![feature(core_slice_ext)]
#![feature(raw)]
#![no_std]

Expand Down
3 changes: 0 additions & 3 deletions src/etc/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ def emit_bsearch_range_table(f):
f.write("""
fn bsearch_range_table(c: char, r: &'static [(char, char)]) -> bool {
use core::cmp::Ordering::{Equal, Less, Greater};
use core::slice::SliceExt;
r.binary_search_by(|&(lo, hi)| {
if lo <= c && c <= hi {
Equal
Expand Down Expand Up @@ -358,7 +357,6 @@ def emit_conversions_module(f, to_upper, to_lower, to_title):
f.write("pub mod conversions {")
f.write("""
use core::cmp::Ordering::{Equal, Less, Greater};
use core::slice::SliceExt;
use core::option::Option;
use core::option::Option::{Some, None};
use core::result::Result::{Ok, Err};
Expand Down Expand Up @@ -404,7 +402,6 @@ def emit_charwidth_module(f, width_table):
f.write("pub mod charwidth {\n")
f.write(" use core::option::Option;\n")
f.write(" use core::option::Option::{Some, None};\n")
f.write(" use core::slice::SliceExt;\n")
f.write(" use core::result::Result::{Ok, Err};\n")
f.write("""
fn bsearch_range_value_table(c: char, is_cjk: bool, r: &'static [(char, char, u8, u8)]) -> u8 {
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ pub struct ExchangeHeapSingleton {
/// See the [module-level documentation](../../std/boxed/index.html) for more.
#[lang = "owned_box"]
#[stable(feature = "rust1", since = "1.0.0")]
#[fundamental]
pub struct Box<T: ?Sized>(Unique<T>);

/// `IntermediateBox` represents uninitialized backing storage for `Box`.
Expand Down
7 changes: 2 additions & 5 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,15 @@
#![cfg_attr(not(stage0), needs_allocator)]

#![cfg_attr(stage0, feature(rustc_attrs))]
#![cfg_attr(stage0, feature(no_std))]
#![cfg_attr(stage0, allow(unused_attributes))]
#![feature(allocator)]
#![feature(box_syntax)]
#![feature(coerce_unsized)]
#![feature(core)]
#![feature(core_intrinsics)]
#![feature(core_slice_ext)]
#![feature(custom_attribute)]
#![feature(fundamental)]
#![feature(lang_items)]
#![feature(no_std)]
#![feature(nonzero)]
#![feature(num_bits_bytes)]
#![feature(optin_builtin_traits)]
Expand All @@ -103,9 +101,8 @@
#![allow(unused_attributes)]
#![feature(dropck_parametricity)]
#![feature(unsize)]
#![feature(core_slice_ext)]
#![feature(core_str_ext)]
#![feature(drop_in_place)]
#![feature(fn_traits)]

#![cfg_attr(stage0, feature(alloc_system))]
#![cfg_attr(not(stage0), feature(needs_allocator))]
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use core::ptr::Unique;
use core::mem;
use core::slice::{self, SliceExt};
use core::slice;
use heap;
use super::oom;
use super::boxed::Box;
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc_jemalloc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
issue = "27783")]
#![feature(allocator)]
#![feature(libc)]
#![feature(no_std)]
#![feature(staged_api)]
#![cfg_attr(stage0, feature(no_std))]

extern crate libc;

Expand Down
2 changes: 1 addition & 1 deletion src/liballoc_system/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
issue = "27783")]
#![feature(allocator)]
#![feature(libc)]
#![feature(no_std)]
#![feature(staged_api)]
#![cfg_attr(stage0, feature(no_std))]

extern crate libc;

Expand Down
7 changes: 2 additions & 5 deletions src/libcollections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,7 @@ impl<T: Ord> BinaryHeap<T> {
///
/// The elements are removed in arbitrary order.
#[inline]
#[unstable(feature = "drain",
reason = "matches collection reform specification, \
waiting for dust to settle",
issue = "27711")]
#[stable(feature = "drain", since = "1.6.0")]
pub fn drain(&mut self) -> Drain<T> {
Drain { iter: self.data.drain(..) }
}
Expand Down Expand Up @@ -738,7 +735,7 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
impl<T> ExactSizeIterator for IntoIter<T> {}

/// An iterator that drains a `BinaryHeap`.
#[unstable(feature = "drain", reason = "recent addition", issue = "27711")]
#[stable(feature = "drain", since = "1.6.0")]
pub struct Drain<'a, T: 'a> {
iter: vec::Drain<'a, T>,
}
Expand Down
5 changes: 2 additions & 3 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(core_intrinsics)]
#![feature(core_slice_ext)]
#![feature(core_str_ext)]
#![feature(fmt_internals)]
#![feature(fmt_radix)]
#![feature(heap_api)]
Expand All @@ -68,9 +66,10 @@
#![feature(unsafe_no_drop_flag, filling_drop)]
#![feature(decode_utf16)]
#![feature(drop_in_place)]
#![feature(clone_from_slice)]
#![cfg_attr(test, feature(clone_from_slice, rand, test))]

#![feature(no_std)]
#![cfg_attr(stage0, feature(no_std))]
#![no_std]

extern crate rustc_unicode;
Expand Down
33 changes: 30 additions & 3 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ mod hack {
where T: Clone
{
let mut vector = Vec::with_capacity(s.len());
vector.push_all(s);
vector.extend_from_slice(s);
vector
}
}
Expand Down Expand Up @@ -777,6 +777,33 @@ impl<T> [T] {
self.sort_by(|a, b| a.cmp(b))
}

/// Sorts the slice, in place, using `key` to extract a key by which to
/// order the sort by.
///
/// This sort is `O(n log n)` worst-case and stable, but allocates
/// approximately `2 * n`, where `n` is the length of `self`.
///
/// This is a stable sort.
///
/// # Examples
///
/// ```rust
/// #![feature(slice_sort_by_key)]
///
/// let mut v = [-5i32, 4, 1, -3, 2];
///
/// v.sort_by_key(|k| k.abs());
/// assert!(v == [1, 2, -3, 4, -5]);
/// ```
#[unstable(feature = "slice_sort_by_key", reason = "recently added",
issue = "27724")]
#[inline]
pub fn sort_by_key<B, F>(&mut self, mut f: F)
where F: FnMut(&T) -> B, B: Ord
{
self.sort_by(|a, b| f(a).cmp(&f(b)))
}

/// Sorts the slice, in place, using `compare` to compare
/// elements.
///
Expand Down Expand Up @@ -906,7 +933,7 @@ impl<T: Clone, V: Borrow<[T]>> SliceConcatExt<T> for [V] {
let size = self.iter().fold(0, |acc, v| acc + v.borrow().len());
let mut result = Vec::with_capacity(size);
for v in self {
result.push_all(v.borrow())
result.extend_from_slice(v.borrow())
}
result
}
Expand All @@ -921,7 +948,7 @@ impl<T: Clone, V: Borrow<[T]>> SliceConcatExt<T> for [V] {
} else {
result.push(sep.clone())
}
result.push_all(v.borrow())
result.extend_from_slice(v.borrow())
}
result
}
Expand Down
28 changes: 12 additions & 16 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ impl String {
let mut res = String::with_capacity(total);

if i > 0 {
unsafe { res.as_mut_vec().push_all(&v[..i]) };
unsafe { res.as_mut_vec().extend_from_slice(&v[..i]) };
}

// subseqidx is the index of the first byte of the subsequence we're
Expand All @@ -498,10 +498,10 @@ impl String {
macro_rules! error { () => ({
unsafe {
if subseqidx != i_ {
res.as_mut_vec().push_all(&v[subseqidx..i_]);
res.as_mut_vec().extend_from_slice(&v[subseqidx..i_]);
}
subseqidx = i;
res.as_mut_vec().push_all(REPLACEMENT);
res.as_mut_vec().extend_from_slice(REPLACEMENT);
}
})}

Expand Down Expand Up @@ -566,7 +566,7 @@ impl String {
}
}
if subseqidx < total {
unsafe { res.as_mut_vec().push_all(&v[subseqidx..total]) };
unsafe { res.as_mut_vec().extend_from_slice(&v[subseqidx..total]) };
}
Cow::Owned(res)
}
Expand Down Expand Up @@ -699,7 +699,7 @@ impl String {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push_str(&mut self, string: &str) {
self.vec.push_all(string.as_bytes())
self.vec.extend_from_slice(string.as_bytes())
}

/// Returns the number of bytes that this string buffer can hold without
Expand Down Expand Up @@ -1026,8 +1026,6 @@ impl String {
/// # Examples
///
/// ```
/// #![feature(drain)]
///
/// let mut s = String::from("α is alpha, β is beta");
/// let beta_offset = s.find('β').unwrap_or(s.len());
///
Expand All @@ -1040,9 +1038,7 @@ impl String {
/// s.drain(..);
/// assert_eq!(s, "");
/// ```
#[unstable(feature = "drain",
reason = "recently added, matches RFC",
issue = "27711")]
#[stable(feature = "drain", since = "1.6.0")]
pub fn drain<R>(&mut self, range: R) -> Drain
where R: RangeArgument<usize>
{
Expand Down Expand Up @@ -1600,7 +1596,7 @@ impl fmt::Write for String {
}

/// A draining iterator for `String`.
#[unstable(feature = "drain", reason = "recently added", issue = "27711")]
#[stable(feature = "drain", since = "1.6.0")]
pub struct Drain<'a> {
/// Will be used as &'a mut String in the destructor
string: *mut String,
Expand All @@ -1612,12 +1608,12 @@ pub struct Drain<'a> {
iter: Chars<'a>,
}

#[unstable(feature = "drain", reason = "recently added", issue = "27711")]
#[stable(feature = "drain", since = "1.6.0")]
unsafe impl<'a> Sync for Drain<'a> {}
#[unstable(feature = "drain", reason = "recently added", issue = "27711")]
#[stable(feature = "drain", since = "1.6.0")]
unsafe impl<'a> Send for Drain<'a> {}

#[unstable(feature = "drain", reason = "recently added", issue = "27711")]
#[stable(feature = "drain", since = "1.6.0")]
impl<'a> Drop for Drain<'a> {
fn drop(&mut self) {
unsafe {
Expand All @@ -1631,7 +1627,7 @@ impl<'a> Drop for Drain<'a> {
}
}

#[unstable(feature = "drain", reason = "recently added", issue = "27711")]
#[stable(feature = "drain", since = "1.6.0")]
impl<'a> Iterator for Drain<'a> {
type Item = char;

Expand All @@ -1645,7 +1641,7 @@ impl<'a> Iterator for Drain<'a> {
}
}

#[unstable(feature = "drain", reason = "recently added", issue = "27711")]
#[stable(feature = "drain", since = "1.6.0")]
impl<'a> DoubleEndedIterator for Drain<'a> {
#[inline]
fn next_back(&mut self) -> Option<char> {
Expand Down
Loading

0 comments on commit 464cdff

Please sign in to comment.