diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-06-13 16:47:54 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-13 16:47:54 +0200 |
| commit | a879f9cdf623f89035e2fa8abc115c7c9f5a3e5e (patch) | |
| tree | 88b29b0ddeafc05ec2b83ee0381f944beb55819b | |
| parent | 0bbc65186965828ab5255241a691e3bdab3f3793 (diff) | |
| parent | 3ab4b380aa0b0db982d3586b47dcfa13a1a427b8 (diff) | |
| download | rust-a879f9cdf623f89035e2fa8abc115c7c9f5a3e5e.tar.gz rust-a879f9cdf623f89035e2fa8abc115c7c9f5a3e5e.zip | |
Rollup merge of #73302 - JakobDegen:should-panic-documentation, r=Mark-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.
| -rw-r--r-- | src/libcore/cell.rs | 26 | ||||
| -rw-r--r-- | src/libcore/char/convert.rs | 11 | ||||
| -rw-r--r-- | src/libcore/char/methods.rs | 62 |
3 files changed, 28 insertions, 71 deletions
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index cadc2e631b0..c4293ed7bcf 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -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] @@ -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] diff --git a/src/libcore/char/convert.rs b/src/libcore/char/convert.rs index 87c56c4b0a1..d7e39946148 100644 --- a/src/libcore/char/convert.rs +++ b/src/libcore/char/convert.rs @@ -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")] diff --git a/src/libcore/char/methods.rs b/src/libcore/char/methods.rs index bf09b28ff69..dd2f01c679f 100644 --- a/src/libcore/char/methods.rs +++ b/src/libcore/char/methods.rs @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] |
