Skip to content

Commit a879f9c

Browse files
authored
Rollup merge of rust-lang#73302 - JakobDegen:should-panic-documentation, r=Mark-Simulacrum
Adjusted some doctests in libcore to use `should_panic`. Fixes rust-lang#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.
2 parents 0bbc651 + 3ab4b38 commit a879f9c

File tree

3 files changed

+28
-71
lines changed

3 files changed

+28
-71
lines changed

Diff for: src/libcore/cell.rs

+8-18
Original file line numberDiff line numberDiff line change
@@ -778,18 +778,13 @@ impl<T: ?Sized> RefCell<T> {
778778
///
779779
/// An example of panic:
780780
///
781-
/// ```
781+
/// ```should_panic
782782
/// use std::cell::RefCell;
783-
/// use std::thread;
784-
///
785-
/// let result = thread::spawn(move || {
786-
/// let c = RefCell::new(5);
787-
/// let m = c.borrow_mut();
788783
///
789-
/// let b = c.borrow(); // this causes a panic
790-
/// }).join();
784+
/// let c = RefCell::new(5);
791785
///
792-
/// assert!(result.is_err());
786+
/// let m = c.borrow_mut();
787+
/// let b = c.borrow(); // this causes a panic
793788
/// ```
794789
#[stable(feature = "rust1", since = "1.0.0")]
795790
#[inline]
@@ -858,18 +853,13 @@ impl<T: ?Sized> RefCell<T> {
858853
///
859854
/// An example of panic:
860855
///
861-
/// ```
856+
/// ```should_panic
862857
/// use std::cell::RefCell;
863-
/// use std::thread;
864-
///
865-
/// let result = thread::spawn(move || {
866-
/// let c = RefCell::new(5);
867-
/// let m = c.borrow();
868858
///
869-
/// let b = c.borrow_mut(); // this causes a panic
870-
/// }).join();
859+
/// let c = RefCell::new(5);
860+
/// let m = c.borrow();
871861
///
872-
/// assert!(result.is_err());
862+
/// let b = c.borrow_mut(); // this causes a panic
873863
/// ```
874864
#[stable(feature = "rust1", since = "1.0.0")]
875865
#[inline]

Diff for: src/libcore/char/convert.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,11 @@ impl fmt::Display for CharTryFromError {
278278
///
279279
/// Passing a large radix, causing a panic:
280280
///
281-
/// ```
282-
/// use std::thread;
281+
/// ```should_panic
283282
/// use std::char;
284283
///
285-
/// let result = thread::spawn(|| {
286-
/// // this panics
287-
/// let c = char::from_digit(1, 37);
288-
/// }).join();
289-
///
290-
/// assert!(result.is_err());
284+
/// // this panics
285+
/// let c = char::from_digit(1, 37);
291286
/// ```
292287
#[inline]
293288
#[stable(feature = "rust1", since = "1.0.0")]

Diff for: src/libcore/char/methods.rs

+17-45
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,11 @@ impl char {
229229
///
230230
/// Passing a large radix, causing a panic:
231231
///
232-
/// ```
233-
/// use std::thread;
232+
/// ```should_panic
234233
/// use std::char;
235234
///
236-
/// let result = thread::spawn(|| {
237-
/// // this panics
238-
/// let c = char::from_digit(1, 37);
239-
/// }).join();
240-
///
241-
/// assert!(result.is_err());
235+
/// // this panics
236+
/// char::from_digit(1, 37);
242237
/// ```
243238
#[unstable(feature = "assoc_char_funcs", reason = "recently added", issue = "71763")]
244239
#[inline]
@@ -282,15 +277,9 @@ impl char {
282277
///
283278
/// Passing a large radix, causing a panic:
284279
///
285-
/// ```
286-
/// use std::thread;
287-
///
288-
/// let result = thread::spawn(|| {
289-
/// // this panics
290-
/// '1'.is_digit(37);
291-
/// }).join();
292-
///
293-
/// assert!(result.is_err());
280+
/// ```should_panic
281+
/// // this panics
282+
/// '1'.is_digit(37);
294283
/// ```
295284
#[stable(feature = "rust1", since = "1.0.0")]
296285
#[inline]
@@ -337,14 +326,9 @@ impl char {
337326
///
338327
/// Passing a large radix, causing a panic:
339328
///
340-
/// ```
341-
/// use std::thread;
342-
///
343-
/// let result = thread::spawn(|| {
344-
/// '1'.to_digit(37);
345-
/// }).join();
346-
///
347-
/// assert!(result.is_err());
329+
/// ```should_panic
330+
/// // this panics
331+
/// '1'.to_digit(37);
348332
/// ```
349333
#[stable(feature = "rust1", since = "1.0.0")]
350334
#[inline]
@@ -646,17 +630,11 @@ impl char {
646630
///
647631
/// A buffer that's too small:
648632
///
649-
/// ```
650-
/// use std::thread;
651-
///
652-
/// let result = thread::spawn(|| {
653-
/// let mut b = [0; 1];
654-
///
655-
/// // this panics
656-
/// 'ß'.encode_utf8(&mut b);
657-
/// }).join();
633+
/// ```should_panic
634+
/// let mut b = [0; 1];
658635
///
659-
/// assert!(result.is_err());
636+
/// // this panics
637+
/// 'ß'.encode_utf8(&mut b);
660638
/// ```
661639
#[stable(feature = "unicode_encode_char", since = "1.15.0")]
662640
#[inline]
@@ -687,17 +665,11 @@ impl char {
687665
///
688666
/// A buffer that's too small:
689667
///
690-
/// ```
691-
/// use std::thread;
692-
///
693-
/// let result = thread::spawn(|| {
694-
/// let mut b = [0; 1];
695-
///
696-
/// // this panics
697-
/// '𝕊'.encode_utf16(&mut b);
698-
/// }).join();
668+
/// ```should_panic
669+
/// let mut b = [0; 1];
699670
///
700-
/// assert!(result.is_err());
671+
/// // this panics
672+
/// '𝕊'.encode_utf16(&mut b);
701673
/// ```
702674
#[stable(feature = "unicode_encode_char", since = "1.15.0")]
703675
#[inline]

0 commit comments

Comments
 (0)