Skip to content

Commit 2d38234

Browse files
committed
Put slicing syntax behind a feature gate.
[breaking-change] If you are using slicing syntax you will need to add #![feature(slicing_syntax)] to your crate.
1 parent 5997694 commit 2d38234

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+101
-39
lines changed

src/compiletest/compiletest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
#![crate_type = "bin"]
12-
#![feature(phase)]
12+
#![feature(phase, slicing_syntax)]
1313

1414
#![deny(warnings)]
1515

src/doc/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3837,7 +3837,7 @@ type signature of `print`, and the cast expression in `main`.
38373837
Within the body of an item that has type parameter declarations, the names of
38383838
its type parameters are types:
38393839

3840-
```
3840+
```ignore
38413841
fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> Vec<B> {
38423842
if xs.len() == 0 {
38433843
return vec![];

src/libcollections/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
html_root_url = "http://doc.rust-lang.org/master/",
2020
html_playground_url = "http://play.rust-lang.org/")]
2121

22+
#![allow(unknown_features)]
2223
#![feature(macro_rules, default_type_params, phase, globs)]
23-
#![feature(unsafe_destructor, import_shadowing)]
24+
#![feature(unsafe_destructor, import_shadowing, slicing_syntax)]
2425
#![no_std]
2526

2627
#[phase(plugin, link)] extern crate core;

src/libcollections/slice.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@
5252
//! interval `[a, b)`:
5353
//!
5454
//! ```rust
55-
//! let numbers = [0i, 1i, 2i];
56-
//! let last_numbers = numbers[1..3];
57-
//! // last_numbers is now &[1i, 2i]
55+
//! #![feature(slicing_syntax)]
56+
//! fn main() {
57+
//! let numbers = [0i, 1i, 2i];
58+
//! let last_numbers = numbers[1..3];
59+
//! // last_numbers is now &[1i, 2i]
60+
//! }
5861
//! ```
5962
//!
6063
//! ## Implementations of other traits

src/libcore/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@
5757
html_playground_url = "http://play.rust-lang.org/")]
5858

5959
#![no_std]
60+
#![allow(unknown_features)]
6061
#![feature(globs, intrinsics, lang_items, macro_rules, phase)]
61-
#![feature(simd, unsafe_destructor)]
62+
#![feature(simd, unsafe_destructor, slicing_syntax)]
6263
#![deny(missing_doc)]
6364

6465
mod macros;

