@@ -60,7 +60,7 @@ impl fmt::Debug for RangeFull {
60
60
/// (`start..end`).
61
61
///
62
62
/// The `Range` `start..end` contains all values with `x >= start` and
63
- /// `x < end`.
63
+ /// `x < end`. It is empty unless `start < end`.
64
64
///
65
65
/// # Examples
66
66
///
@@ -124,6 +124,17 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
124
124
/// assert!( (3..3).is_empty());
125
125
/// assert!( (3..2).is_empty());
126
126
/// ```
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
+ /// ```
127
138
#[ unstable( feature = "range_is_empty" , reason = "recently added" , issue = "48111" ) ]
128
139
pub fn is_empty ( & self ) -> bool {
129
140
!( self . start < self . end )
@@ -260,7 +271,7 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
260
271
/// An range bounded inclusively below and above (`start..=end`).
261
272
///
262
273
/// The `RangeInclusive` `start..=end` contains all values with `x >= start`
263
- /// and `x <= end`.
274
+ /// and `x <= end`. It is empty unless `start <= end`.
264
275
///
265
276
/// This iterator is [fused], but the specific values of `start` and `end` after
266
277
/// iteration has finished are **unspecified** other than that [`.is_empty()`]
@@ -337,6 +348,17 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
337
348
/// assert!( (3..=2).is_empty());
338
349
/// ```
339
350
///
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
+ ///
340
362
/// This method returns `true` after iteration has finished:
341
363
///
342
364
/// ```
0 commit comments