syntax: Remove parsing of old slice syntax

This syntax has been deprecated for quite some time, and there were only a few
remaining uses of it in the codebase anyway.
This commit is contained in:
Alex Crichton 2015-03-26 09:57:58 -07:00
parent a923278c62
commit 77de3ee6e5
7 changed files with 24 additions and 83 deletions

View File

@ -553,7 +553,7 @@ impl<T> VecDeque<T> {
/// *num = *num - 2;
/// }
/// let b: &[_] = &[&mut 3, &mut 1, &mut 2];
/// assert_eq!(&buf.iter_mut().collect::<Vec<&mut i32>>()[], b);
/// assert_eq!(&buf.iter_mut().collect::<Vec<&mut i32>>()[..], b);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn iter_mut(&mut self) -> IterMut<T> {

View File

@ -510,37 +510,37 @@ mod test {
writer.write_all(&[0, 1]).unwrap();
let b: &[_] = &[];
assert_eq!(&writer.get_ref()[], b);
assert_eq!(&writer.get_ref()[..], b);
writer.write_all(&[2]).unwrap();
let b: &[_] = &[0, 1];
assert_eq!(&writer.get_ref()[], b);
assert_eq!(&writer.get_ref()[..], b);
writer.write_all(&[3]).unwrap();
assert_eq!(&writer.get_ref()[], b);
assert_eq!(&writer.get_ref()[..], b);
writer.flush().unwrap();
let a: &[_] = &[0, 1, 2, 3];
assert_eq!(a, &writer.get_ref()[]);
assert_eq!(a, &writer.get_ref()[..]);
writer.write_all(&[4]).unwrap();
writer.write_all(&[5]).unwrap();
assert_eq!(a, &writer.get_ref()[]);
assert_eq!(a, &writer.get_ref()[..]);
writer.write_all(&[6]).unwrap();
let a: &[_] = &[0, 1, 2, 3, 4, 5];
assert_eq!(a, &writer.get_ref()[]);
assert_eq!(a, &writer.get_ref()[..]);
writer.write_all(&[7, 8]).unwrap();
let a: &[_] = &[0, 1, 2, 3, 4, 5, 6];
assert_eq!(a, &writer.get_ref()[]);
assert_eq!(a, &writer.get_ref()[..]);
writer.write_all(&[9, 10, 11]).unwrap();
let a: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
assert_eq!(a, &writer.get_ref()[]);
assert_eq!(a, &writer.get_ref()[..]);
writer.flush().unwrap();
assert_eq!(a, &writer.get_ref()[]);
assert_eq!(a, &writer.get_ref()[..]);
}
#[test]
@ -548,7 +548,7 @@ mod test {
let mut w = BufferedWriter::with_capacity(3, Vec::new());
w.write_all(&[0, 1]).unwrap();
let a: &[_] = &[];
assert_eq!(a, &w.get_ref()[]);
assert_eq!(a, &w.get_ref()[..]);
let w = w.into_inner();
let a: &[_] = &[0, 1];
assert_eq!(a, &w[..]);
@ -593,21 +593,21 @@ mod test {
let mut writer = LineBufferedWriter::new(Vec::new());
writer.write_all(&[0]).unwrap();
let b: &[_] = &[];
assert_eq!(&writer.get_ref()[], b);
assert_eq!(&writer.get_ref()[..], b);
writer.write_all(&[1]).unwrap();
assert_eq!(&writer.get_ref()[], b);
assert_eq!(&writer.get_ref()[..], b);
writer.flush().unwrap();
let b: &[_] = &[0, 1];
assert_eq!(&writer.get_ref()[], b);
assert_eq!(&writer.get_ref()[..], b);
writer.write_all(&[0, b'\n', 1, b'\n', 2]).unwrap();
let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n'];
assert_eq!(&writer.get_ref()[], b);
assert_eq!(&writer.get_ref()[..], b);
writer.flush().unwrap();
let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n', 2];
assert_eq!(&writer.get_ref()[], b);
assert_eq!(&writer.get_ref()[..], b);
writer.write_all(&[3, b'\n']).unwrap();
let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n', 2, 3, b'\n'];
assert_eq!(&writer.get_ref()[], b);
assert_eq!(&writer.get_ref()[..], b);
}
#[test]

View File

@ -23,7 +23,6 @@ use ptr::P;
#[derive(Copy, PartialEq, Eq, Hash)]
pub enum ObsoleteSyntax {
ClosureKind,
EmptyIndex,
ExternCrateString,
}
@ -52,11 +51,6 @@ impl<'a> ParserObsoleteMethods for parser::Parser<'a> {
"rely on inference instead",
true,
),
ObsoleteSyntax::EmptyIndex => (
"[]",
"write `[..]` instead",
false, // warning for now
),
ObsoleteSyntax::ExternCrateString => (
"\"crate-name\"",
"use an identifier not in quotes instead",

View File

@ -2312,46 +2312,13 @@ impl<'a> Parser<'a> {
// expr[...]
// Could be either an index expression or a slicing expression.
token::OpenDelim(token::Bracket) => {
let bracket_pos = self.span.lo;
self.bump();
if self.eat(&token::CloseDelim(token::Bracket)) {
// No expression, expand to a RangeFull
// FIXME(#20516) It would be better to use a lang item or
// something for RangeFull.
hi = self.last_span.hi;
let idents = vec![token::str_to_ident("std"),
token::str_to_ident("ops"),
token::str_to_ident("RangeFull")];
let segments = idents.into_iter().map(|ident| {
ast::PathSegment {
identifier: ident,
parameters: ast::PathParameters::none(),
}
}).collect();
let span = mk_sp(lo, hi);
let path = ast::Path {
span: span,
global: true,
segments: segments,
};
let range = ExprStruct(path, vec![], None);
let ix = self.mk_expr(bracket_pos, hi, range);
let index = self.mk_index(e, ix);
e = self.mk_expr(lo, hi, index);
let obsolete_span = mk_sp(bracket_pos, hi);
self.obsolete(obsolete_span, ObsoleteSyntax::EmptyIndex);
} else {
let ix = self.parse_expr();
hi = self.span.hi;
self.commit_expr_expecting(&*ix, token::CloseDelim(token::Bracket));
let index = self.mk_index(e, ix);
e = self.mk_expr(lo, hi, index)
}
let ix = self.parse_expr();
hi = self.span.hi;
self.commit_expr_expecting(&*ix, token::CloseDelim(token::Bracket));
let index = self.mk_index(e, ix);
e = self.mk_expr(lo, hi, index)
}
_ => return e
}

View File

@ -47,7 +47,7 @@ impl Noise2DContext {
let mut rng = StdRng::new().unwrap();
let mut rgradients = [Vec2 { x: 0.0, y: 0.0 }; 256];
for x in &mut rgradients[] {
for x in &mut rgradients[..] {
*x = random_gradient(&mut rng);
}

View File

@ -1,20 +0,0 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test slicing &expr[] is deprecated and gives a helpful error message.
struct Foo;
fn main() {
let x = Foo;
&x[];
//~^ WARN obsolete syntax
//~| ERROR cannot index
}

View File

@ -28,7 +28,7 @@ fn main() {
// checking that it ends_with the executable name. This
// is needed because of Windows, which has a different behavior.
// See #15149 for more info.
return assert!(args[0].ends_with(&format!("mytest{}", env::consts::EXE_SUFFIX)[]));
return assert!(args[0].ends_with(&format!("mytest{}", env::consts::EXE_SUFFIX)));
}
test();