src/libcore/ops.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ pub trait IndexMut<Index, Result> {
684684
* A trivial implementation of `Slice`. When `Foo[..Foo]` happens, it ends up
685685
* calling `slice_to`, and therefore, `main` prints `Slicing!`.
686686
*
687-
* ```
687+
* ```ignore
688688
* struct Foo;
689689
*
690690
* impl ::core::ops::Slice<Foo, Foo> for Foo {
@@ -734,7 +734,7 @@ pub trait Slice<Idx, Sized? Result> for Sized? {
734734
* A trivial implementation of `SliceMut`. When `Foo[Foo..]` happens, it ends up
735735
* calling `slice_from_mut`, and therefore, `main` prints `Slicing!`.
736736
*
737-
* ```
737+
* ```ignore
738738
* struct Foo;
739739
*
740740
* impl ::core::ops::SliceMut<Foo, Foo> for Foo {
@@ -756,7 +756,7 @@ pub trait Slice<Idx, Sized? Result> for Sized? {
756756
* }
757757
* }
758758
*
759-
* fn main() {
759+
* pub fn main() {
760760
* Foo[mut Foo..];
761761
* }
762762
* ```

src/libcoretest/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10-
#![feature(globs, unsafe_destructor, macro_rules)]
10+
#![feature(globs, unsafe_destructor, macro_rules, slicing_syntax)]
1111

1212
extern crate core;
1313
extern crate test;

src/libnative/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757

5858
#![deny(unused_result, unused_must_use)]
5959
#![allow(non_camel_case_types, deprecated)]
60-
#![feature(default_type_params, lang_items)]
60+
#![allow(unknown_features)]
61+
#![feature(default_type_params, lang_items, slicing_syntax)]
6162

6263
// NB this crate explicitly does *not* allow glob imports, please seriously
6364
// consider whether they're needed before adding that feature here (the

src/libnum/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
//!
4444
//! [newt]: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
4545
46-
#![feature(macro_rules)]
46+
#![allow(unknown_features)]
47+
#![feature(macro_rules, slicing_syntax)]
4748
#![feature(default_type_params)]
4849

4950
#![crate_name = "num"]

src/librbml/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2525
html_root_url = "http://doc.rust-lang.org/master/",
2626
html_playground_url = "http://play.rust-lang.org/")]
27-
#![feature(macro_rules, phase)]
27+
#![allow(unknown_features)]
28+
#![feature(macro_rules, phase, slicing_syntax)]
2829
#![allow(missing_doc)]
2930

3031
extern crate serialize;

src/libregex/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@
368368
html_root_url = "http://doc.rust-lang.org/master/",
369369
html_playground_url = "http://play.rust-lang.org/")]
370370

371-
#![feature(macro_rules, phase)]
371+
#![allow(unknown_features)]
372+
#![feature(macro_rules, phase, slicing_syntax)]
372373
#![deny(missing_doc)]
373374

374375
#[cfg(test)]

src/librustc/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ This API is completely unstable and subject to change.
2929
html_root_url = "http://doc.rust-lang.org/master/")]
3030

3131
#![allow(deprecated)]
32+
#![allow(unknown_features)]
3233
#![feature(macro_rules, globs, struct_variant, quote)]
33-
#![feature(default_type_params, phase, unsafe_destructor)]
34+
#![feature(default_type_params, phase, unsafe_destructor, slicing_syntax)]
3435

3536
#![feature(rustc_diagnostic_macros)]
3637
#![feature(import_shadowing)]

src/librustc_back/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
3232
html_root_url = "http://doc.rust-lang.org/")]
3333

34-
#![feature(globs, phase, macro_rules)]
34+
#![allow(unknown_features)]
35+
#![feature(globs, phase, macro_rules, slicing_syntax)]
3536

3637
#[phase(plugin, link)]
3738
extern crate log;

src/librustdoc/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
#![crate_type = "dylib"]
1616
#![crate_type = "rlib"]
1717

18-
#![feature(globs, struct_variant, macro_rules, phase)]
18+
#![allow(unknown_features)]
19+
#![feature(globs, struct_variant, macro_rules, phase, slicing_syntax)]
1920

2021
extern crate arena;
2122
extern crate debug;

src/librustrt/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
1717
html_root_url = "http://doc.rust-lang.org/master/")]
1818

19+
#![allow(unknown_features)]
1920
#![feature(macro_rules, phase, globs, thread_local, asm)]
2021
#![feature(linkage, lang_items, unsafe_destructor, default_type_params)]
21-
#![feature(import_shadowing)]
22+
#![feature(import_shadowing, slicing_syntax)]
2223
#![no_std]
2324
#![experimental]
2425

src/libserialize/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ Core encoding and decoding interfaces.
2323
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2424
html_root_url = "http://doc.rust-lang.org/master/",
2525
html_playground_url = "http://play.rust-lang.org/")]
26-
#![feature(macro_rules, default_type_params, phase)]
26+
#![allow(unknown_features)]
27+
#![feature(macro_rules, default_type_params, phase, slicing_syntax)]
2728

2829
// test harness access
2930
#[cfg(test)]

src/libstd/io/net/udp.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,29 @@ use rt::rtio;
3535
///
3636
/// ```rust,no_run
3737
/// # #![allow(unused_must_use)]
38+
/// #![feature(slicing_syntax)]
39+
///
3840
/// use std::io::net::udp::UdpSocket;
3941
/// use std::io::net::ip::{Ipv4Addr, SocketAddr};
42+
/// fn main() {
43+
/// let addr = SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 34254 };
44+
/// let mut socket = match UdpSocket::bind(addr) {
45+
/// Ok(s) => s,
46+
/// Err(e) => fail!("couldn't bind socket: {}", e),
47+
/// };
4048
///
41-
/// let addr = SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 34254 };
42-
/// let mut socket = match UdpSocket::bind(addr) {
43-
/// Ok(s) => s,
44-
/// Err(e) => fail!("couldn't bind socket: {}", e),
45-
/// };
46-
///
47-
/// let mut buf = [0, ..10];
48-
/// match socket.recv_from(buf) {
49-
/// Ok((amt, src)) => {
50-
/// // Send a reply to the socket we received data from
51-
/// let buf = buf[mut ..amt];
52-
/// buf.reverse();
53-
/// socket.send_to(buf, src);
49+
/// let mut buf = [0, ..10];
50+
/// match socket.recv_from(buf) {
51+
/// Ok((amt, src)) => {
52+
/// // Send a reply to the socket we received data from
53+
/// let buf = buf[mut ..amt];
54+
/// buf.reverse();
55+
/// socket.send_to(buf, src);
56+
/// }
57+
/// Err(e) => println!("couldn't receive a datagram: {}", e)
5458
/// }
55-
/// Err(e) => println!("couldn't receive a datagram: {}", e)
59+
/// drop(socket); // close the socket
5660
/// }
57-
/// drop(socket); // close the socket
5861
/// ```
5962
pub struct UdpSocket {
6063
obj: Box<RtioUdpSocket + Send>,

src/libstd/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@
105105
html_root_url = "http://doc.rust-lang.org/master/",
106106
html_playground_url = "http://play.rust-lang.org/")]
107107

108+
#![allow(unknown_features)]
108109
#![feature(macro_rules, globs, linkage)]
109110
#![feature(default_type_params, phase, lang_items, unsafe_destructor)]
110-
#![feature(import_shadowing)]
111+
#![feature(import_shadowing, slicing_syntax)]
111112

112113
// Don't link to std. We are std.
113114
#![no_std]

src/libsyntax/feature_gate.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
7070
("tuple_indexing", Active),
7171
("associated_types", Active),
7272
("visible_private_types", Active),
73+
("slicing_syntax", Active),
7374

7475
("if_let", Active),
7576

@@ -350,6 +351,11 @@ impl<'a, 'v> Visitor<'v> for Context<'a> {
350351
self.gate_feature("if_let", e.span,
351352
"`if let` syntax is experimental");
352353
}
354+
ast::ExprSlice(..) => {
355+
self.gate_feature("slicing_syntax",
356+
e.span,
357+
"slicing syntax is experimental");
358+
}
353359
_ => {}
354360
}
355361
visit::walk_expr(self, e);

src/libsyntax/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2424
html_root_url = "http://doc.rust-lang.org/master/")]
2525

