Skip to content
/ rust Public
forked from rust-lang/rust

Commit 0d342bc

Browse files
authored
Rollup merge of rust-lang#160151 - fs-rachel:unwind-in-alloc-doctest, r=clarfonthey
Mark a doctest as requiring unwinding rust-lang#158547 moved `std::io::BufWriter` to `alloc::io::BufWriter`. That allows it to be used in `no-std` configurations, and in particular on platforms where unwinding isn't supported. However one of the doc tests uses `catch_unwind`, which fails on platforms which cannot unwind. Fix this by copying the magic incantation from a similar doctest in library/core/src/range.rs
2 parents 8fd063a + d3be642 commit 0d342bc

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

library/alloc/src/io/buffered/bufwriter.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,10 @@ impl<W: ?Sized + Write> BufWriter<W> {
490490
/// # Example
491491
///
492492
/// ```
493+
/// # // This test requires unwinding to work.
494+
/// # // Disable it when unwinding isn't available.
495+
/// # #[cfg(panic = "unwind")]
496+
/// # fn main() {
493497
/// use std::io::{self, BufWriter, Write};
494498
/// use std::panic::{catch_unwind, AssertUnwindSafe};
495499
///
@@ -508,6 +512,9 @@ impl<W: ?Sized + Write> BufWriter<W> {
508512
/// let (recovered_writer, buffered_data) = stream.into_parts();
509513
/// assert!(matches!(recovered_writer, PanickingWriter));
510514
/// assert_eq!(buffered_data.unwrap_err().into_inner(), b"some data");
515+
/// # }
516+
/// # #[cfg(not(panic = "unwind"))]
517+
/// # fn main() {}
511518
/// ```
512519
pub struct WriterPanicked {
513520
buf: Vec<u8>,

0 commit comments

Comments
 (0)