Skip to content

Commit f70b2eb

Browse files
committed
new() should be const; start()/end() after iteration is unspecified.
1 parent c916ee8 commit f70b2eb

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Diff for: src/libcore/ops/range.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,20 @@ impl<Idx> RangeInclusive<Idx> {
362362
/// ```
363363
#[unstable(feature = "inclusive_range_methods", issue = "49022")]
364364
#[inline]
365-
pub fn new(start: Idx, end: Idx) -> Self {
365+
pub const fn new(start: Idx, end: Idx) -> Self {
366366
Self { start, end }
367367
}
368368

369369
/// Returns the lower bound of the range (inclusive).
370370
///
371+
/// When using an inclusive range for iteration, the values of `start()` and
372+
/// [`end()`] are unspecified after the iteration ended. To determine
373+
/// whether the inclusive range is empty, use the [`is_empty()`] method
374+
/// instead of comparing `start() > end()`.
375+
///
376+
/// [`end()`]: #method.end
377+
/// [`is_empty()`]: #method.is_empty
378+
///
371379
/// # Examples
372380
///
373381
/// ```
@@ -383,6 +391,14 @@ impl<Idx> RangeInclusive<Idx> {
383391

384392
/// Returns the upper bound of the range (inclusive).
385393
///
394+
/// When using an inclusive range for iteration, the values of [`start()`]
395+
/// and `end()` are unspecified after the iteration ended. To determine
396+
/// whether the inclusive range is empty, use the [`is_empty()`] method
397+
/// instead of comparing `start() > end()`.
398+
///
399+
/// [`start()`]: #method.start
400+
/// [`is_empty()`]: #method.is_empty
401+
///
386402
/// # Examples
387403
///
388404
/// ```

0 commit comments

Comments
 (0)