26-
#![feature(macro_rules, globs, default_type_params, phase)]
26+
#![allow(unknown_features)]
27+
#![feature(macro_rules, globs, default_type_params, phase, slicing_syntax)]
2728
#![feature(quote, struct_variant, unsafe_destructor, import_shadowing)]
2829
#![allow(deprecated)]
2930

src/libterm/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
html_root_url = "http://doc.rust-lang.org/master/",
5050
html_playground_url = "http://play.rust-lang.org/")]
5151

52-
#![feature(macro_rules, phase)]
52+
#![allow(unknown_features)]
53+
#![feature(macro_rules, phase, slicing_syntax)]
5354

5455
#![deny(missing_doc)]
5556

src/test/bench/shootout-fannkuch-redux.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
3939
// OF THE POSSIBILITY OF SUCH DAMAGE.
4040

41+
#![feature(slicing_syntax)]
42+
4143
use std::{cmp, iter, mem};
4244
use std::sync::Future;
4345

src/test/bench/shootout-fasta-redux.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
3939
// OF THE POSSIBILITY OF SUCH DAMAGE.
4040

41+
#![feature(slicing_syntax)]
42+
4143
use std::cmp::min;
4244
use std::io::{stdout, IoResult};
4345
use std::os;

src/test/bench/shootout-fasta.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
3939
// OF THE POSSIBILITY OF SUCH DAMAGE.
4040

41+
#![feature(slicing_syntax)]
42+
4143
use std::io;
4244
use std::io::{BufferedWriter, File};
4345
use std::cmp::min;

src/test/bench/shootout-k-nucleotide-pipes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
// multi tasking k-nucleotide
1515

16+
#![feature(slicing_syntax)]
17+
1618
extern crate collections;
1719

1820
use std::collections::HashMap;

src/test/bench/shootout-k-nucleotide.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040

4141
// ignore-android see #10393 #13206
4242

43+
#![feature(slicing_syntax)]
44+
4345
use std::string::String;
4446
use std::slice;
4547
use std::sync::{Arc, Future};

src/test/bench/shootout-regex-dna.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
// ignore-stage1
4242
// ignore-cross-compile #12102
4343

44-
#![feature(macro_rules, phase)]
44+
#![feature(macro_rules, phase, slicing_syntax)]
4545

4646
extern crate regex;
4747
#[phase(plugin)]extern crate regex_macros;

src/test/bench/shootout-reverse-complement.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
// ignore-pretty very bad with line comments
4242
// ignore-android doesn't terminate?
4343

44+
#![feature(slicing_syntax)]
45+
4446
use std::iter::range_step;
4547
use std::io::{stdin, stdout, File};
4648

src/test/compile-fail/issue-15730.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(slicing_syntax)]
12+
1113
fn main() {
1214
let mut array = [1, 2, 3];
1315
//~^ ERROR cannot determine a type for this local variable: cannot determine the type of this integ

src/test/compile-fail/slice-2.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// Test that slicing syntax gives errors if we have not implemented the trait.
1212

13+
#![feature(slicing_syntax)]
14+
1315
struct Foo;
1416

1517
fn main() {

src/test/compile-fail/slice-borrow.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// Test slicing expressions doesn't defeat the borrow checker.
1212

13+
#![feature(slicing_syntax)]
14+
1315
fn main() {
1416
let y;
1517
{

src/test/compile-fail/slice-mut-2.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// Test mutability and slicing syntax.
1212

13+
#![feature(slicing_syntax)]
14+
1315
fn main() {
1416
let x: &[int] = &[1, 2, 3, 4, 5];
1517
// Can't mutably slice an immutable slice

src/test/compile-fail/slice-mut.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// Test mutability and slicing syntax.
1212

13+
#![feature(slicing_syntax)]
14+
1315
fn main() {
1416
let x: &[int] = &[1, 2, 3, 4, 5];
1517
// Immutable slices are not mutable.

src/test/debuginfo/vec-slices.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
// lldb-check:[...]$5 = &[AStruct { x: 10, y: 11, z: 12 }, AStruct { x: 13, y: 14, z: 15 }]
8181

8282
#![allow(unused_variable)]
83+
#![feature(slicing_syntax)]
8384

8485
struct AStruct {
8586
x: i16,

0 commit comments

Comments
 (0)