Skip to content

Commit

Permalink
Feature gate *all* slice patterns. rust-lang#23121
Browse files Browse the repository at this point in the history
Until some backwards-compatibility hazards are fixed in rust-lang#23121,
these need to be unstable.

[breaking-change]
  • Loading branch information
brson committed Mar 27, 2015
1 parent 199bdcf commit 1639e51
Show file tree
Hide file tree
Showing 51 changed files with 93 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2408,9 +2408,13 @@ considered off, and using the features will result in a compiler error.

The currently implemented features of the reference compiler are:

* `advanced_slice_patterns` - see the [match expressions](#match-expressions)
* `advanced_slice_patterns` - See the [match expressions](#match-expressions)
section for discussion; the exact semantics of
slice patterns are subject to change.
slice patterns are subject to change, so some types
are still unstable.

* `slice_patterns` - OK, actually, slice patterns are just scary and
completely unstable.

* `asm` - The `asm!` macro provides a means for inline assembly. This is often
useful, but the exact syntax for this feature along with its
Expand Down Expand Up @@ -3329,7 +3333,7 @@ array, like `[.., 42, ..]`. If preceded by a variable name, it will bind the
corresponding slice to the variable. Example:

```
# #![feature(advanced_slice_patterns)]
# #![feature(advanced_slice_patterns, slice_patterns)]
fn is_symmetric(list: &[u32]) -> bool {
match list {
[] | [_] => true,
Expand Down
1 change: 1 addition & 0 deletions src/doc/trpl/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ match origin {
If you want to match against a slice or array, you can use `&`:

```{rust}
# #![feature(slice_patterns)]
fn main() {
let v = vec!["match_this", "1"];
Expand Down
1 change: 1 addition & 0 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#![feature(step_by)]
#![feature(str_char)]
#![feature(convert)]
#![feature(slice_patterns)]
#![cfg_attr(test, feature(rand, rustc_private, test, hash, collections))]
#![cfg_attr(test, allow(deprecated))] // rand

Expand Down
1 change: 1 addition & 0 deletions src/libcoretest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#![feature(debug_builders)]
#![feature(unique)]
#![feature(step_by)]
#![feature(slice_patterns)]
#![allow(deprecated)] // rand

extern crate core;
Expand Down
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#![feature(str_char)]
#![feature(convert)]
#![feature(into_cow)]
#![feature(slice_patterns)]
#![cfg_attr(test, feature(test))]

#![allow(trivial_casts)]
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#![feature(path_ext)]
#![feature(path_relative_from)]
#![feature(convert)]
#![feature(slice_patterns)]

extern crate arena;
extern crate getopts;
Expand Down
1 change: 1 addition & 0 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
#![feature(allow_internal_unstable)]
#![feature(str_char)]
#![feature(into_cow)]
#![feature(slice_patterns)]
#![cfg_attr(test, feature(test, rustc_private, std_misc))]

// Don't link to std. We are std.
Expand Down
8 changes: 8 additions & 0 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
// below (it has to be checked before expansion possibly makes
// macros disappear).
("allow_internal_unstable", "1.0.0", Active),

// #23121. Array patterns have some hazards yet.
("slice_patterns", "1.0.0", Active),
];
// (changing above list without updating src/doc/reference.md makes @cmr sad)

Expand Down Expand Up @@ -694,6 +697,11 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
but at the end of a slice (e.g. \
`[0, ..xs, 0]` are experimental")
}
ast::PatVec(..) => {
self.gate_feature("slice_patterns",
pattern.span,
"slice pattern syntax is experimental");
}
ast::PatBox(..) => {
self.gate_feature("box_patterns",
pattern.span,
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#![feature(str_char)]
#![feature(convert)]
#![feature(into_cow)]
#![feature(slice_patterns)]

extern crate arena;
extern crate fmt_macros;
Expand Down
1 change: 1 addition & 0 deletions src/test/auxiliary/roman_numerals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#![crate_type="dylib"]
#![feature(plugin_registrar, rustc_private)]
#![feature(slice_patterns)]

extern crate syntax;
extern crate rustc;
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/borrowck-match-binding-is-assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// Test that immutable pattern bindings cannot be reassigned.

#![feature(slice_patterns)]

enum E {
Foo(isize)
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/borrowck-move-out-of-vec-tail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// Test that we do not permit moves from &[] matched by a vec pattern.

#![feature(slice_patterns)]

#[derive(Clone, Debug)]
struct Foo {
string: String
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/borrowck-vec-pattern-element-loan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

#![feature(advanced_slice_patterns)]
#![feature(slice_patterns)]

fn a<'a>() -> &'a [isize] {
let vec = vec!(1, 2, 3, 4);
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

fn a() {
let mut v = vec!(1, 2, 3);
let vb: &mut [isize] = &mut v;
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/borrowck-vec-pattern-move-tail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

fn main() {
let mut a = [1, 2, 3, 4];
let t = match a {
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/borrowck-vec-pattern-nesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#![feature(advanced_slice_patterns)]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(slice_patterns)]

fn a() {
let mut vec = [box 1, box 2, box 3];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

fn a<'a>() -> &'a isize {
let vec = vec!(1, 2, 3, 4);
let vec: &[isize] = &vec; //~ ERROR `vec` does not live long enough
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/feature-gate-advanced-slice-features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

fn main() {
let x = [ 1, 2, 3, 4, 5 ];
match x {
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/issue-12369.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

fn main() {
let sl = vec![1,2,3];
let v: isize = match &*sl {
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/issue-12567.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

fn match_vecs<'a, T>(l1: &'a [T], l2: &'a [T]) {
match (l1, l2) {
([], []) => println!("both empty"),
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/issue-13482-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// compile-flags:-Z verbose

#![feature(slice_patterns)]

fn main() {
let x = [1,2];
let y = match x {
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/issue-13482.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

fn main() {
let x = [1,2];
let y = match x {
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/issue-15381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

fn main() {
let values: Vec<u8> = vec![1,2,3,4,5,6,7,8];

Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/issue-6804.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

#![feature(rustc_attrs)]
#![feature(slice_patterns)]
#![allow(dead_code)]

// Matching against NaN should result in a warning
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/match-ref-ice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

// The arity of `ref x` is always 1. If the pattern is compared to some non-structural type whose
// arity is always 0, an ICE occurs.
//
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/match-vec-fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

fn a() {
let v = [1, 2, 3];
match v {
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/match-vec-mismatch-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

fn main() {
match () {
[()] => { }
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/match-vec-mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

fn main() {
match "foo".to_string() {
['f', 'o', ..] => {} //~ ERROR mismatched types
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/match-vec-unreachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

fn main() {
let x: Vec<(isize, isize)> = Vec::new();
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/non-exhaustive-match-nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

enum t { a(u), b }
enum u { c, d }

Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/non-exhaustive-match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

enum t { a, b, }

fn main() {
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/non-exhaustive-pattern-witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

#![feature(advanced_slice_patterns)]
#![feature(slice_patterns)]

struct Foo {
first: bool,
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/regions-pattern-typing-issue-19552.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

fn assert_static<T: 'static>(_t: T) {}

fn main() {
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-make/graphviz-flowgraph/f07.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(slice_patterns)]

pub fn pat_vec_7() {
match [7, 77, 777, 7777] {
[x, y, ..] => x + y
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/destructure-array-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

// pretty-expanded FIXME #23616

#![feature(slice_patterns)]

struct D { x: u8 }

impl Drop for D { fn drop(&mut self) { } }
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/ignore-all-the-things.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// pretty-expanded FIXME #23616

#![feature(advanced_slice_patterns)]
#![feature(slice_patterns)]

struct Foo(int, int, int, int);
struct Bar{a: int, b: int, c: int, d: int}
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/issue-13027.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// Tests that match expression handles overlapped literal and range
// properly in the presence of guard function.

#![feature(slice_patterns)]

fn val() -> uint { 1 }

static CONST: uint = 1;
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/issue-15080.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// pretty-expanded FIXME #23616

#![feature(slice_patterns)]

fn main() {
let mut x: &[_] = &[1, 2, 3, 4];

Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/issue-15104.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// pretty-expanded FIXME #23616

#![feature(slice_patterns)]

fn main() {
assert_eq!(count_members(&[1, 2, 3, 4]), 4);
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/issue-16648.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// pretty-expanded FIXME #23616

#![feature(slice_patterns)]

fn main() {
let x: (int, &[int]) = (2, &[1, 2]);
assert_eq!(match x {
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/issue-17877.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// pretty-expanded FIXME #23616

#![feature(slice_patterns)]

fn main() {
assert_eq!(match [0u8; 1024] {
_ => 42_usize,
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/issue-7784.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// pretty-expanded FIXME #23616

#![feature(advanced_slice_patterns)]
#![feature(slice_patterns)]

use std::ops::Add;

Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/match-vec-alternatives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// pretty-expanded FIXME #23616

#![feature(advanced_slice_patterns)]
#![feature(slice_patterns)]

fn match_vecs<'a, T>(l1: &'a [T], l2: &'a [T]) -> &'static str {
match (l1, l2) {
Expand Down
Loading

0 comments on commit 1639e51

Please sign in to comment.