Inclusive range updated to ..= syntax

This commit is contained in:
Badel2 2017-11-03 18:17:44 +01:00
parent 525b81d570
commit 4bd6be9dc6
4 changed files with 10 additions and 13 deletions

View File

@ -16,9 +16,6 @@
#![stable(feature = "rust1", since = "1.0.0")]
// FIXME: after next stage0, change RangeInclusive { ... } back to ..=
use ops::RangeInclusive;
// How this module is organized.
//
// The library infrastructure for slices is fairly messy. There's
@ -1047,32 +1044,32 @@ impl<T> SliceIndex<[T]> for ops::RangeToInclusive<usize> {
#[inline]
fn get(self, slice: &[T]) -> Option<&[T]> {
(RangeInclusive { start: 0, end: self.end }).get(slice)
(0..=self.end).get(slice)
}
#[inline]
fn get_mut(self, slice: &mut [T]) -> Option<&mut [T]> {
(RangeInclusive { start: 0, end: self.end }).get_mut(slice)
(0..=self.end).get_mut(slice)
}
#[inline]
unsafe fn get_unchecked(self, slice: &[T]) -> &[T] {
(RangeInclusive { start: 0, end: self.end }).get_unchecked(slice)
(0..=self.end).get_unchecked(slice)
}
#[inline]
unsafe fn get_unchecked_mut(self, slice: &mut [T]) -> &mut [T] {
(RangeInclusive { start: 0, end: self.end }).get_unchecked_mut(slice)
(0..=self.end).get_unchecked_mut(slice)
}
#[inline]
fn index(self, slice: &[T]) -> &[T] {
(RangeInclusive { start: 0, end: self.end }).index(slice)
(0..=self.end).index(slice)
}
#[inline]
fn index_mut(self, slice: &mut [T]) -> &mut [T] {
(RangeInclusive { start: 0, end: self.end }).index_mut(slice)
(0..=self.end).index_mut(slice)
}
}

View File

@ -165,7 +165,7 @@ impl<'a> CacheDecoder<'a> {
fn find_filemap_prev_bytepos(&self,
prev_bytepos: BytePos)
-> Option<(BytePos, StableFilemapId)> {
for (start, id) in self.prev_filemap_starts.range(BytePos(0) ... prev_bytepos).rev() {
for (start, id) in self.prev_filemap_starts.range(BytePos(0) ..= prev_bytepos).rev() {
return Some((*start, *id))
}

View File

@ -2203,7 +2203,7 @@ impl<'a> State<'a> {
if limits == ast::RangeLimits::HalfOpen {
self.s.word("..")?;
} else {
self.s.word("...")?;
self.s.word("..=")?;
}
if let Some(ref e) = *end {
self.print_expr_maybe_paren(e, fake_prec)?;

View File

@ -41,8 +41,8 @@ fn main() {
let raw_byte_string_lit_kind = LitKind::ByteStr(Rc::new(b"#\"two\"#".to_vec()));
assert_eq!(raw_byte_string.node, ExprKind::Lit(P(dummy_spanned(raw_byte_string_lit_kind))));
// check dotdotdot
let closed_range = quote_expr!(&cx, 0 ... 1);
// check dotdoteq
let closed_range = quote_expr!(&cx, 0 ..= 1);
assert_eq!(closed_range.node, ExprKind::Range(
Some(quote_expr!(&cx, 0)),
Some(quote_expr!(&cx, 1)),