about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-04-07 14:19:34 +0800
committerkennytm <kennytm@gmail.com>2018-05-01 01:45:18 +0800
commitf70b2ebd08f47c504681ca5f62c3ccdacdd69763 (patch)
treea1ce839f43851b7d203c61a8e2487a879a616fc5
parentc916ee8511339dd231d90d7fe6be2cc6995284b9 (diff)
downloadrust-f70b2ebd08f47c504681ca5f62c3ccdacdd69763.tar.gz
rust-f70b2ebd08f47c504681ca5f62c3ccdacdd69763.zip
new() should be const; start()/end() after iteration is unspecified.
-rw-r--r--src/libcore/ops/range.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs
index 59ee40fdda4..b01a769eda7 100644
--- a/src/libcore/ops/range.rs
+++ b/src/libcore/ops/range.rs
@@ -362,12 +362,20 @@ impl<Idx> RangeInclusive<Idx> {
     /// ```
     #[unstable(feature = "inclusive_range_methods", issue = "49022")]
     #[inline]
-    pub fn new(start: Idx, end: Idx) -> Self {
+    pub const fn new(start: Idx, end: Idx) -> Self {
         Self { start, end }
     }
 
     /// Returns the lower bound of the range (inclusive).
     ///
+    /// When using an inclusive range for iteration, the values of `start()` and
+    /// [`end()`] are unspecified after the iteration ended. To determine
+    /// whether the inclusive range is empty, use the [`is_empty()`] method
+    /// instead of comparing `start() > end()`.
+    ///
+    /// [`end()`]: #method.end
+    /// [`is_empty()`]: #method.is_empty
+    ///
     /// # Examples
     ///
     /// ```
@@ -383,6 +391,14 @@ impl<Idx> RangeInclusive<Idx> {
 
     /// Returns the upper bound of the range (inclusive).
     ///
+    /// When using an inclusive range for iteration, the values of [`start()`]
+    /// and `end()` are unspecified after the iteration ended. To determine
+    /// whether the inclusive range is empty, use the [`is_empty()`] method
+    /// instead of comparing `start() > end()`.
+    ///
+    /// [`start()`]: #method.start
+    /// [`is_empty()`]: #method.is_empty
+    ///
     /// # Examples
     ///
     /// ```