Skip to content

Commit 22b0489

Browse files
committed
Add the emptiness condition to the docs; add a PartialOrd example with NAN
1 parent 6f70a11 commit 22b0489

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/libcore/ops/range.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl fmt::Debug for RangeFull {
6060
/// (`start..end`).
6161
///
6262
/// The `Range` `start..end` contains all values with `x >= start` and
63-
/// `x < end`.
63+
/// `x < end`. It is empty unless `start < end`.
6464
///
6565
/// # Examples
6666
///
@@ -124,6 +124,17 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
124124
/// assert!( (3..3).is_empty());
125125
/// assert!( (3..2).is_empty());
126126
/// ```
127+
///
128+
/// The range is empty if either side is incomparable:
129+
///
130+
/// ```
131+
/// #![feature(range_is_empty,inclusive_range_syntax)]
132+
///
133+
/// use std::f32::NAN;
134+
/// assert!(!(3.0..5.0).is_empty());
135+
/// assert!( (3.0..NAN).is_empty());
136+
/// assert!( (NAN..5.0).is_empty());
137+
/// ```
127138
#[unstable(feature = "range_is_empty", reason = "recently added", issue = "48111")]
128139
pub fn is_empty(&self) -> bool {
129140
!(self.start < self.end)
@@ -260,7 +271,7 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
260271
/// An range bounded inclusively below and above (`start..=end`).
261272
///
262273
/// The `RangeInclusive` `start..=end` contains all values with `x >= start`
263-
/// and `x <= end`.
274+
/// and `x <= end`. It is empty unless `start <= end`.
264275
///
265276
/// This iterator is [fused], but the specific values of `start` and `end` after
266277
/// iteration has finished are **unspecified** other than that [`.is_empty()`]
@@ -337,6 +348,17 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
337348
/// assert!( (3..=2).is_empty());
338349
/// ```
339350
///
351+
/// The range is empty if either side is incomparable:
352+
///
353+
/// ```
354+
/// #![feature(range_is_empty,inclusive_range_syntax)]
355+
///
356+
/// use std::f32::NAN;
357+
/// assert!(!(3.0..=5.0).is_empty());
358+
/// assert!( (3.0..=NAN).is_empty());
359+
/// assert!( (NAN..=5.0).is_empty());
360+
/// ```
361+
///
340362
/// This method returns `true` after iteration has finished:
341363
///
342364
/// ```

0 commit comments

Comments
 (0)