From 77de3ee6e572b66c9b0ee9d7d909fced980fe70f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 26 Mar 2015 09:57:58 -0700 Subject: [PATCH] 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. --- src/libcollections/vec_deque.rs | 2 +- src/libstd/old_io/buffered.rs | 32 ++++++++++++------------ src/libsyntax/parse/obsolete.rs | 6 ----- src/libsyntax/parse/parser.rs | 43 ++++---------------------------- src/test/bench/noise.rs | 2 +- src/test/compile-fail/slice-1.rs | 20 --------------- src/test/run-pass/issue-15149.rs | 2 +- 7 files changed, 24 insertions(+), 83 deletions(-) delete mode 100644 src/test/compile-fail/slice-1.rs diff --git a/src/libcollections/vec_deque.rs b/src/libcollections/vec_deque.rs index af9db46f810..a9884b80e42 100644 --- a/src/libcollections/vec_deque.rs +++ b/src/libcollections/vec_deque.rs @@ -553,7 +553,7 @@ impl VecDeque { /// *num = *num - 2; /// } /// let b: &[_] = &[&mut 3, &mut 1, &mut 2]; - /// assert_eq!(&buf.iter_mut().collect::>()[], b); + /// assert_eq!(&buf.iter_mut().collect::>()[..], b); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn iter_mut(&mut self) -> IterMut { diff --git a/src/libstd/old_io/buffered.rs b/src/libstd/old_io/buffered.rs index 9a9d421dfe1..9c42fbf5c16 100644 --- a/src/libstd/old_io/buffered.rs +++ b/src/libstd/old_io/buffered.rs @@ -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] diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 276be73823a..bb9b586bb3f 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -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", diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 220ea30256e..d016576238c 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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 } diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs index 6cd75836187..42051e33e2e 100644 --- a/src/test/bench/noise.rs +++ b/src/test/bench/noise.rs @@ -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); } diff --git a/src/test/compile-fail/slice-1.rs b/src/test/compile-fail/slice-1.rs deleted file mode 100644 index 3b992e3bcc3..00000000000 --- a/src/test/compile-fail/slice-1.rs +++ /dev/null @@ -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 or the MIT license -// , 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 -} diff --git a/src/test/run-pass/issue-15149.rs b/src/test/run-pass/issue-15149.rs index 0e194860251..ee348d9cb0c 100644 --- a/src/test/run-pass/issue-15149.rs +++ b/src/test/run-pass/issue-15149.rs @@ -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();