From f70b2ebd08f47c504681ca5f62c3ccdacdd69763 Mon Sep 17 00:00:00 2001 From: kennytm Date: Sat, 7 Apr 2018 14:19:34 +0800 Subject: [PATCH] new() should be const; start()/end() after iteration is unspecified. --- src/libcore/ops/range.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 RangeInclusive { /// ``` #[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 @@ pub fn start(&self) -> &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 /// /// ``` -- 2.44.0