Adjusted some doctests in libcore to use `should_panic`.
Previously, some doctests were spawning new threads and joining them to indicate that a particular call should panic; this hurt readability, so the tests have been adjusted to simply call the method and use the `should_panic` marker.
This commit is contained in:
parent
e93cb961ba
commit
3ab4b380aa
|
@ -778,18 +778,13 @@ impl<T: ?Sized> RefCell<T> {
|
|||
///
|
||||
/// An example of panic:
|
||||
///
|
||||
/// ```
|
||||
/// ```should_panic
|
||||
/// use std::cell::RefCell;
|
||||
/// use std::thread;
|
||||
///
|
||||
/// let result = thread::spawn(move || {
|
||||
/// let c = RefCell::new(5);
|
||||
///
|
||||
/// let m = c.borrow_mut();
|
||||
///
|
||||
/// let b = c.borrow(); // this causes a panic
|
||||
/// }).join();
|
||||
///
|
||||
/// assert!(result.is_err());
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
|
@ -858,18 +853,13 @@ impl<T: ?Sized> RefCell<T> {
|
|||
///
|
||||
/// An example of panic:
|
||||
///
|
||||
/// ```
|
||||
/// ```should_panic
|
||||
/// use std::cell::RefCell;
|
||||
/// use std::thread;
|
||||
///
|
||||
/// let result = thread::spawn(move || {
|
||||
/// let c = RefCell::new(5);
|
||||
/// let m = c.borrow();
|
||||
///
|
||||
/// let b = c.borrow_mut(); // this causes a panic
|
||||
/// }).join();
|
||||
///
|
||||
/// assert!(result.is_err());
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
|
|
|
@ -278,16 +278,11 @@ impl fmt::Display for CharTryFromError {
|
|||
///
|
||||
/// Passing a large radix, causing a panic:
|
||||
///
|
||||
/// ```
|
||||
/// use std::thread;
|
||||
/// ```should_panic
|
||||
/// use std::char;
|
||||
///
|
||||
/// let result = thread::spawn(|| {
|
||||
/// // this panics
|
||||
/// let c = char::from_digit(1, 37);
|
||||
/// }).join();
|
||||
///
|
||||
/// assert!(result.is_err());
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
|
|
@ -229,16 +229,11 @@ impl char {
|
|||
///
|
||||
/// Passing a large radix, causing a panic:
|
||||
///
|
||||
/// ```
|
||||
/// use std::thread;
|
||||
/// ```should_panic
|
||||
/// use std::char;
|
||||
///
|
||||
/// let result = thread::spawn(|| {
|
||||
/// // this panics
|
||||
/// let c = char::from_digit(1, 37);
|
||||
/// }).join();
|
||||
///
|
||||
/// assert!(result.is_err());
|
||||
/// char::from_digit(1, 37);
|
||||
/// ```
|
||||
#[unstable(feature = "assoc_char_funcs", reason = "recently added", issue = "71763")]
|
||||
#[inline]
|
||||
|
@ -282,15 +277,9 @@ impl char {
|
|||
///
|
||||
/// Passing a large radix, causing a panic:
|
||||
///
|
||||
/// ```
|
||||
/// use std::thread;
|
||||
///
|
||||
/// let result = thread::spawn(|| {
|
||||
/// ```should_panic
|
||||
/// // this panics
|
||||
/// '1'.is_digit(37);
|
||||
/// }).join();
|
||||
///
|
||||
/// assert!(result.is_err());
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
|
@ -337,14 +326,9 @@ impl char {
|
|||
///
|
||||
/// Passing a large radix, causing a panic:
|
||||
///
|
||||
/// ```
|
||||
/// use std::thread;
|
||||
///
|
||||
/// let result = thread::spawn(|| {
|
||||
/// ```should_panic
|
||||
/// // this panics
|
||||
/// '1'.to_digit(37);
|
||||
/// }).join();
|
||||
///
|
||||
/// assert!(result.is_err());
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
|
@ -646,17 +630,11 @@ impl char {
|
|||
///
|
||||
/// A buffer that's too small:
|
||||
///
|
||||
/// ```
|
||||
/// use std::thread;
|
||||
///
|
||||
/// let result = thread::spawn(|| {
|
||||
/// ```should_panic
|
||||
/// let mut b = [0; 1];
|
||||
///
|
||||
/// // this panics
|
||||
/// 'ß'.encode_utf8(&mut b);
|
||||
/// }).join();
|
||||
///
|
||||
/// assert!(result.is_err());
|
||||
/// ```
|
||||
#[stable(feature = "unicode_encode_char", since = "1.15.0")]
|
||||
#[inline]
|
||||
|
@ -687,17 +665,11 @@ impl char {
|
|||
///
|
||||
/// A buffer that's too small:
|
||||
///
|
||||
/// ```
|
||||
/// use std::thread;
|
||||
///
|
||||
/// let result = thread::spawn(|| {
|
||||
/// ```should_panic
|
||||
/// let mut b = [0; 1];
|
||||
///
|
||||
/// // this panics
|
||||
/// '𝕊'.encode_utf16(&mut b);
|
||||
/// }).join();
|
||||
///
|
||||
/// assert!(result.is_err());
|
||||
/// ```
|
||||
#[stable(feature = "unicode_encode_char", since = "1.15.0")]
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in New Issue