提交 b64c9d56 编写于 作者: A Alex Crichton

std: Clean out old unstable + deprecated APIs

These should all have been deprecated for at least one cycle, so this commit
cleans them all out.
上级 a967611d
......@@ -112,11 +112,6 @@ fn connect(&self, sep: &str) -> String {
}
}
/// Deprecated, renamed to EncodeUtf16
#[unstable(feature = "str_utf16", issue = "27714")]
#[rustc_deprecated(since = "1.8.0", reason = "renamed to EncodeUtf16")]
pub type Utf16Units<'a> = EncodeUtf16<'a>;
/// External iterator for a string's UTF-16 code units.
///
/// For use with the `std::iter` module.
......@@ -352,230 +347,6 @@ pub unsafe fn slice_mut_unchecked(&mut self, begin: usize, end: usize) -> &mut s
core_str::StrExt::slice_mut_unchecked(self, begin, end)
}
/// Given a byte position, returns the next `char` and its index.
///
/// # Panics
///
/// If `i` is greater than or equal to the length of the string.
/// If `i` is not the index of the beginning of a valid UTF-8 sequence.
///
/// # Examples
///
/// This example manually iterates through the code points of a string;
/// this should normally be
/// done by `.chars()` or `.char_indices()`.
///
/// ```
/// #![feature(str_char)]
/// #![allow(deprecated)]
///
/// use std::str::CharRange;
///
/// let s = "中华Việt Nam";
/// let mut i = 0;
/// while i < s.len() {
/// let CharRange {ch, next} = s.char_range_at(i);
/// println!("{}: {}", i, ch);
/// i = next;
/// }
/// ```
///
/// This outputs:
///
/// ```text
/// 0: 中
/// 3: 华
/// 6: V
/// 7: i
/// 8: e
/// 9:
/// 11:
/// 13: t
/// 14:
/// 15: N
/// 16: a
/// 17: m
/// ```
#[unstable(feature = "str_char",
reason = "often replaced by char_indices, this method may \
be removed in favor of just char_at() or eventually \
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)
}
/// Given a byte position, returns the previous `char` and its position.
///
/// Note that Unicode has many features, such as combining marks, ligatures,
/// and direction marks, that need to be taken into account to correctly reverse a string.
///
/// Returns 0 for next index if called on start index 0.
///
/// # Panics
///
/// If `i` is greater than the length of the string.
/// If `i` is not an index following a valid UTF-8 sequence.
///
/// # Examples
///
/// This example manually iterates through the code points of a string;
/// this should normally be
/// done by `.chars().rev()` or `.char_indices()`.
///
/// ```
/// #![feature(str_char)]
/// #![allow(deprecated)]
///
/// use std::str::CharRange;
///
/// let s = "中华Việt Nam";
/// let mut i = s.len();
/// while i > 0 {
/// let CharRange {ch, next} = s.char_range_at_reverse(i);
/// println!("{}: {}", i, ch);
/// i = next;
/// }
/// ```
///
/// This outputs:
///
/// ```text
/// 18: m
/// 17: a
/// 16: N
/// 15:
/// 14: t
/// 13:
/// 11:
/// 9: e
/// 8: i
/// 7: V
/// 6: 华
/// 3: 中
/// ```
#[unstable(feature = "str_char",
reason = "often replaced by char_indices, this method may \
be removed in favor of just char_at_reverse() or \
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)
}
/// Given a byte position, returns the `char` at that position.
///
/// # Panics
///
/// If `i` is greater than or equal to the length of the string.
/// If `i` is not the index of the beginning of a valid UTF-8 sequence.
///
/// # Examples
///
/// ```
/// #![feature(str_char)]
/// #![allow(deprecated)]
///
/// let s = "abπc";
/// assert_eq!(s.char_at(1), 'b');
/// assert_eq!(s.char_at(2), 'π');
/// assert_eq!(s.char_at(4), 'c');
/// ```
#[unstable(feature = "str_char",
reason = "frequently replaced by the chars() iterator, this \
method may be removed or possibly renamed in the \
future; it is normally replaced by chars/char_indices \
iterators or by getting the first char from a \
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)
}
/// Given a byte position, returns the `char` at that position, counting
/// from the end.
///
/// # Panics
///
/// If `i` is greater than the length of the string.
/// If `i` is not an index following a valid UTF-8 sequence.
///
/// # Examples
///
/// ```
/// #![feature(str_char)]
/// #![allow(deprecated)]
///
/// let s = "abπc";
/// assert_eq!(s.char_at_reverse(1), 'a');
/// assert_eq!(s.char_at_reverse(2), 'b');
/// assert_eq!(s.char_at_reverse(3), 'π');
/// ```
#[unstable(feature = "str_char",
reason = "see char_at for more details, but reverse semantics \
are also somewhat unclear, especially with which \
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)
}
/// Retrieves the first `char` from a `&str` and returns it.
///
/// Note that a single Unicode character (grapheme cluster)
/// can be composed of multiple `char`s.
///
/// This does not allocate a new string; instead, it returns a slice that
/// points one code point beyond the code point that was shifted.
///
/// `None` is returned if the slice is empty.
///
/// # Examples
///
/// ```
/// #![feature(str_char)]
/// #![allow(deprecated)]
///
/// let s = "Łódź"; // \u{141}o\u{301}dz\u{301}
/// let (c, s1) = s.slice_shift_char().unwrap();
///
/// assert_eq!(c, 'Ł');
/// assert_eq!(s1, "ódź");
///
/// let (c, s2) = s1.slice_shift_char().unwrap();
///
/// assert_eq!(c, 'o');
/// assert_eq!(s2, "\u{301}dz\u{301}");
/// ```
#[unstable(feature = "str_char",
reason = "awaiting conventions about shifting and slices and \
may not be warranted with the existence of the chars \
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)
}
/// Divide one string slice into two at an index.
///
/// The argument, `mid`, should be a byte offset from the start of the
......@@ -867,16 +638,6 @@ pub fn lines_any(&self) -> LinesAny {
core_str::StrExt::lines_any(self)
}
/// Returns an iterator of `u16` over the string encoded as UTF-16.
#[unstable(feature = "str_utf16",
reason = "this functionality may only be provided by libunicode",
issue = "27714")]
#[rustc_deprecated(since = "1.8.0", reason = "renamed to encode_utf16")]
#[allow(deprecated)]
pub fn utf16_units(&self) -> Utf16Units {
Utf16Units { encoder: Utf16Encoder::new(self[..].chars()) }
}
/// Returns an iterator of `u16` over the string encoded as UTF-16.
#[stable(feature = "encode_utf16", since = "1.8.0")]
pub fn encode_utf16(&self) -> EncodeUtf16 {
......
......@@ -25,7 +25,6 @@
#![feature(pattern)]
#![feature(rand)]
#![feature(step_by)]
#![feature(str_char)]
#![feature(str_escape)]
#![feature(test)]
#![feature(unboxed_closures)]
......
......@@ -479,20 +479,6 @@ fn test_is_whitespace() {
assert!(!" _ ".chars().all(|c| c.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);
}
#[test]
fn test_is_utf8() {
// deny overlong encodings
......@@ -674,30 +660,6 @@ fn test_contains_char() {
assert!(!"".contains('a'));
}
#[test]
#[allow(deprecated)]
fn test_char_at() {
let s = "ศไทย中华Việt Nam";
let v = vec!['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
let mut pos = 0;
for ch in &v {
assert!(s.char_at(pos) == *ch);
pos += ch.to_string().len();
}
}
#[test]
#[allow(deprecated)]
fn test_char_at_reverse() {
let s = "ศไทย中华Việt Nam";
let v = vec!['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m'];
let mut pos = s.len();
for ch in v.iter().rev() {
assert!(s.char_at_reverse(pos) == *ch);
pos -= ch.to_string().len();
}
}
#[test]
fn test_split_at() {
let s = "ศไทย中华Việt Nam";
......@@ -764,26 +726,6 @@ fn test_total_ord() {
assert_eq!("22".cmp("1234"), Greater);
}
#[test]
#[allow(deprecated)]
fn test_char_range_at() {
let data = "b¢€𤭢𤭢€¢b";
assert_eq!('b', data.char_range_at(0).ch);
assert_eq!('¢', data.char_range_at(1).ch);
assert_eq!('€', data.char_range_at(3).ch);
assert_eq!('𤭢', data.char_range_at(6).ch);
assert_eq!('𤭢', data.char_range_at(10).ch);
assert_eq!('€', data.char_range_at(14).ch);
assert_eq!('¢', data.char_range_at(17).ch);
assert_eq!('b', data.char_range_at(19).ch);
}
#[test]
#[allow(deprecated)]
fn test_char_range_at_reverse_underflow() {
assert_eq!("abc".char_range_at_reverse(0).next, 0);
}
#[test]
fn test_iterator() {
let s = "ศไทย中华Việt Nam";
......
......@@ -692,40 +692,6 @@ pub fn map<U: ?Sized, F>(orig: Ref<'b, T>, f: F) -> Ref<'b, U>
borrow: orig.borrow,
}
}
/// Make a new `Ref` for an optional component of the borrowed data, e.g. an
/// enum variant.
///
/// The `RefCell` is already immutably borrowed, so this cannot fail.
///
/// This is an associated function that needs to be used as
/// `Ref::filter_map(...)`. A method would interfere with methods of the
/// same name on the contents of a `RefCell` used through `Deref`.
///
/// # Example
///
/// ```
/// # #![feature(cell_extras)]
/// use std::cell::{RefCell, Ref};
///
/// let c = RefCell::new(Ok(5));
/// let b1: Ref<Result<u32, ()>> = c.borrow();
/// let b2: Ref<u32> = Ref::filter_map(b1, |o| o.as_ref().ok()).unwrap();
/// assert_eq!(*b2, 5)
/// ```
#[unstable(feature = "cell_extras", reason = "recently added",
issue = "27746")]
#[rustc_deprecated(since = "1.8.0", reason = "can be built on `Ref::map`: \
https://crates.io/crates/ref_filter_map")]
#[inline]
pub fn filter_map<U: ?Sized, F>(orig: Ref<'b, T>, f: F) -> Option<Ref<'b, U>>
where F: FnOnce(&T) -> Option<&U>
{
f(orig.value).map(move |new| Ref {
value: new,
borrow: orig.borrow,
})
}
}
#[unstable(feature = "coerce_unsized", issue = "27732")]
......@@ -765,47 +731,6 @@ pub fn map<U: ?Sized, F>(orig: RefMut<'b, T>, f: F) -> RefMut<'b, U>
borrow: orig.borrow,
}
}
/// Make a new `RefMut` for an optional component of the borrowed data, e.g.
/// an enum variant.
///
/// The `RefCell` is already mutably borrowed, so this cannot fail.
///
/// This is an associated function that needs to be used as
/// `RefMut::filter_map(...)`. A method would interfere with methods of the
/// same name on the contents of a `RefCell` used through `Deref`.
///
/// # Example
///
/// ```
/// # #![feature(cell_extras)]
/// use std::cell::{RefCell, RefMut};
///
/// let c = RefCell::new(Ok(5));
/// {
/// let b1: RefMut<Result<u32, ()>> = c.borrow_mut();
/// let mut b2: RefMut<u32> = RefMut::filter_map(b1, |o| {
/// o.as_mut().ok()
/// }).unwrap();
/// assert_eq!(*b2, 5);
/// *b2 = 42;
/// }
/// assert_eq!(*c.borrow(), Ok(42));
/// ```
#[unstable(feature = "cell_extras", reason = "recently added",
issue = "27746")]
#[rustc_deprecated(since = "1.8.0", reason = "can be built on `RefMut::map`: \
https://crates.io/crates/ref_filter_map")]
#[inline]
pub fn filter_map<U: ?Sized, F>(orig: RefMut<'b, T>, f: F) -> Option<RefMut<'b, U>>
where F: FnOnce(&mut T) -> Option<&mut U>
{
let RefMut { value, borrow } = orig;
f(value).map(move |new| RefMut {
value: new,
borrow: borrow,
})
}
}
struct BorrowRefMut<'b> {
......
......@@ -18,63 +18,6 @@
//!
//! Their definition should always match the ABI defined in `rustc::back::abi`.
use clone::Clone;
use marker::Copy;
use mem;
/// The representation of a slice like `&[T]`.
///
/// This struct is guaranteed to have the layout of types like `&[T]`,
/// `&str`, and `Box<[T]>`, but is not the type of such slices
/// (e.g. the fields are not directly accessible on a `&[T]`) nor does
/// it control that layout (changing the definition will not change
/// the layout of a `&[T]`). It is only designed to be used by unsafe
/// code that needs to manipulate the low-level details.
///
/// However, it is not recommended to use this type for such code,
/// since there are alternatives which may be safer:
///
/// - Creating a slice from a data pointer and length can be done with
/// `std::slice::from_raw_parts` or `std::slice::from_raw_parts_mut`
/// instead of `std::mem::transmute`ing a value of type `Slice`.
/// - Extracting the data pointer and length from a slice can be
/// performed with the `as_ptr` (or `as_mut_ptr`) and `len`
/// methods.
///
/// If one does decide to convert a slice value to a `Slice`, the
/// `Repr` trait in this module provides a method for a safe
/// conversion from `&[T]` (and `&str`) to a `Slice`, more type-safe
/// than a call to `transmute`.
///
/// # Examples
///
/// ```
/// #![feature(raw)]
///
/// use std::raw::{self, Repr};
///
/// let slice: &[u16] = &[1, 2, 3, 4];
///
/// let repr: raw::Slice<u16> = slice.repr();
/// println!("data pointer = {:?}, length = {}", repr.data, repr.len);
/// ```
#[repr(C)]
#[allow(missing_debug_implementations)]
#[rustc_deprecated(reason = "use raw accessors/constructors in `slice` module",
since = "1.9.0")]
#[unstable(feature = "raw", issue = "27751")]
pub struct Slice<T> {
pub data: *const T,
pub len: usize,
}
#[allow(deprecated)]
impl<T> Copy for Slice<T> {}
#[allow(deprecated)]
impl<T> Clone for Slice<T> {
fn clone(&self) -> Slice<T> { *self }
}
/// The representation of a trait object like `&SomeTrait`.
///
/// This struct has the same layout as types like `&SomeTrait` and
......@@ -154,22 +97,3 @@ pub struct TraitObject {
pub data: *mut (),
pub vtable: *mut (),
}
/// This trait is meant to map equivalences between raw structs and their
/// corresponding rust values.
#[rustc_deprecated(reason = "use raw accessors/constructors in `slice` module",
since = "1.9.0")]
#[unstable(feature = "raw", issue = "27751")]
pub unsafe trait Repr<T> {
/// This function "unwraps" a rust value (without consuming it) into its raw
/// struct representation. This can be used to read/write different values
/// for the struct. This is a safe method because by default it does not
/// enable write-access to the fields of the return value in safe code.
#[inline]
fn repr(&self) -> T { unsafe { mem::transmute_copy(&self) } }
}
#[allow(deprecated)]
unsafe impl<T> Repr<Slice<T>> for [T] {}
#[allow(deprecated)]
unsafe impl Repr<Slice<u8>> for str {}
......@@ -17,7 +17,7 @@
use self::pattern::Pattern;
use self::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher};
use char::{self, CharExt};
use char;
use clone::Clone;
use convert::AsRef;
use default::Default;
......@@ -1663,40 +1663,6 @@ fn trim_right_matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> &'a str
where P::Searcher: ReverseSearcher<'a>;
#[stable(feature = "is_char_boundary", since = "1.9.0")]
fn is_char_boundary(&self, index: usize) -> bool;
#[unstable(feature = "str_char",
reason = "often replaced by char_indices, this method may \
be removed in favor of just char_at() or eventually \
removed altogether",
issue = "27754")]
#[rustc_deprecated(reason = "use slicing plus chars() plus len_utf8",
since = "1.9.0")]
fn char_range_at(&self, start: usize) -> CharRange;
#[unstable(feature = "str_char",
reason = "often replaced by char_indices, this method may \
be removed in favor of just char_at_reverse() or \
eventually removed altogether",
issue = "27754")]
#[rustc_deprecated(reason = "use slicing plus chars().rev() plus len_utf8",
since = "1.9.0")]
fn char_range_at_reverse(&self, start: usize) -> CharRange;
#[unstable(feature = "str_char",
reason = "frequently replaced by the chars() iterator, this \
method may be removed or possibly renamed in the \
future; it is normally replaced by chars/char_indices \
iterators or by getting the first char from a \
subslice",
issue = "27754")]
#[rustc_deprecated(reason = "use slicing plus chars()",
since = "1.9.0")]
fn char_at(&self, i: usize) -> char;
#[unstable(feature = "str_char",
reason = "see char_at for more details, but reverse semantics \
are also somewhat unclear, especially with which \
cases generate panics",
issue = "27754")]
#[rustc_deprecated(reason = "use slicing plus chars().rev()",
since = "1.9.0")]
fn char_at_reverse(&self, i: usize) -> char;
#[stable(feature = "core", since = "1.6.0")]
fn as_bytes(&self) -> &[u8];
#[stable(feature = "core", since = "1.6.0")]
......@@ -1709,14 +1675,6 @@ fn rfind<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option<usize>
fn split_at(&self, mid: usize) -> (&str, &str);
#[stable(feature = "core", since = "1.6.0")]
fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str);
#[unstable(feature = "str_char",
reason = "awaiting conventions about shifting and slices and \
may not be warranted with the existence of the chars \
and/or char_indices iterators",
issue = "27754")]
#[rustc_deprecated(reason = "use chars() plus Chars::as_str",
since = "1.9.0")]
fn slice_shift_char(&self) -> Option<(char, &str)>;
#[stable(feature = "core", since = "1.6.0")]
fn as_ptr(&self) -> *const u8;
#[stable(feature = "core", since = "1.6.0")]
......@@ -1945,55 +1903,6 @@ fn is_char_boundary(&self, index: usize) -> bool {
}
}
#[inline]
fn char_range_at(&self, i: usize) -> CharRange {
let (c, n) = char_range_at_raw(self.as_bytes(), i);
CharRange { ch: unsafe { char::from_u32_unchecked(c) }, next: n }
}
#[inline]
fn char_range_at_reverse(&self, start: usize) -> CharRange {
let mut prev = start;
prev = prev.saturating_sub(1);
if self.as_bytes()[prev] < 128 {
return CharRange{ch: self.as_bytes()[prev] as char, next: prev}
}
// Multibyte case is a fn to allow char_range_at_reverse to inline cleanly
fn multibyte_char_range_at_reverse(s: &str, mut i: usize) -> CharRange {
// while there is a previous byte == 10......
while i > 0 && s.as_bytes()[i] & !CONT_MASK == TAG_CONT_U8 {
i -= 1;
}
let first= s.as_bytes()[i];
let w = UTF8_CHAR_WIDTH[first as usize];
assert!(w != 0);
let mut val = utf8_first_byte(first, w as u32);
val = utf8_acc_cont_byte(val, s.as_bytes()[i + 1]);
if w > 2 { val = utf8_acc_cont_byte(val, s.as_bytes()[i + 2]); }
if w > 3 { val = utf8_acc_cont_byte(val, s.as_bytes()[i + 3]); }
CharRange {ch: unsafe { char::from_u32_unchecked(val) }, next: i}
}
multibyte_char_range_at_reverse(self, prev)
}
#[inline]
#[allow(deprecated)]
fn char_at(&self, i: usize) -> char {
self.char_range_at(i).ch
}
#[inline]
#[allow(deprecated)]
fn char_at_reverse(&self, i: usize) -> char {
self.char_range_at_reverse(i).ch
}
#[inline]
fn as_bytes(&self) -> &[u8] {
unsafe { mem::transmute(self) }
......@@ -2040,18 +1949,6 @@ fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str) {
}
}
#[inline]
#[allow(deprecated)]
fn slice_shift_char(&self) -> Option<(char, &str)> {
if self.is_empty() {
None
} else {
let ch = self.char_at(0);
let next_s = unsafe { self.slice_unchecked(ch.len_utf8(), self.len()) };
Some((ch, next_s))
}
}
#[inline]
fn as_ptr(&self) -> *const u8 {
self as *const str as *const u8
......@@ -2077,31 +1974,6 @@ fn as_ref(&self) -> &[u8] {
}
}
/// Pluck a code point out of a UTF-8-like byte slice and return the
/// index of the next code point.
#[inline]
fn char_range_at_raw(bytes: &[u8], i: usize) -> (u32, usize) {
if bytes[i] < 128 {
return (bytes[i] as u32, i + 1);
}
// Multibyte case is a fn to allow char_range_at to inline cleanly
fn multibyte_char_range_at(bytes: &[u8], i: usize) -> (u32, usize) {
let first = bytes[i];
let w = UTF8_CHAR_WIDTH[first as usize];
assert!(w != 0);
let mut val = utf8_first_byte(first, w as u32);
val = utf8_acc_cont_byte(val, bytes[i + 1]);
if w > 2 { val = utf8_acc_cont_byte(val, bytes[i + 2]); }
if w > 3 { val = utf8_acc_cont_byte(val, bytes[i + 3]); }
(val, i + w as usize)
}
multibyte_char_range_at(bytes, i)
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Default for &'a str {
fn default() -> &'a str { "" }
......
......@@ -158,20 +158,6 @@ fn accessor(&self) -> Ref<u32> {
assert_eq!(*d, 7);
}
#[test]
#[allow(deprecated)]
fn ref_filter_map_accessor() {
struct X(RefCell<Result<u32, ()>>);
impl X {
fn accessor(&self) -> Option<Ref<u32>> {
Ref::filter_map(self.0.borrow(), |r| r.as_ref().ok())
}
}
let x = X(RefCell::new(Ok(7)));
let d: Ref<u32> = x.accessor().unwrap();
assert_eq!(*d, 7);
}
#[test]
fn ref_mut_map_accessor() {
struct X(RefCell<(u32, char)>);
......@@ -189,24 +175,6 @@ fn accessor(&self) -> RefMut<u32> {
assert_eq!(*x.0.borrow(), (8, 'z'));
}
#[test]
#[allow(deprecated)]
fn ref_mut_filter_map_accessor() {
struct X(RefCell<Result<u32, ()>>);
impl X {
fn accessor(&self) -> Option<RefMut<u32>> {
RefMut::filter_map(self.0.borrow_mut(), |r| r.as_mut().ok())
}
}
let x = X(RefCell::new(Ok(7)));
{
let mut d: RefMut<u32> = x.accessor().unwrap();
assert_eq!(*d, 7);
*d += 1;
}
assert_eq!(*x.0.borrow(), Ok(8));
}
#[test]
fn as_unsafe_cell() {
let c1: Cell<usize> = Cell::new(0);
......
......@@ -25,21 +25,7 @@
#[stable(feature = "panic_hooks", since = "1.10.0")]
pub use panicking::{take_hook, set_hook, PanicInfo, Location};
///
#[rustc_deprecated(since = "1.9.0", reason = "renamed to set_hook")]
#[unstable(feature = "panic_handler", reason = "awaiting feedback", issue = "30449")]
pub fn set_handler<F>(handler: F) where F: Fn(&PanicInfo) + 'static + Sync + Send {
set_hook(Box::new(handler))
}
///
#[rustc_deprecated(since = "1.9.0", reason = "renamed to take_hook")]
#[unstable(feature = "panic_handler", reason = "awaiting feedback", issue = "30449")]
pub fn take_handler() -> Box<Fn(&PanicInfo) + 'static + Sync + Send> {
take_hook()
}
/// A marker trait which represents "unwind safe" types in Rust.
/// A marker trait which represents "panic safe" types in Rust.
///
/// This trait is implemented by default for many types and behaves similarly in
/// terms of inference of implementation to the `Send` and `Sync` traits. The
......@@ -117,14 +103,6 @@ pub fn take_handler() -> Box<Fn(&PanicInfo) + 'static + Sync + Send> {
across an unwind boundary"]
pub trait UnwindSafe {}
/// Deprecated, renamed to UnwindSafe
#[unstable(feature = "recover", reason = "awaiting feedback", issue = "27719")]
#[rustc_deprecated(reason = "renamed to `UnwindSafe`", since = "1.9.0")]
pub trait RecoverSafe {}
#[unstable(feature = "recover", reason = "awaiting feedback", issue = "27719")]
#[allow(deprecated)]
impl<T: UnwindSafe> RecoverSafe for T {}
/// A marker trait representing types where a shared reference is considered
/// unwind safe.
///
......@@ -202,11 +180,6 @@ pub struct AssertUnwindSafe<T>(
pub T
);
/// Deprecated, renamed to `AssertUnwindSafe`
#[unstable(feature = "recover", issue = "27719")]
#[rustc_deprecated(reason = "renamed to `AssertUnwindSafe`", since = "1.9.0")]
pub struct AssertRecoverSafe<T>(pub T);
// Implementations of the `UnwindSafe` trait:
//
// * By default everything is unwind safe
......@@ -234,9 +207,6 @@ impl<T: ?Sized> UnwindSafe for Mutex<T> {}
impl<T: ?Sized> UnwindSafe for RwLock<T> {}
#[stable(feature = "catch_unwind", since = "1.9.0")]
impl<T> UnwindSafe for AssertUnwindSafe<T> {}
#[unstable(feature = "recover", issue = "27719")]
#[allow(deprecated)]
impl<T> UnwindSafe for AssertRecoverSafe<T> {}
// not covered via the Shared impl above b/c the inner contents use
// Cell/AtomicUsize, but the usage here is unwind safe so we can lift the
......@@ -256,9 +226,6 @@ impl RefUnwindSafe for .. {}
impl<T: ?Sized> !RefUnwindSafe for UnsafeCell<T> {}
#[stable(feature = "catch_unwind", since = "1.9.0")]
impl<T> RefUnwindSafe for AssertUnwindSafe<T> {}
#[unstable(feature = "recover", issue = "27719")]
#[allow(deprecated)]
impl<T> RefUnwindSafe for AssertRecoverSafe<T> {}
#[stable(feature = "catch_unwind", since = "1.9.0")]
impl<T> Deref for AssertUnwindSafe<T> {
......@@ -285,53 +252,6 @@ extern "rust-call" fn call_once(self, _args: ()) -> R {
}
}
#[allow(deprecated)]
impl<T> AssertRecoverSafe<T> {
/// Creates a new `AssertRecoverSafe` wrapper around the provided type.
#[unstable(feature = "recover", reason = "awaiting feedback", issue = "27719")]
#[rustc_deprecated(reason = "the type's field is now public, construct it directly",
since = "1.9.0")]
pub fn new(t: T) -> AssertRecoverSafe<T> {
AssertRecoverSafe(t)
}
/// Consumes the `AssertRecoverSafe`, returning the wrapped value.
#[unstable(feature = "recover", reason = "awaiting feedback", issue = "27719")]
#[rustc_deprecated(reason = "the type's field is now public, access it directly",
since = "1.9.0")]
pub fn into_inner(self) -> T {
self.0
}
}
#[unstable(feature = "recover", issue = "27719")]
#[allow(deprecated)]
impl<T> Deref for AssertRecoverSafe<T> {
type Target = T;
fn deref(&self) -> &T {
&self.0
}
}
#[unstable(feature = "recover", issue = "27719")]
#[allow(deprecated)]
impl<T> DerefMut for AssertRecoverSafe<T> {
fn deref_mut(&mut self) -> &mut T {
&mut self.0
}
}
#[unstable(feature = "recover", issue = "27719")]
#[allow(deprecated)]
impl<R, F: FnOnce() -> R> FnOnce<()> for AssertRecoverSafe<F> {
type Output = R;
extern "rust-call" fn call_once(self, _args: ()) -> R {
(self.0)()
}
}
/// Invokes a closure, capturing the cause of an unwinding panic if one occurs.
///
/// This function will return `Ok` with the closure's result if the closure
......@@ -388,13 +308,6 @@ pub fn catch_unwind<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Result<R> {
}
}
/// Deprecated, renamed to `catch_unwind`
#[unstable(feature = "recover", reason = "awaiting feedback", issue = "27719")]
#[rustc_deprecated(reason = "renamed to `catch_unwind`", since = "1.9.0")]
pub fn recover<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Result<R> {
catch_unwind(f)
}
/// Triggers a panic without invoking the panic hook.
///
/// This is designed to be used in conjunction with `catch_unwind` to, for
......@@ -424,10 +337,3 @@ pub fn recover<F: FnOnce() -> R + UnwindSafe, R>(f: F) -> Result<R> {
pub fn resume_unwind(payload: Box<Any + Send>) -> ! {
panicking::rust_panic(payload)
}
/// Deprecated, use resume_unwind instead
#[unstable(feature = "panic_propagate", reason = "awaiting feedback", issue = "30752")]
#[rustc_deprecated(reason = "renamed to `resume_unwind`", since = "1.9.0")]
pub fn propagate(payload: Box<Any + Send>) -> ! {
resume_unwind(payload)
}
......@@ -468,42 +468,6 @@ unsafe fn new(lock: &'rwlock StaticRwLock, data: &'rwlock UnsafeCell<T>)
}
})
}
/// Transform this guard to hold a sub-borrow of the original data.
///
/// Applies the supplied closure to the data, returning a new lock
/// guard referencing the borrow returned by the closure.
///
/// # Examples
///
/// ```rust
/// # #![feature(guard_map)]
/// # use std::sync::{RwLockReadGuard, RwLock};
/// let x = RwLock::new(vec![1, 2]);
///
/// let y = RwLockReadGuard::map(x.read().unwrap(), |v| &v[0]);
/// assert_eq!(*y, 1);
/// ```
#[unstable(feature = "guard_map",
reason = "recently added, needs RFC for stabilization,
questionable interaction with Condvar",
issue = "27746")]
#[rustc_deprecated(since = "1.8.0",
reason = "unsound on Mutex because of Condvar and \
RwLock may also with to be used with Condvar \
one day")]
pub fn map<U: ?Sized, F>(this: Self, cb: F) -> RwLockReadGuard<'rwlock, U>
where F: FnOnce(&T) -> &U
{
let new = RwLockReadGuard {
__lock: this.__lock,
__data: cb(this.__data)
};
mem::forget(this);
new
}
}
#[allow(deprecated)]
......@@ -518,57 +482,6 @@ unsafe fn new(lock: &'rwlock StaticRwLock, data: &'rwlock UnsafeCell<T>)
}
})
}
/// Transform this guard to hold a sub-borrow of the original data.
///
/// Applies the supplied closure to the data, returning a new lock
/// guard referencing the borrow returned by the closure.
///
/// # Examples
///
/// ```rust
/// # #![feature(guard_map)]
/// # use std::sync::{RwLockWriteGuard, RwLock};
/// let x = RwLock::new(vec![1, 2]);
///
/// {
/// let mut y = RwLockWriteGuard::map(x.write().unwrap(), |v| &mut v[0]);
/// assert_eq!(*y, 1);
///
/// *y = 10;
/// }
///
/// assert_eq!(&**x.read().unwrap(), &[10, 2]);
/// ```
#[unstable(feature = "guard_map",
reason = "recently added, needs RFC for stabilization,
questionable interaction with Condvar",
issue = "27746")]
#[rustc_deprecated(since = "1.8.0",
reason = "unsound on Mutex because of Condvar and \
RwLock may also with to be used with Condvar \
one day")]
pub fn map<U: ?Sized, F>(this: Self, cb: F) -> RwLockWriteGuard<'rwlock, U>
where F: FnOnce(&mut T) -> &mut U
{
// Compute the new data while still owning the original lock
// in order to correctly poison if the callback panics.
let data = unsafe { ptr::read(&this.__data) };
let new_data = cb(data);
// We don't want to unlock the lock by running the destructor of the
// original lock, so just read the fields we need and forget it.
let (poison, lock) = unsafe {
(ptr::read(&this.__poison), ptr::read(&this.__lock))
};
mem::forget(this);
RwLockWriteGuard {
__lock: lock,
__data: new_data,
__poison: poison
}
}
}
#[stable(feature = "rust1", since = "1.0.0")]
......@@ -619,7 +532,7 @@ mod tests {
use rand::{self, Rng};
use sync::mpsc::channel;
use thread;
use sync::{Arc, RwLock, StaticRwLock, TryLockError, RwLockWriteGuard};
use sync::{Arc, RwLock, StaticRwLock, TryLockError};
use sync::atomic::{AtomicUsize, Ordering};
#[derive(Eq, PartialEq, Debug)]
......@@ -867,20 +780,4 @@ fn test_get_mut_poison() {
Ok(x) => panic!("get_mut of poisoned RwLock is Ok: {:?}", x),
}
}
#[test]
fn test_rwlock_write_map_poison() {
let rwlock = Arc::new(RwLock::new(vec![1, 2]));
let rwlock2 = rwlock.clone();
thread::spawn(move || {
let _ = RwLockWriteGuard::map::<usize, _>(rwlock2.write().unwrap(), |_| panic!());
}).join().unwrap_err();
match rwlock.read() {
Ok(r) => panic!("Read lock on poisioned RwLock is Ok: {:?}", &*r),
Err(_) => {}
};
}
}
......@@ -34,21 +34,6 @@ pub trait CommandExt {
#[stable(feature = "rust1", since = "1.0.0")]
fn gid(&mut self, id: u32) -> &mut process::Command;
/// Create a new session (cf. `setsid(2)`) for the child process. This means
/// that the child is the leader of a new process group. The parent process
/// remains the child reaper of the new process.
///
/// This is not enough to create a daemon process. The *init* process should
/// be the child reaper of a daemon. This can be achieved if the parent
/// process exit. Moreover, a daemon should not have a controlling terminal.
/// To achieve this, a session leader (the child) must spawn another process
/// (the daemon) in the same session.
#[unstable(feature = "process_session_leader", reason = "recently added",
issue = "27811")]
#[rustc_deprecated(reason = "use `before_exec` instead",
since = "1.9.0")]
fn session_leader(&mut self, on: bool) -> &mut process::Command;
/// Schedules a closure to be run just before the `exec` function is
/// invoked.
///
......@@ -112,11 +97,6 @@ fn gid(&mut self, id: u32) -> &mut process::Command {
self
}
fn session_leader(&mut self, on: bool) -> &mut process::Command {
self.as_inner_mut().session_leader(on);
self
}
fn before_exec<F>(&mut self, f: F) -> &mut process::Command
where F: FnMut() -> io::Result<()> + Send + Sync + 'static
{
......
......@@ -55,7 +55,6 @@ pub struct Command {
cwd: Option<CString>,
uid: Option<uid_t>,
gid: Option<gid_t>,
session_leader: bool,
saw_nul: bool,
closures: Vec<Box<FnMut() -> io::Result<()> + Send + Sync>>,
stdin: Option<Stdio>,
......@@ -105,7 +104,6 @@ pub fn new(program: &OsStr) -> Command {
cwd: None,
uid: None,
gid: None,
session_leader: false,
saw_nul: saw_nul,
closures: Vec::new(),
stdin: None,
......@@ -197,9 +195,6 @@ pub fn uid(&mut self, id: uid_t) {
pub fn gid(&mut self, id: gid_t) {
self.gid = Some(id);
}
pub fn session_leader(&mut self, session_leader: bool) {
self.session_leader = session_leader;
}
pub fn before_exec(&mut self,
f: Box<FnMut() -> io::Result<()> + Send + Sync>) {
......@@ -367,12 +362,6 @@ unsafe fn do_exec(&mut self, stdio: ChildPipes) -> io::Error {
t!(cvt(libc::setuid(u as uid_t)));
}
if self.session_leader {
// Don't check the error of setsid because it fails if we're the
// process leader already. We just forked so it shouldn't return
// error, but ignore it anyway.
let _ = libc::setsid();
}
if let Some(ref cwd) = self.cwd {
t!(cvt(libc::chdir(cwd.as_ptr())));
}
......
......@@ -183,25 +183,15 @@
////////////////////////////////////////////////////////////////////////////////
#[macro_use] mod local;
#[macro_use] mod scoped_tls;
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::local::{LocalKey, LocalKeyState};
#[unstable(feature = "scoped_tls",
reason = "scoped TLS has yet to have wide enough use to fully \
consider stabilizing its interface",
issue = "27715")]
#[allow(deprecated)]
pub use self::scoped_tls::ScopedKey;
#[unstable(feature = "libstd_thread_internals", issue = "0")]
#[cfg(target_thread_local)]
#[doc(hidden)] pub use self::local::elf::Key as __ElfLocalKeyInner;
#[unstable(feature = "libstd_thread_internals", issue = "0")]
#[doc(hidden)] pub use self::local::os::Key as __OsLocalKeyInner;
#[unstable(feature = "libstd_thread_internals", issue = "0")]
#[doc(hidden)] pub use self::scoped_tls::__KeyInner as __ScopedKeyInner;
////////////////////////////////////////////////////////////////////////////////
// Builder
......
// Copyright 2014-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.
//! Scoped thread-local storage
//!
//! This module provides the ability to generate *scoped* thread-local
//! variables. In this sense, scoped indicates that thread local storage
//! actually stores a reference to a value, and this reference is only placed
//! in storage for a scoped amount of time.
//!
//! There are no restrictions on what types can be placed into a scoped
//! variable, but all scoped variables are initialized to the equivalent of
//! null. Scoped thread local storage is useful when a value is present for a known
//! period of time and it is not required to relinquish ownership of the
//! contents.
//!
//! # Examples
//!
//! ```
//! #![feature(scoped_tls)]
//!
//! scoped_thread_local!(static FOO: u32);
//!
//! // Initially each scoped slot is empty.
//! assert!(!FOO.is_set());
//!
//! // When inserting a value, the value is only in place for the duration
//! // of the closure specified.
//! FOO.set(&1, || {
//! FOO.with(|slot| {
//! assert_eq!(*slot, 1);
//! });
//! });
//! ```
#![unstable(feature = "thread_local_internals", issue = "0")]
#![allow(deprecated)]
#[doc(hidden)]
pub use self::imp::KeyInner as __KeyInner;
/// Type representing a thread local storage key corresponding to a reference
/// to the type parameter `T`.
///
/// Keys are statically allocated and can contain a reference to an instance of
/// type `T` scoped to a particular lifetime. Keys provides two methods, `set`
/// and `with`, both of which currently use closures to control the scope of
/// their contents.
#[unstable(feature = "scoped_tls",
reason = "scoped TLS has yet to have wide enough use to fully consider \
stabilizing its interface",
issue = "27715")]
#[rustc_deprecated(since = "1.8.0",
reason = "hasn't proven itself over LocalKey")]
pub struct ScopedKey<T:'static> { inner: fn() -> &'static imp::KeyInner<T> }
/// Declare a new scoped thread local storage key.
///
/// This macro declares a `static` item on which methods are used to get and
/// set the value stored within.
///
/// See [ScopedKey documentation](thread/struct.ScopedKey.html) for more
/// information.
#[unstable(feature = "thread_local_internals",
reason = "should not be necessary",
issue = "0")]
#[rustc_deprecated(since = "1.8.0",
reason = "hasn't proven itself over LocalKey")]
#[macro_export]
#[allow_internal_unstable]
macro_rules! scoped_thread_local {
(static $name:ident: $t:ty) => (
static $name: $crate::thread::ScopedKey<$t> =
__scoped_thread_local_inner!($t);
);
(pub static $name:ident: $t:ty) => (
pub static $name: $crate::thread::ScopedKey<$t> =
__scoped_thread_local_inner!($t);
);
}
#[doc(hidden)]
#[unstable(feature = "thread_local_internals",
reason = "should not be necessary",
issue = "0")]
#[rustc_deprecated(since = "1.8.0",
reason = "hasn't proven itself over LocalKey")]
#[macro_export]
#[allow_internal_unstable]
macro_rules! __scoped_thread_local_inner {
($t:ty) => {{
#[cfg_attr(target_thread_local, thread_local)]
static _KEY: $crate::thread::__ScopedKeyInner<$t> =
$crate::thread::__ScopedKeyInner::new();
fn _getit() -> &'static $crate::thread::__ScopedKeyInner<$t> { &_KEY }
$crate::thread::ScopedKey::new(_getit)
}}
}
#[unstable(feature = "scoped_tls",
reason = "scoped TLS has yet to have wide enough use to fully consider \
stabilizing its interface",
issue = "27715")]
#[rustc_deprecated(since = "1.8.0",
reason = "hasn't proven itself over LocalKey")]
impl<T> ScopedKey<T> {
#[doc(hidden)]
pub const fn new(inner: fn() -> &'static imp::KeyInner<T>) -> ScopedKey<T> {
ScopedKey { inner: inner }
}
/// Inserts a value into this scoped thread local storage slot for a
/// duration of a closure.
///
/// While `cb` is running, the value `t` will be returned by `get` unless
/// this function is called recursively inside of `cb`.
///
/// Upon return, this function will restore the previous value, if any
/// was available.
///
/// # Examples
///
/// ```
/// #![feature(scoped_tls)]
///
/// scoped_thread_local!(static FOO: u32);
///
/// FOO.set(&100, || {
/// let val = FOO.with(|v| *v);
/// assert_eq!(val, 100);
///
/// // set can be called recursively
/// FOO.set(&101, || {
/// // ...
/// });
///
/// // Recursive calls restore the previous value.
/// let val = FOO.with(|v| *v);
/// assert_eq!(val, 100);
/// });
/// ```
pub fn set<R, F>(&'static self, t: &T, cb: F) -> R where
F: FnOnce() -> R,
{
struct Reset<'a, T: 'a> {
key: &'a imp::KeyInner<T>,
val: *mut T,
}
impl<'a, T> Drop for Reset<'a, T> {
fn drop(&mut self) {
unsafe { self.key.set(self.val) }
}
}
let inner = (self.inner)();
let prev = unsafe {
let prev = inner.get();
inner.set(t as *const T as *mut T);
prev
};
let _reset = Reset { key: inner, val: prev };
cb()
}
/// Gets a value out of this scoped variable.
///
/// This function takes a closure which receives the value of this
/// variable.
///
/// # Panics
///
/// This function will panic if `set` has not previously been called.
///
/// # Examples
///
/// ```no_run
/// #![feature(scoped_tls)]
///
/// scoped_thread_local!(static FOO: u32);
///
/// FOO.with(|slot| {
/// // work with `slot`
/// });
/// ```
pub fn with<R, F>(&'static self, cb: F) -> R where
F: FnOnce(&T) -> R
{
unsafe {
let ptr = (self.inner)().get();
assert!(!ptr.is_null(), "cannot access a scoped thread local \
variable without calling `set` first");
cb(&*ptr)
}
}
/// Test whether this TLS key has been `set` for the current thread.
pub fn is_set(&'static self) -> bool {
unsafe { !(self.inner)().get().is_null() }
}
}
#[cfg(target_thread_local)]
#[doc(hidden)]
mod imp {
use cell::Cell;
use ptr;
pub struct KeyInner<T> { inner: Cell<*mut T> }
unsafe impl<T> ::marker::Sync for KeyInner<T> { }
impl<T> KeyInner<T> {
pub const fn new() -> KeyInner<T> {
KeyInner { inner: Cell::new(ptr::null_mut()) }
}
pub unsafe fn set(&self, ptr: *mut T) { self.inner.set(ptr); }
pub unsafe fn get(&self) -> *mut T { self.inner.get() }
}
}
#[cfg(not(target_thread_local))]
#[doc(hidden)]
mod imp {
use cell::Cell;
use marker;
use sys_common::thread_local::StaticKey as OsStaticKey;
pub struct KeyInner<T> {
pub inner: OsStaticKey,
pub marker: marker::PhantomData<Cell<T>>,
}
unsafe impl<T> marker::Sync for KeyInner<T> { }
impl<T> KeyInner<T> {
pub const fn new() -> KeyInner<T> {
KeyInner {
inner: OsStaticKey::new(None),
marker: marker::PhantomData
}
}
pub unsafe fn set(&self, ptr: *mut T) { self.inner.set(ptr as *mut _) }
pub unsafe fn get(&self) -> *mut T { self.inner.get() as *mut _ }
}
}
#[cfg(test)]
mod tests {
use cell::Cell;
scoped_thread_local!(static FOO: u32);
#[test]
fn smoke() {
scoped_thread_local!(static BAR: u32);
assert!(!BAR.is_set());
BAR.set(&1, || {
assert!(BAR.is_set());
BAR.with(|slot| {
assert_eq!(*slot, 1);
});
});
assert!(!BAR.is_set());
}
#[test]
fn cell_allowed() {
scoped_thread_local!(static BAR: Cell<u32>);
BAR.set(&Cell::new(1), || {
BAR.with(|slot| {
assert_eq!(slot.get(), 1);
});
});
}
#[test]
fn scope_item_allowed() {
assert!(!FOO.is_set());
FOO.set(&1, || {
assert!(FOO.is_set());
FOO.with(|slot| {
assert_eq!(*slot, 1);
});
});
assert!(!FOO.is_set());
}
}
......@@ -143,13 +143,6 @@ pub fn duration_since(&self, earlier: Instant) -> Duration {
self.0.sub_instant(&earlier.0)
}
/// Deprecated, renamed to `duration_since`
#[unstable(feature = "time2_old", issue = "29866")]
#[rustc_deprecated(since = "1.8.0", reason = "renamed to duration_since")]
pub fn duration_from_earlier(&self, earlier: Instant) -> Duration {
self.0.sub_instant(&earlier.0)
}
/// Returns the amount of time elapsed since this instant was created.
///
/// # Panics
......@@ -235,14 +228,6 @@ pub fn duration_since(&self, earlier: SystemTime)
self.0.sub_time(&earlier.0).map_err(SystemTimeError)
}
/// Deprecated, renamed to `duration_since`
#[unstable(feature = "time2_old", issue = "29866")]
#[rustc_deprecated(since = "1.8.0", reason = "renamed to duration_since")]
pub fn duration_from_earlier(&self, earlier: SystemTime)
-> Result<Duration, SystemTimeError> {
self.0.sub_time(&earlier.0).map_err(SystemTimeError)
}
/// Returns the amount of time elapsed since this system time was created.
///
/// This function may fail as the underlying system clock is susceptible to
......
......@@ -8,12 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::raw::Slice;
struct Slice<T> {
data: *const T,
len: usize,
}
fn main() {
let Slice { data: data, len: len } = "foo";
//~^ ERROR mismatched types
//~| expected type `&str`
//~| found type `std::raw::Slice<_>`
//~| expected &-ptr, found struct `std::raw::Slice`
//~| found type `Slice<_>`
//~| expected &-ptr, found struct `Slice`
}
......@@ -8,15 +8,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::raw::Slice;
struct Slice<T> {
data: *const T,
len: usize,
}
fn main() {
match () {
Slice { data: data, len: len } => (),
//~^ ERROR mismatched types
//~| expected type `()`
//~| found type `std::raw::Slice<_>`
//~| expected (), found struct `std::raw::Slice`
//~| found type `Slice<_>`
//~| expected (), found struct `Slice`
_ => unreachable!()
}
}
......@@ -9,13 +9,12 @@
// except according to those terms.
#![allow(dead_code)]
#![feature(recover)]
use std::panic::RecoverSafe;
use std::panic::UnwindSafe;
use std::rc::Rc;
use std::cell::RefCell;
fn assert<T: RecoverSafe + ?Sized>() {}
fn assert<T: UnwindSafe + ?Sized>() {}
fn main() {
assert::<Rc<RefCell<i32>>>();
......
......@@ -9,13 +9,12 @@
// except according to those terms.
#![allow(dead_code)]
#![feature(recover)]
use std::panic::RecoverSafe;
use std::panic::UnwindSafe;
use std::sync::Arc;
use std::cell::RefCell;
fn assert<T: RecoverSafe + ?Sized>() {}
fn assert<T: UnwindSafe + ?Sized>() {}
fn main() {
assert::<Arc<RefCell<i32>>>();
......
......@@ -9,12 +9,11 @@
// except according to those terms.
#![allow(dead_code)]
#![feature(recover)]
use std::panic::RecoverSafe;
use std::panic::UnwindSafe;
use std::cell::RefCell;
fn assert<T: RecoverSafe + ?Sized>() {}
fn assert<T: UnwindSafe + ?Sized>() {}
fn main() {
assert::<&RefCell<i32>>();
......
......@@ -9,12 +9,11 @@
// except according to those terms.
#![allow(dead_code)]
#![feature(recover)]
use std::panic::RecoverSafe;
use std::panic::UnwindSafe;
use std::cell::UnsafeCell;
fn assert<T: RecoverSafe + ?Sized>() {}
fn assert<T: UnwindSafe + ?Sized>() {}
fn main() {
assert::<*const UnsafeCell<i32>>(); //~ ERROR E0277
......
......@@ -9,12 +9,11 @@
// except according to those terms.
#![allow(dead_code)]
#![feature(recover)]
use std::panic::RecoverSafe;
use std::panic::UnwindSafe;
use std::cell::RefCell;
fn assert<T: RecoverSafe + ?Sized>() {}
fn assert<T: UnwindSafe + ?Sized>() {}
fn main() {
assert::<*mut RefCell<i32>>();
......
......@@ -10,13 +10,14 @@
// error-pattern:greetings from the panic handler
#![feature(std_panic, panic_handler)]
#![feature(panic_handler)]
use std::panic;
use std::io::{self, Write};
fn main() {
panic::set_handler(|i| {
panic::set_hook(Box::new(|i| {
write!(io::stderr(), "greetings from the panic handler");
});
}));
panic!("foobar");
}
......@@ -10,14 +10,15 @@
// error-pattern:thread '<main>' panicked at 'foobar'
#![feature(std_panic, panic_handler)]
#![feature(panic_handler)]
use std::panic;
use std::io::{self, Write};
fn main() {
panic::set_handler(|i| {
panic::set_hook(Box::new(|i| {
write!(io::stderr(), "greetings from the panic handler");
});
panic::take_handler();
}));
panic::take_hook();
panic!("foobar");
}
......@@ -10,10 +10,11 @@
// error-pattern:thread '<main>' panicked at 'foobar'
#![feature(std_panic, panic_handler)]
#![feature(panic_handler)]
use std::panic;
fn main() {
panic::take_handler();
panic::take_hook();
panic!("foobar");
}
......@@ -8,10 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(recover, rand, std_panic)]
#![feature(rand, std_panic)]
use std::__rand::{thread_rng, Rng};
use std::panic::{self, AssertRecoverSafe};
use std::panic::{self, AssertUnwindSafe};
use std::collections::BinaryHeap;
use std::cmp;
......@@ -70,8 +70,8 @@ fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
{
// push the panicking item to the heap and catch the panic
let thread_result = {
let mut heap_ref = AssertRecoverSafe(&mut heap);
panic::recover(move || {
let mut heap_ref = AssertUnwindSafe(&mut heap);
panic::catch_unwind(move || {
heap_ref.push(panic_item);
})
};
......
......@@ -10,25 +10,25 @@
// ignore-emscripten no threads support
#![feature(std_panic, recover, panic_propagate, panic_handler, const_fn)]
#![feature(panic_handler)]
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
use std::panic;
use std::thread;
static A: AtomicUsize = AtomicUsize::new(0);
static A: AtomicUsize = ATOMIC_USIZE_INIT;
fn main() {
panic::set_handler(|_| {
panic::set_hook(Box::new(|_| {
A.fetch_add(1, Ordering::SeqCst);
});
}));
let result = thread::spawn(|| {
let result = panic::recover(|| {
let result = panic::catch_unwind(|| {
panic!("hi there");
});
panic::propagate(result.unwrap_err());
panic::resume_unwind(result.unwrap_err());
}).join();
let msg = *result.unwrap_err().downcast::<&'static str>().unwrap();
......
......@@ -10,8 +10,6 @@
// aux-build:reachable-unnameable-items.rs
#![feature(recover)]
extern crate reachable_unnameable_items;
use reachable_unnameable_items::*;
......@@ -37,5 +35,5 @@ fn main() {
let none = None;
function_accepting_unnameable_type(none);
let _guard = std::panic::recover(|| none.unwrap().method_of_unnameable_type3());
let _guard = std::panic::catch_unwind(|| none.unwrap().method_of_unnameable_type3());
}
......@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(std_panic, recover, start)]
#![feature(start)]
use std::ffi::CStr;
use std::process::{Command, Output};
......@@ -22,8 +22,8 @@ fn start(argc: isize, argv: *const *const u8) -> isize {
match **argv.offset(1) as char {
'1' => {}
'2' => println!("foo"),
'3' => assert!(panic::recover(|| {}).is_ok()),
'4' => assert!(panic::recover(|| panic!()).is_err()),
'3' => assert!(panic::catch_unwind(|| {}).is_ok()),
'4' => assert!(panic::catch_unwind(|| panic!()).is_err()),
'5' => assert!(Command::new("test").spawn().is_err()),
_ => panic!()
}
......
......@@ -23,8 +23,6 @@ pub fn main() {
assert_eq!(s.chars().count(), 4);
assert_eq!(schs.len(), 4);
assert_eq!(schs.iter().cloned().collect::<String>(), s);
assert_eq!(s.char_at(0), 'e');
assert_eq!(s.char_at(1), 'é');
assert!((str::from_utf8(s.as_bytes()).is_ok()));
// invalid prefix
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册