Skip to content

Commit

Permalink
std: Stabilize APIs for the 1.9 release
Browse files Browse the repository at this point in the history
This commit applies all stabilizations, renamings, and deprecations that the
library team has decided on for the upcoming 1.9 release. All tracking issues
have gone through a cycle-long "final comment period" and the specific APIs
stabilized/deprecated are:

Stable

* `std::panic`
* `std::panic::catch_unwind` (renamed from `recover`)
* `std::panic::resume_unwind` (renamed from `propagate`)
* `std::panic::AssertUnwindSafe` (renamed from `AssertRecoverSafe`)
* `std::panic::UnwindSafe` (renamed from `RecoverSafe`)
* `str::is_char_boundary`
* `<*const T>::as_ref`
* `<*mut T>::as_ref`
* `<*mut T>::as_mut`
* `AsciiExt::make_ascii_uppercase`
* `AsciiExt::make_ascii_lowercase`
* `char::decode_utf16`
* `char::DecodeUtf16`
* `char::DecodeUtf16Error`
* `char::DecodeUtf16Error::unpaired_surrogate`
* `BTreeSet::take`
* `BTreeSet::replace`
* `BTreeSet::get`
* `HashSet::take`
* `HashSet::replace`
* `HashSet::get`
* `OsString::with_capacity`
* `OsString::clear`
* `OsString::capacity`
* `OsString::reserve`
* `OsString::reserve_exact`
* `OsStr::is_empty`
* `OsStr::len`
* `std::os::unix::thread`
* `RawPthread`
* `JoinHandleExt`
* `JoinHandleExt::as_pthread_t`
* `JoinHandleExt::into_pthread_t`
* `HashSet::hasher`
* `HashMap::hasher`
* `CommandExt::exec`
* `File::try_clone`
* `SocketAddr::set_ip`
* `SocketAddr::set_port`
* `SocketAddrV4::set_ip`
* `SocketAddrV4::set_port`
* `SocketAddrV6::set_ip`
* `SocketAddrV6::set_port`
* `SocketAddrV6::set_flowinfo`
* `SocketAddrV6::set_scope_id`
* `<[T]>::copy_from_slice`
* `ptr::read_volatile`
* `ptr::write_volatile`
* The `#[deprecated]` attribute
* `OpenOptions::create_new`

Deprecated

* `std::raw::Slice` - use raw parts of `slice` module instead
* `std::raw::Repr` - use raw parts of `slice` module instead
* `str::char_range_at` - use slicing plus `chars()` plus `len_utf8`
* `str::char_range_at_reverse` - use slicing plus `chars().rev()` plus `len_utf8`
* `str::char_at` - use slicing plus `chars()`
* `str::char_at_reverse` - use slicing plus `chars().rev()`
* `str::slice_shift_char` - use `chars()` plus `Chars::as_str`
* `CommandExt::session_leader` - use `before_exec` instead.

Closes rust-lang#27719
cc rust-lang#27751 (deprecating the `Slice` bits)
Closes rust-lang#27754
Closes rust-lang#27780
Closes rust-lang#27809
Closes rust-lang#27811
Closes rust-lang#27830
Closes rust-lang#28050
Closes rust-lang#29453
Closes rust-lang#29791
Closes rust-lang#29935
Closes rust-lang#30014
Closes rust-lang#30752
Closes rust-lang#31262
cc rust-lang#31398 (still need to deal with `before_exec`)
Closes rust-lang#31405
Closes rust-lang#31572
Closes rust-lang#31755
Closes rust-lang#31756
  • Loading branch information
alexcrichton committed Apr 11, 2016
1 parent 8694b4f commit 552eda7
Show file tree
Hide file tree
Showing 58 changed files with 508 additions and 328 deletions.
31 changes: 20 additions & 11 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#![feature(box_syntax)]
#![feature(libc)]
#![feature(rustc_private)]
#![feature(str_char)]
#![feature(test)]
#![feature(question_mark)]

