Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions library/core/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ const impl<T> From<legacy::RangeInclusive<T>> for RangeInclusive<T> {
///
/// # Panics
///
/// Panics if the legacy range iterator has been exhausted.
/// If the legacy range iterator has been exhausted,
/// this function will either panic or return an empty range.
///
/// # Examples
///
Expand All @@ -419,19 +420,23 @@ const impl<T> From<legacy::RangeInclusive<T>> for RangeInclusive<T> {
/// assert_eq!((empty.start, empty.last), (0, 0));
/// ```
///
/// ```should_panic
/// ```
/// # // This test requires unwinding to work.
/// # // Disable it when unwinding isn't available.
/// # #[cfg(panic = "unwind")]
/// # fn main() {
/// use core::range::legacy;
/// use core::range::RangeInclusive;
/// use std::panic::catch_unwind;
///
/// let mut exhausted: legacy::RangeInclusive<i32> = 0..=0;
/// exhausted.next();
/// # if exhausted.is_empty() {
/// # // assert!s don't work correctly in `should_panic` doctests since you
/// # // can't assert the panic message. Skip the rest of the test instead,
/// # // so that the expected panic doesn't happen and the test fails.
/// assert!(exhausted.is_empty());
/// let _ = RangeInclusive::from(exhausted); // this panics
/// let result = catch_unwind(|| RangeInclusive::from(exhausted));
/// // The `from` call either panicked or returned an empty range.
/// assert!(result.is_err() || result.is_ok_and(|range| range.is_empty()));
/// # }
/// # #[cfg(not(panic = "unwind"))]
/// # fn main() {}
/// ```
#[inline]
fn from(value: legacy::RangeInclusive<T>) -> Self {
Expand Down
Loading