about summary refs log tree commit diff
path: root/src/libcore/ops
diff options
context:
space:
mode:
authorAlex Burka <alex@alexburka.com>2017-09-19 05:40:04 +0000
committerBadel2 <2badel2@gmail.com>2017-09-22 22:05:18 +0200
commite64efc91f49affb265328e354c8c8f0544daa462 (patch)
treeab6832194ec3c23ab7033941b885f164ebc37686 /src/libcore/ops
parent3eb19bf9b160825cd338b9419551670a30962c4e (diff)
downloadrust-e64efc91f49affb265328e354c8c8f0544daa462.tar.gz
rust-e64efc91f49affb265328e354c8c8f0544daa462.zip
Add support for `..=` syntax
Add ..= to the parser

Add ..= to libproc_macro

Add ..= to ICH

Highlight ..= in rustdoc

Update impl Debug for RangeInclusive to ..=

Replace `...` to `..=` in range docs

Make the dotdoteq warning point to the ...

Add warning for ... in expressions

Updated more tests to the ..= syntax

Updated even more tests to the ..= syntax

Updated the inclusive_range entry in unstable book
Diffstat (limited to 'src/libcore/ops')
-rw-r--r--src/libcore/ops/range.rs50
1 files changed, 25 insertions, 25 deletions
diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs
index 463a50491a8..3f573f7c7eb 100644
--- a/src/libcore/ops/range.rs
+++ b/src/libcore/ops/range.rs
@@ -241,9 +241,9 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
     }
 }
 
-/// An range bounded inclusively below and above (`start...end`).
+/// An range bounded inclusively below and above (`start..=end`).
 ///
-/// The `RangeInclusive` `start...end` contains all values with `x >= start`
+/// The `RangeInclusive` `start..=end` contains all values with `x >= start`
 /// and `x <= end`.
 ///
 /// # Examples
@@ -251,12 +251,12 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
 /// ```
 /// #![feature(inclusive_range,inclusive_range_syntax)]
 ///
-/// assert_eq!((3...5), std::ops::RangeInclusive { start: 3, end: 5 });
-/// assert_eq!(3 + 4 + 5, (3...5).sum());
+/// assert_eq!((3..=5), std::ops::RangeInclusive { start: 3, end: 5 });
+/// assert_eq!(3 + 4 + 5, (3..=5).sum());
 ///
 /// let arr = [0, 1, 2, 3];
-/// assert_eq!(arr[ ...2], [0,1,2  ]);
-/// assert_eq!(arr[1...2], [  1,2  ]);  // RangeInclusive
+/// assert_eq!(arr[ ..=2], [0,1,2  ]);
+/// assert_eq!(arr[1..=2], [  1,2  ]);  // RangeInclusive
 /// ```
 #[derive(Clone, PartialEq, Eq, Hash)]  // not Copy -- see #27186
 #[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
@@ -276,7 +276,7 @@ pub struct RangeInclusive<Idx> {
 #[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
 impl<Idx: fmt::Debug> fmt::Debug for RangeInclusive<Idx> {
     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
-        write!(fmt, "{:?}...{:?}", self.start, self.end)
+        write!(fmt, "{:?}..={:?}", self.start, self.end)
     }
 }
 
@@ -289,32 +289,32 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
     /// ```
     /// #![feature(range_contains,inclusive_range_syntax)]
     ///
-    /// assert!(!(3...5).contains(2));
-    /// assert!( (3...5).contains(3));
-    /// assert!( (3...5).contains(4));
-    /// assert!( (3...5).contains(5));
-    /// assert!(!(3...5).contains(6));
+    /// assert!(!(3..=5).contains(2));
+    /// assert!( (3..=5).contains(3));
+    /// assert!( (3..=5).contains(4));
+    /// assert!( (3..=5).contains(5));
+    /// assert!(!(3..=5).contains(6));
     ///
-    /// assert!( (3...3).contains(3));
-    /// assert!(!(3...2).contains(3));
+    /// assert!( (3..=3).contains(3));
+    /// assert!(!(3..=2).contains(3));
     /// ```
     pub fn contains(&self, item: Idx) -> bool {
         self.start <= item && item <= self.end
     }
 }
 
-/// A range only bounded inclusively above (`...end`).
+/// A range only bounded inclusively above (`..=end`).
 ///
-/// The `RangeToInclusive` `...end` contains all values with `x <= end`.
+/// The `RangeToInclusive` `..=end` contains all values with `x <= end`.
 /// It cannot serve as an [`Iterator`] because it doesn't have a starting point.
 ///
 /// # Examples
 ///
-/// The `...end` syntax is a `RangeToInclusive`:
+/// The `..=end` syntax is a `RangeToInclusive`:
 ///
 /// ```
 /// #![feature(inclusive_range,inclusive_range_syntax)]
-/// assert_eq!((...5), std::ops::RangeToInclusive{ end: 5 });
+/// assert_eq!((..=5), std::ops::RangeToInclusive{ end: 5 });
 /// ```
 ///
 /// It does not have an [`IntoIterator`] implementation, so you can't use it in a
@@ -325,7 +325,7 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
 ///
 /// // error[E0277]: the trait bound `std::ops::RangeToInclusive<{integer}>:
 /// // std::iter::Iterator` is not satisfied
-/// for i in ...5 {
+/// for i in ..=5 {
 ///     // ...
 /// }
 /// ```
@@ -337,8 +337,8 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
 /// #![feature(inclusive_range_syntax)]
 ///
 /// let arr = [0, 1, 2, 3];
-/// assert_eq!(arr[ ...2], [0,1,2  ]);  // RangeToInclusive
-/// assert_eq!(arr[1...2], [  1,2  ]);
+/// assert_eq!(arr[ ..=2], [0,1,2  ]);  // RangeToInclusive
+/// assert_eq!(arr[1..=2], [  1,2  ]);
 /// ```
 ///
 /// [`IntoIterator`]: ../iter/trait.Iterator.html
@@ -357,7 +357,7 @@ pub struct RangeToInclusive<Idx> {
 #[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
 impl<Idx: fmt::Debug> fmt::Debug for RangeToInclusive<Idx> {
     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
-        write!(fmt, "...{:?}", self.end)
+        write!(fmt, "..={:?}", self.end)
     }
 }
 
@@ -370,9 +370,9 @@ impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
     /// ```
     /// #![feature(range_contains,inclusive_range_syntax)]
     ///
-    /// assert!( (...5).contains(-1_000_000_000));
-    /// assert!( (...5).contains(5));
-    /// assert!(!(...5).contains(6));
+    /// assert!( (..=5).contains(-1_000_000_000));
+    /// assert!( (..=5).contains(5));
+    /// assert!(!(..=5).contains(6));
     /// ```
     pub fn contains(&self, item: Idx) -> bool {
         (item <= self.end)