Expand Down Expand Up @@ -412,16 +411,26 @@ fn extract_gdb_version(full_version_line: Option<String>) -> Option<String> {

// used to be a regex "(^|[^0-9])([0-9]\.[0-9]+)"
for (pos, c) in full_version_line.char_indices() {
if !c.is_digit(10) { continue }
if pos + 2 >= full_version_line.len() { continue }
if full_version_line.char_at(pos + 1) != '.' { continue }
if !full_version_line.char_at(pos + 2).is_digit(10) { continue }
if pos > 0 && full_version_line.char_at_reverse(pos).is_digit(10) {
if !c.is_digit(10) {
continue
}
if pos + 2 >= full_version_line.len() {
continue
}
if full_version_line[pos + 1..].chars().next().unwrap() != '.' {
continue
}
if !full_version_line[pos + 2..].chars().next().unwrap().is_digit(10) {
continue
}
if pos > 0 && full_version_line[..pos].chars().next_back()
.unwrap().is_digit(10) {
continue
}
let mut end = pos + 3;
while end < full_version_line.len() &&
full_version_line.char_at(end).is_digit(10) {
full_version_line[end..].chars().next()
.unwrap().is_digit(10) {
end += 1;
}
return Some(full_version_line[pos..end].to_owned());
Expand Down Expand Up @@ -453,13 +462,13 @@ fn extract_lldb_version(full_version_line: Option<String>) -> Option<String> {
for (pos, l) in full_version_line.char_indices() {
if l != 'l' && l != 'L' { continue }
if pos + 5 >= full_version_line.len() { continue }
let l = full_version_line.char_at(pos + 1);
let l = full_version_line[pos + 1..].chars().next().unwrap();
if l != 'l' && l != 'L' { continue }
let d = full_version_line.char_at(pos + 2);
let d = full_version_line[pos + 2..].chars().next().unwrap();
if d != 'd' && d != 'D' { continue }
let b = full_version_line.char_at(pos + 3);
let b = full_version_line[pos + 3..].chars().next().unwrap();
if b != 'b' && b != 'B' { continue }
let dash = full_version_line.char_at(pos + 4);
let dash = full_version_line[pos + 4..].chars().next().unwrap();
if dash != '-' { continue }

let vers = full_version_line[pos + 5..].chars().take_while(|c| {
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn parse_expected(last_nonfollow_error: Option<usize>,
tag: &str)
-> Option<(WhichLine, ExpectedError)> {
let start = match line.find(tag) { Some(i) => i, None => return None };
let (follow, adjusts) = if line.char_at(start + tag.len()) == '|' {
let (follow, adjusts) = if line[start + tag.len()..].chars().next().unwrap() == '|' {
(true, 0)
} else {
(false, line[start + tag.len()..].chars().take_while(|c| *c == '^').count())
Expand Down
6 changes: 3 additions & 3 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ fn scan_char(haystack: &str, needle: char, idx: &mut usize) -> bool {
if *idx >= haystack.len() {
return false;
}
let ch = haystack.char_at(*idx);
let ch = haystack[*idx..].chars().next().unwrap();
if ch != needle {
return false;
}
Expand All @@ -1188,7 +1188,7 @@ fn scan_char(haystack: &str, needle: char, idx: &mut usize) -> bool {
fn scan_integer(haystack: &str, idx: &mut usize) -> bool {
let mut i = *idx;
while i < haystack.len() {
let ch = haystack.char_at(i);
let ch = haystack[i..].chars().next().unwrap();
if ch < '0' || '9' < ch {
break;
}
Expand All @@ -1208,7 +1208,7 @@ fn scan_string(haystack: &str, needle: &str, idx: &mut usize) -> bool {
if haystack_i >= haystack.len() {
return false;
}
let ch = haystack.char_at(haystack_i);
let ch = haystack[haystack_i..].chars().next().unwrap();
haystack_i += ch.len_utf8();
if !scan_char(needle, ch, &mut needle_i) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/libcollections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl<T: Ord> BTreeSet<T> {
/// The value may be any borrowed form of the set's value type,
/// but the ordering on the borrowed form *must* match the
/// ordering on the value type.
#[unstable(feature = "set_recovery", issue = "28050")]
#[stable(feature = "set_recovery", since = "1.9.0")]
pub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T>
where T: Borrow<Q>,
Q: Ord
Expand Down Expand Up @@ -502,7 +502,7 @@ impl<T: Ord> BTreeSet<T> {

/// Adds a value to the set, replacing the existing value, if any, that is equal to the given
/// one. Returns the replaced value.
#[unstable(feature = "set_recovery", issue = "28050")]
#[stable(feature = "set_recovery", since = "1.9.0")]
pub fn replace(&mut self, value: T) -> Option<T> {
Recover::replace(&mut self.map, value)
}
Expand Down Expand Up @@ -538,7 +538,7 @@ impl<T: Ord> BTreeSet<T> {
/// The value may be any borrowed form of the set's value type,
/// but the ordering on the borrowed form *must* match the
/// ordering on the value type.
#[unstable(feature = "set_recovery", issue = "28050")]
#[stable(feature = "set_recovery", since = "1.9.0")]
pub fn take<Q: ?Sized>(&mut self, value: &Q) -> Option<T>
where T: Borrow<Q>,
Q: Ord
Expand Down
2 changes: 0 additions & 2 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@
test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]

#![cfg_attr(test, allow(deprecated))] // rand
#![cfg_attr(not(test), feature(copy_from_slice))] // impl [T]
#![cfg_attr(not(stage0), deny(warnings))]

#![feature(alloc)]
#![feature(allow_internal_unstable)]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(core_intrinsics)]
#![feature(decode_utf16)]
#![feature(dropck_parametricity)]
#![feature(fmt_internals)]
#![feature(heap_api)]
Expand Down
3 changes: 1 addition & 2 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,14 +845,13 @@ impl<T> [T] {
/// # Example
///
/// ```rust
/// #![feature(copy_from_slice)]
/// let mut dst = [0, 0, 0];
/// let src = [1, 2, 3];
///
/// dst.copy_from_slice(&src);
/// assert_eq!(src, dst);
/// ```
#[unstable(feature = "copy_from_slice", issue = "31755")]
#[stable(feature = "copy_from_slice", since = "1.9.0")]
pub fn copy_from_slice(&mut self, src: &[T]) where T: Copy {
core_slice::SliceExt::copy_from_slice(self, src)
}
Expand Down
29 changes: 21 additions & 8 deletions src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ impl str {
/// # Examples
///
/// ```
/// #![feature(str_char)]
///
/// let s = "Löwe 老虎 Léopard";
/// assert!(s.is_char_boundary(0));
/// // start of `老`
Expand All @@ -242,12 +240,7 @@ impl str {
/// // third byte of `老`
/// assert!(!s.is_char_boundary(8));
/// ```
#[unstable(feature = "str_char",
reason = "it is unclear whether this method pulls its weight \
with the existence of the char_indices iterator or \
this method may want to be replaced with checked \
slicing",
issue = "27754")]
#[stable(feature = "is_char_boundary", since = "1.9.0")]
#[inline]
pub fn is_char_boundary(&self, index: usize) -> bool {
core_str::StrExt::is_char_boundary(self, index)
Expand Down Expand Up @@ -374,6 +367,7 @@ impl str {
///
/// ```
/// #![feature(str_char)]
/// #![allow(deprecated)]
///
/// use std::str::CharRange;
///
Expand Down Expand Up @@ -408,6 +402,9 @@ impl str {
removed altogether",
issue = "27754")]
#[inline]
#[rustc_deprecated(reason = "use slicing plus chars() plus len_utf8",
since = "1.9.0")]
#[allow(deprecated)]
pub fn char_range_at(&self, start: usize) -> CharRange {
core_str::StrExt::char_range_at(self, start)
}
Expand All @@ -432,6 +429,7 @@ impl str {
///
/// ```
/// #![feature(str_char)]
/// #![allow(deprecated)]
///
/// use std::str::CharRange;
///
Expand Down Expand Up @@ -466,6 +464,9 @@ impl str {
eventually removed altogether",
issue = "27754")]
#[inline]
#[rustc_deprecated(reason = "use slicing plus chars().rev() plus len_utf8",
since = "1.9.0")]
#[allow(deprecated)]
pub fn char_range_at_reverse(&self, start: usize) -> CharRange {
core_str::StrExt::char_range_at_reverse(self, start)
}
Expand All @@ -481,6 +482,7 @@ impl str {
///
/// ```
/// #![feature(str_char)]
/// #![allow(deprecated)]
///
/// let s = "abπc";
/// assert_eq!(s.char_at(1), 'b');
Expand All @@ -495,6 +497,9 @@ impl str {
subslice",
issue = "27754")]
#[inline]
#[allow(deprecated)]
#[rustc_deprecated(reason = "use slicing plus chars()",
since = "1.9.0")]
pub fn char_at(&self, i: usize) -> char {
core_str::StrExt::char_at(self, i)
}
Expand All @@ -511,6 +516,7 @@ impl str {
///
/// ```
/// #![feature(str_char)]
/// #![allow(deprecated)]
///
/// let s = "abπc";
/// assert_eq!(s.char_at_reverse(1), 'a');
Expand All @@ -523,6 +529,9 @@ impl str {
cases generate panics",
issue = "27754")]
#[inline]
#[rustc_deprecated(reason = "use slicing plus chars().rev()",
since = "1.9.0")]
#[allow(deprecated)]
pub fn char_at_reverse(&self, i: usize) -> char {
core_str::StrExt::char_at_reverse(self, i)
}
Expand All @@ -541,6 +550,7 @@ impl str {
///
/// ```
/// #![feature(str_char)]
/// #![allow(deprecated)]
///
/// let s = "Łódź"; // \u{141}o\u{301}dz\u{301}
/// let (c, s1) = s.slice_shift_char().unwrap();
Expand All @@ -559,6 +569,9 @@ impl str {
and/or char_indices iterators",
issue = "27754")]
#[inline]
#[rustc_deprecated(reason = "use chars() plus Chars::as_str",
since = "1.9.0")]
#[allow(deprecated)]
pub fn slice_shift_char(&self) -> Option<(char, &str)> {
core_str::StrExt::slice_shift_char(self)
}
Expand Down
21 changes: 11 additions & 10 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,14 +1037,13 @@ impl String {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn pop(&mut self) -> Option<char> {
let len = self.len();
if len == 0 {
return None;
}

let ch = self.char_at_reverse(len);
let ch = match self.chars().rev().next() {
Some(ch) => ch,
None => return None,
};
let newlen = self.len() - ch.len_utf8();
unsafe {
self.vec.set_len(len - ch.len_utf8());
self.vec.set_len(newlen);
}
Some(ch)
}
Expand Down Expand Up @@ -1075,11 +1074,13 @@ impl String {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn remove(&mut self, idx: usize) -> char {
let len = self.len();
assert!(idx < len);
let ch = match self[idx..].chars().next() {
Some(ch) => ch,
None => panic!("cannot remove a char from the end of a string"),
};

let ch = self.char_at(idx);
let next = idx + ch.len_utf8();
let len = self.len();
unsafe {
ptr::copy(self.vec.as_ptr().offset(next as isize),
self.vec.as_mut_ptr().offset(idx as isize),
Expand Down
3 changes: 0 additions & 3 deletions src/libcollectionstest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@

#![deny(warnings)]

#![feature(ascii)]
#![feature(binary_heap_extras)]
#![feature(box_syntax)]
#![feature(btree_range)]
#![feature(collections)]
#![feature(collections_bound)]
#![feature(copy_from_slice)]
#![feature(const_fn)]
#![feature(fn_traits)]
#![feature(enumset)]
Expand All @@ -25,7 +23,6 @@
#![feature(map_values_mut)]
#![feature(pattern)]
#![feature(rand)]
#![feature(set_recovery)]
#![feature(step_by)]
#![feature(str_char)]
#![feature(str_escape)]
Expand Down
6 changes: 6 additions & 0 deletions src/libcollectionstest/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,14 @@ fn test_is_whitespace() {
}

#[test]
#[allow(deprecated)]
fn test_slice_shift_char() {
let data = "ประเทศไทย中";
assert_eq!(data.slice_shift_char(), Some(('ป', "ระเทศไทย中")));
}

#[test]
#[allow(deprecated)]
fn test_slice_shift_char_2() {
let empty = "";
assert_eq!(empty.slice_shift_char(), None);
Expand Down Expand Up @@ -657,6 +659,7 @@ fn test_contains_char() {
}

#[test]
#[allow(deprecated)]
fn test_char_at() {
let s = "ศไทย中华Việt Nam";
let v = vec!['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
Expand All @@ -668,6 +671,7 @@ fn test_char_at() {
}

#[test]
#[allow(deprecated)]
fn test_char_at_reverse() {
let s = "ศไทย中华Việt Nam";
let v = vec!['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
Expand Down Expand Up @@ -745,6 +749,7 @@ fn test_total_ord() {
}

#[test]
#[allow(deprecated)]
fn test_char_range_at() {
let data = "b¢€𤭢𤭢€¢b";
assert_eq!('b', data.char_range_at(0).ch);
Expand All @@ -758,6 +763,7 @@ fn test_char_range_at() {
}

#[test]
#[allow(deprecated)]
fn test_char_range_at_reverse_underflow() {
assert_eq!("abc".char_range_at_reverse(0).next, 0);
}
Expand Down
Loading

0 comments on commit 552eda7

Please sign in to comment.