Skip to content

Commit

Permalink
Rollup merge of #73302 - JakobDegen:should-panic-documentation, r=Mar…
Browse files Browse the repository at this point in the history
…k-Simulacrum

Adjusted some doctests in libcore to use `should_panic`.

Fixes #73196 .

I grepped libstd and libcore for all the instances of this pattern that I could find, but its possible that I missed some of course. If anyone knows of any more, please let me know and I will add them to the PR.
  • Loading branch information
Dylan-DPC authored Jun 13, 2020
2 parents 0bbc651 + 3ab4b38 commit a879f9c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 71 deletions.
26 changes: 8 additions & 18 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
/// let c = RefCell::new(5);
///
/// assert!(result.is_err());
/// let m = c.borrow_mut();
/// let b = c.borrow(); // this causes a panic
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down Expand Up @@ -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();
/// let c = RefCell::new(5);
/// let m = c.borrow();
///
/// assert!(result.is_err());
/// let b = c.borrow_mut(); // this causes a panic
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down
11 changes: 3 additions & 8 deletions src/libcore/char/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
/// // this panics
/// let c = char::from_digit(1, 37);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
62 changes: 17 additions & 45 deletions src/libcore/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
/// // this panics
/// char::from_digit(1, 37);
/// ```
#[unstable(feature = "assoc_char_funcs", reason = "recently added", issue = "71763")]
#[inline]
Expand Down Expand Up @@ -282,15 +277,9 @@ impl char {
///
/// Passing a large radix, causing a panic:
///
/// ```
/// use std::thread;
///
/// let result = thread::spawn(|| {
/// // this panics
/// '1'.is_digit(37);
/// }).join();
///
/// assert!(result.is_err());
/// ```should_panic
/// // this panics
/// '1'.is_digit(37);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down Expand Up @@ -337,14 +326,9 @@ impl char {
///
/// Passing a large radix, causing a panic:
///
/// ```
/// use std::thread;
///
/// let result = thread::spawn(|| {
/// '1'.to_digit(37);
/// }).join();
///
/// assert!(result.is_err());
/// ```should_panic
/// // this panics
/// '1'.to_digit(37);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down Expand Up @@ -646,17 +630,11 @@ impl char {
///
/// A buffer that's too small:
///
/// ```
/// use std::thread;
///
/// let result = thread::spawn(|| {
/// let mut b = [0; 1];
///
/// // this panics
/// 'ß'.encode_utf8(&mut b);
/// }).join();
/// ```should_panic
/// let mut b = [0; 1];
///
/// assert!(result.is_err());
/// // this panics
/// 'ß'.encode_utf8(&mut b);
/// ```
#[stable(feature = "unicode_encode_char", since = "1.15.0")]
#[inline]
Expand Down Expand Up @@ -687,17 +665,11 @@ impl char {
///
/// A buffer that's too small:
///
/// ```
/// use std::thread;
///
/// let result = thread::spawn(|| {
/// let mut b = [0; 1];
///
/// // this panics
/// '𝕊'.encode_utf16(&mut b);
/// }).join();
/// ```should_panic
/// let mut b = [0; 1];
///
/// assert!(result.is_err());
/// // this panics
/// '𝕊'.encode_utf16(&mut b);
/// ```
#[stable(feature = "unicode_encode_char", since = "1.15.0")]
#[inline]
Expand Down

0 comments on commit a879f9c

Please sign in to comment.