Permalink
Browse files

std: Stabilize APIs for the 1.9 release

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 #27719
cc #27751 (deprecating the `Slice` bits)
Closes #27754
Closes #27780
Closes #27809
Closes #27811
Closes #27830
Closes #28050
Closes #29453
Closes #29791
Closes #29935
Closes #30014
Closes #30752
Closes #31262
cc #31398 (still need to deal with `before_exec`)
Closes #31405
Closes #31572
Closes #31755
Closes #31756
  • Loading branch information...
alexcrichton committed Apr 7, 2016
1 parent 8694b4f commit 552eda70d33cead1398adfecce1a75e7a61e3daf
Showing with 508 additions and 328 deletions.
  1. +20 −11 src/compiletest/compiletest.rs
  2. +1 −1 src/compiletest/errors.rs
  3. +3 −3 src/compiletest/runtest.rs
  4. +3 −3 src/libcollections/btree/set.rs
  5. +0 −2 src/libcollections/lib.rs
  6. +1 −2 src/libcollections/slice.rs
  7. +21 −8 src/libcollections/str.rs
  8. +11 −10 src/libcollections/string.rs
  9. +0 −3 src/libcollectionstest/lib.rs
  10. +6 −0 src/libcollectionstest/str.rs
  11. +37 −27 src/libcore/ptr.rs
  12. +10 −0 src/libcore/raw.rs
  13. +14 −8 src/libcore/slice.rs
  14. +23 −16 src/libcore/str/mod.rs
  15. +6 −1 src/libcoretest/char.rs
  16. +0 −3 src/libcoretest/lib.rs
  17. +4 −5 src/libgetopts/lib.rs
  18. +0 −1 src/librbml/lib.rs
  19. +7 −4 src/librustc/hir/print.rs
  20. +0 −2 src/librustc/lib.rs
  21. +3 −3 src/librustc/session/mod.rs
  22. +0 −1 src/librustc_back/lib.rs
  23. +3 −1 src/librustc_lint/bad_style.rs
  24. +0 −1 src/librustc_lint/lib.rs
  25. +38 −17 src/librustc_unicode/char.rs
  26. +0 −2 src/librustdoc/lib.rs
  27. +8 −13 src/librustdoc/test.rs
  28. +4 −1 src/libserialize/hex.rs
  29. +0 −1 src/libserialize/lib.rs
  30. +2 −6 src/libstd/ascii.rs
  31. +1 −2 src/libstd/collections/hash/map.rs
  32. +4 −5 src/libstd/collections/hash/set.rs
  33. +8 −3 src/libstd/error.rs
  34. +26 −26 src/libstd/ffi/os_str.rs
  35. +2 −5 src/libstd/fs.rs
  36. +1 −1 src/libstd/io/mod.rs
  37. +0 −2 src/libstd/lib.rs
  38. +32 −16 src/libstd/net/addr.rs
  39. +156 −66 src/libstd/panic.rs
  40. +1 −1 src/libstd/rt.rs
  41. +3 −3 src/libstd/sync/once.rs
  42. +1 −1 src/libstd/sys/common/backtrace.rs
  43. +4 −1 src/libstd/sys/common/wtf8.rs
  44. +3 −1 src/libstd/sys/unix/ext/mod.rs
  45. +3 −1 src/libstd/sys/unix/ext/process.rs
  46. +9 −5 src/libstd/sys/unix/ext/thread.rs
  47. +3 −1 src/libstd/sys/windows/ext/thread.rs
  48. +2 −2 src/libsyntax/feature_gate.rs
  49. +0 −1 src/libsyntax/lib.rs
  50. +6 −4 src/libsyntax/print/pprust.rs
  51. +6 −5 src/libsyntax_ext/asm.rs
  52. +0 −1 src/libsyntax_ext/lib.rs
  53. +1 −1 src/test/compile-fail/deprecation-in-staged-api.rs
  54. +0 −2 src/test/compile-fail/deprecation-lint.rs
  55. +0 −2 src/test/compile-fail/deprecation-sanity.rs
  56. +3 −3 src/test/compile-fail/not-panic-safe.rs
  57. +1 −4 src/test/compile-fail/placement-expr-unstable.rs
  58. +7 −7 src/test/run-pass/panic-safe.rs
@@ -13,7 +13,6 @@
#![feature(box_syntax)]
#![feature(libc)]
#![feature(rustc_private)]
#![feature(str_char)]
#![feature(test)]
#![feature(question_mark)]

@@ -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());
@@ -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| {
@@ -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())
@@ -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;
}
@@ -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;
}
@@ -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;
@@ -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
@@ -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)
}
@@ -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
@@ -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)]
@@ -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)
}
@@ -228,8 +228,6 @@ impl str {
/// # Examples
///
/// ```
/// #![feature(str_char)]
///
/// let s = "Löwe 老虎 Léopard";
/// assert!(s.is_char_boundary(0));
/// // start of `老`
@@ -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)
@@ -374,6 +367,7 @@ impl str {
///
/// ```
/// #![feature(str_char)]
/// #![allow(deprecated)]
///
/// use std::str::CharRange;
///
@@ -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)
}
@@ -432,6 +429,7 @@ impl str {
///
/// ```
/// #![feature(str_char)]
/// #![allow(deprecated)]
///
/// use std::str::CharRange;
///
@@ -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)
}
@@ -481,6 +482,7 @@ impl str {
///
/// ```
/// #![feature(str_char)]
/// #![allow(deprecated)]
///
/// let s = "abπc";
/// assert_eq!(s.char_at(1), 'b');
@@ -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)
}
@@ -511,6 +516,7 @@ impl str {
///
/// ```
/// #![feature(str_char)]
/// #![allow(deprecated)]
///
/// let s = "abπc";
/// assert_eq!(s.char_at_reverse(1), 'a');
@@ -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)
}
@@ -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();
@@ -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)
}
@@ -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)
}
@@ -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),
@@ -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)]
@@ -25,7 +23,6 @@
#![feature(map_values_mut)]
#![feature(pattern)]
#![feature(rand)]
#![feature(set_recovery)]
#![feature(step_by)]
#![feature(str_char)]
#![feature(str_escape)]
@@ -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);
@@ -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'];
@@ -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'];
@@ -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);
@@ -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);
}
Oops, something went wrong.

0 comments on commit 552eda7

Please sign in to comment.