Auto merge of #48516 - petrochenkov:stabsl, r=nikomatsakis
Stabilize slice patterns without `..` And merge `feature(advanced_slice_patterns)` into `feature(slice_patterns)`. The detailed description can be found in https://github.com/rust-lang/rust/issues/48836. Slice patterns were unstable for long time since before 1.0 due to many bugs in the implementation, now this stabilization is possible primarily due to work of @arielb1 who [wrote the new MIR-based implementation of slice patterns](https://github.com/rust-lang/rust/pull/32202) and @mikhail-m1 who [fixed one remaining class of codegen issues](https://github.com/rust-lang/rust/pull/47926). Reference PR https://github.com/rust-lang-nursery/reference/pull/259 cc https://github.com/rust-lang/rust/issues/23121 fixes #48836
This commit is contained in:
commit
b99172311c
75 changed files with 125 additions and 227 deletions
|
@ -1,35 +0,0 @@
|
|||
# `advanced_slice_patterns`
|
||||
|
||||
The tracking issue for this feature is: [#23121]
|
||||
|
||||
[#23121]: https://github.com/rust-lang/rust/issues/23121
|
||||
|
||||
See also [`slice_patterns`](language-features/slice-patterns.html).
|
||||
|
||||
------------------------
|
||||
|
||||
|
||||
The `advanced_slice_patterns` gate lets you use `..` to indicate any number of
|
||||
elements inside a pattern matching a slice. This wildcard can only be used once
|
||||
for a given array. If there's an identifier before the `..`, the result of the
|
||||
slice will be bound to that name. For example:
|
||||
|
||||
```rust
|
||||
#![feature(advanced_slice_patterns, slice_patterns)]
|
||||
|
||||
fn is_symmetric(list: &[u32]) -> bool {
|
||||
match list {
|
||||
&[] | &[_] => true,
|
||||
&[x, ref inside.., y] if x == y => is_symmetric(inside),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let sym = &[0, 1, 4, 2, 4, 1, 0];
|
||||
assert!(is_symmetric(sym));
|
||||
|
||||
let not_sym = &[0, 1, 7, 2, 4, 1, 0];
|
||||
assert!(!is_symmetric(not_sym));
|
||||
}
|
||||
```
|
|
@ -4,25 +4,29 @@ The tracking issue for this feature is: [#23121]
|
|||
|
||||
[#23121]: https://github.com/rust-lang/rust/issues/23121
|
||||
|
||||
See also
|
||||
[`advanced_slice_patterns`](language-features/advanced-slice-patterns.html).
|
||||
|
||||
------------------------
|
||||
|
||||
|
||||
If you want to match against a slice or array, you can use `&` with the
|
||||
`slice_patterns` feature:
|
||||
The `slice_patterns` feature gate lets you use `..` to indicate any number of
|
||||
elements inside a pattern matching a slice. This wildcard can only be used once
|
||||
for a given array. If there's an pattern before the `..`, the subslice will be
|
||||
matched against that pattern. For example:
|
||||
|
||||
```rust
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn main() {
|
||||
let v = vec!["match_this", "1"];
|
||||
|
||||
match &v[..] {
|
||||
&["match_this", second] => println!("The second element is {}", second),
|
||||
_ => {},
|
||||
fn is_symmetric(list: &[u32]) -> bool {
|
||||
match list {
|
||||
&[] | &[_] => true,
|
||||
&[x, ref inside.., y] if x == y => is_symmetric(inside),
|
||||
&[..] => false,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
fn main() {
|
||||
let sym = &[0, 1, 4, 2, 4, 1, 0];
|
||||
assert!(is_symmetric(sym));
|
||||
|
||||
let not_sym = &[0, 1, 7, 2, 4, 1, 0];
|
||||
assert!(!is_symmetric(not_sym));
|
||||
}
|
||||
```
|
||||
|
|
|
@ -111,7 +111,6 @@
|
|||
#![feature(ptr_internals)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(slice_get_slice)]
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(slice_rsplit)]
|
||||
#![feature(specialization)]
|
||||
#![feature(staged_api)]
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#![deny(warnings)]
|
||||
|
||||
#![feature(flt2dec)]
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(test)]
|
||||
|
||||
extern crate core;
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#![feature(raw)]
|
||||
#![feature(refcell_replace_swap)]
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(slice_rotate)]
|
||||
#![feature(sort_internals)]
|
||||
#![feature(specialization)]
|
||||
#![feature(step_trait)]
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
#![deny(warnings)]
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
#![forbid(unsafe_code)]
|
||||
|
||||
#![feature(i128_type)]
|
||||
#![feature(slice_patterns)]
|
||||
#![cfg_attr(stage0, feature(slice_patterns))]
|
||||
#![feature(try_from)]
|
||||
|
||||
// See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#![deny(warnings)]
|
||||
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(macro_lifetime_matcher)]
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#![feature(macro_vis_matcher)]
|
||||
#![feature(quote)]
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
#![feature(slice_patterns)]
|
||||
#![cfg_attr(stage0, feature(never_type))]
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#![feature(libc)]
|
||||
#![feature(quote)]
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
#![feature(slice_patterns)]
|
||||
#![cfg_attr(stage0, feature(slice_patterns))]
|
||||
#![feature(conservative_impl_trait)]
|
||||
#![feature(optin_builtin_traits)]
|
||||
#![feature(inclusive_range_fields)]
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#![feature(i128_type)]
|
||||
#![feature(quote)]
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(conservative_impl_trait)]
|
||||
|
||||
extern crate ar;
|
||||
|
|
|
@ -3559,8 +3559,6 @@ elements in the array being matched.
|
|||
Example of erroneous code:
|
||||
|
||||
```compile_fail,E0527
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
let r = &[1, 2, 3, 4];
|
||||
match r {
|
||||
&[a, b] => { // error: pattern requires 2 elements but array
|
||||
|
@ -3625,8 +3623,6 @@ An array or slice pattern was matched against some other type.
|
|||
Example of erroneous code:
|
||||
|
||||
```compile_fail,E0529
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
let r: f32 = 1.0;
|
||||
match r {
|
||||
[a, b] => { // error: expected an array or slice, found `f32`
|
||||
|
@ -3639,8 +3635,6 @@ Ensure that the pattern and the expression being matched on are of consistent
|
|||
types:
|
||||
|
||||
```
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
let r = [1.0, 2.0];
|
||||
match r {
|
||||
[a, b] => { // ok!
|
||||
|
|
|
@ -72,7 +72,7 @@ This API is completely unstable and subject to change.
|
|||
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
#![feature(advanced_slice_patterns)]
|
||||
#![cfg_attr(stage0, feature(advanced_slice_patterns))]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(conservative_impl_trait)]
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#![feature(box_syntax)]
|
||||
#![feature(fs_read_write)]
|
||||
#![feature(set_stdio)]
|
||||
#![feature(slice_patterns)]
|
||||
#![cfg_attr(stage0, feature(slice_patterns))]
|
||||
#![feature(test)]
|
||||
#![feature(unicode)]
|
||||
#![feature(vec_remove_item)]
|
||||
|
|
|
@ -145,7 +145,6 @@ declare_features! (
|
|||
// rustc internal
|
||||
(active, rustc_diagnostic_macros, "1.0.0", None, None),
|
||||
(active, rustc_const_unstable, "1.0.0", None, None),
|
||||
(active, advanced_slice_patterns, "1.0.0", Some(23121), None),
|
||||
(active, box_syntax, "1.0.0", Some(27779), None),
|
||||
(active, placement_in_syntax, "1.0.0", Some(27779), None),
|
||||
(active, unboxed_closures, "1.0.0", Some(29625), None),
|
||||
|
@ -474,6 +473,8 @@ declare_features! (
|
|||
(removed, allocator, "1.0.0", None, None),
|
||||
// Allows the `#[simd]` attribute -- removed in favor of `#[repr(simd)]`
|
||||
(removed, simd, "1.0.0", Some(27731), None),
|
||||
// Merged into `slice_patterns`
|
||||
(removed, advanced_slice_patterns, "1.0.0", Some(23121), None),
|
||||
);
|
||||
|
||||
declare_features! (
|
||||
|
@ -1655,17 +1656,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
|||
|
||||
fn visit_pat(&mut self, pattern: &'a ast::Pat) {
|
||||
match pattern.node {
|
||||
PatKind::Slice(_, Some(_), ref last) if !last.is_empty() => {
|
||||
gate_feature_post!(&self, advanced_slice_patterns,
|
||||
pattern.span,
|
||||
"multiple-element slice matches anywhere \
|
||||
but at the end of a slice (e.g. \
|
||||
`[0, ..xs, 0]`) are experimental")
|
||||
}
|
||||
PatKind::Slice(..) => {
|
||||
PatKind::Slice(_, Some(ref subslice), _) => {
|
||||
gate_feature_post!(&self, slice_patterns,
|
||||
pattern.span,
|
||||
"slice pattern syntax is experimental");
|
||||
subslice.span,
|
||||
"syntax for subslices in slice patterns is not yet stabilized");
|
||||
}
|
||||
PatKind::Box(..) => {
|
||||
gate_feature_post!(&self, box_patterns,
|
||||
|
|
|
@ -3618,7 +3618,7 @@ impl<'a> Parser<'a> {
|
|||
slice = Some(P(Pat {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
node: PatKind::Wild,
|
||||
span: self.span,
|
||||
span: self.prev_span,
|
||||
}));
|
||||
before_slice = false;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
//[mir]compile-flags: -Z borrowck=mir
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(advanced_slice_patterns)]
|
||||
|
||||
pub struct Foo {
|
||||
x: u32
|
||||
|
|
|
@ -13,8 +13,6 @@
|
|||
|
||||
// Test that immutable pattern bindings cannot be reassigned.
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
enum E {
|
||||
Foo(isize)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
// revisions: ast mir
|
||||
//[mir]compile-flags: -Z borrowck=mir
|
||||
|
||||
#![feature(box_syntax, slice_patterns, advanced_slice_patterns)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn move_out_from_begin_and_end() {
|
||||
let a = [box 1, box 2];
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(advanced_slice_patterns)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn a<'a>() -> &'a [isize] {
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
// except according to those terms.
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
#![allow(unused_variables)]
|
||||
#![deny(unreachable_patterns)]
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
// compile-flags:-Z verbose
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn main() {
|
||||
let x = [1,2];
|
||||
let y = match x {
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
// 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 {
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
// 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];
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
// Matching against float literals should result in a linter error
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(exclusive_range_pattern)]
|
||||
#![allow(unused)]
|
||||
#![forbid(illegal_floating_point_literal_pattern)]
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
// Matching against NaN should result in a warning
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
#![allow(unused)]
|
||||
#![deny(illegal_floating_point_literal_pattern)]
|
||||
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(advanced_slice_patterns, slice_patterns)]
|
||||
|
||||
fn main() {
|
||||
let buf = &[0, 1, 2, 3];
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(advanced_slice_patterns, slice_patterns)]
|
||||
#![feature(slice_patterns)]
|
||||
#![deny(unreachable_patterns)]
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
#![deny(unreachable_patterns)]
|
||||
|
||||
// The arity of `ref x` is always 1. If the pattern is compared to some non-structural type whose
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(advanced_slice_patterns, slice_patterns)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn check(list: &[Option<()>]) {
|
||||
match list {
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
#![deny(unreachable_patterns)]
|
||||
|
||||
fn a() {
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn main() {
|
||||
match () {
|
||||
[()] => { }
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
#![feature(slice_patterns)]
|
||||
#![deny(unreachable_patterns)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
fn main() {
|
||||
let x: Vec<(isize, isize)> = Vec::new();
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(slice_patterns, box_patterns)]
|
||||
#![feature(box_patterns)]
|
||||
|
||||
struct A;
|
||||
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
// 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() {
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
enum Void {}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
// except according to those terms.
|
||||
|
||||
#![feature(box_patterns)]
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(exhaustive_patterns)]
|
||||
#![feature(slice_patterns)]
|
||||
#![deny(unreachable_patterns)]
|
||||
|
||||
mod foo {
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(box_syntax, slice_patterns, advanced_slice_patterns)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn move_out_from_end() {
|
||||
let a = [box 1, box 2];
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
|
||||
#![crate_type="dylib"]
|
||||
#![feature(plugin_registrar, rustc_private)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
extern crate syntax;
|
||||
extern crate syntax_pos;
|
||||
|
|
|
@ -11,9 +11,6 @@
|
|||
// Ensure that we can do a destructuring bind of a fixed-size array,
|
||||
// even when the element type has a destructor.
|
||||
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
struct D { x: u8 }
|
||||
|
||||
impl Drop for D { fn drop(&mut self) { } }
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
|
||||
// ignore-wasm32-bare compiled with panic=abort by default
|
||||
|
||||
#![feature(generators, generator_trait, untagged_unions, slice_patterns, advanced_slice_patterns)]
|
||||
#![feature(generators, generator_trait, untagged_unions)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::ops::Generator;
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
#![feature(advanced_slice_patterns)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
struct Foo(isize, isize, isize, isize);
|
||||
|
@ -20,11 +19,11 @@ pub fn main() {
|
|||
let Foo(..) = Foo(5, 5, 5, 5);
|
||||
let Foo(..) = Foo(5, 5, 5, 5);
|
||||
let Bar{..} = Bar{a: 5, b: 5, c: 5, d: 5};
|
||||
//let (..) = (5, 5, 5, 5);
|
||||
//let Foo(a, b, ..) = Foo(5, 5, 5, 5);
|
||||
//let Foo(.., d) = Foo(5, 5, 5, 5);
|
||||
//let (a, b, ..) = (5, 5, 5, 5);
|
||||
//let (.., c, d) = (5, 5, 5, 5);
|
||||
let (..) = (5, 5, 5, 5);
|
||||
let Foo(a, b, ..) = Foo(5, 5, 5, 5);
|
||||
let Foo(.., d) = Foo(5, 5, 5, 5);
|
||||
let (a, b, ..) = (5, 5, 5, 5);
|
||||
let (.., c, d) = (5, 5, 5, 5);
|
||||
let Bar{b: b, ..} = Bar{a: 5, b: 5, c: 5, d: 5};
|
||||
match [5, 5, 5, 5] {
|
||||
[..] => { }
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
// Tests that match expression handles overlapped literal and range
|
||||
// properly in the presence of guard function.
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn val() -> usize { 1 }
|
||||
|
||||
static CONST: usize = 1;
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -8,9 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn main() {
|
||||
let x: (isize, &[isize]) = (2, &[1, 2]);
|
||||
assert_eq!(match x {
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(advanced_slice_patterns, slice_patterns)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn check(list: &[u8]) {
|
||||
match list {
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
// Check that constant ADTs are translated OK, part k of N.
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
enum Bar {
|
||||
C
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
// compile-flags: -Zmir-opt-level=1
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
use std::mem;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(advanced_slice_patterns)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
use std::ops::Add;
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(advanced_slice_patterns)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn match_vecs<'a, T>(l1: &'a [T], l2: &'a [T]) -> &'static str {
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(match_default_bindings)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn slice_pat() {
|
||||
let sl: &[u8] = b"foo";
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
#![feature(advanced_slice_patterns,)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn f<T,>(_: T,) {}
|
||||
|
|
|
@ -8,9 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
pub fn main() {
|
||||
let x = [1, 2, 3];
|
||||
match x {
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(advanced_slice_patterns)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn a() {
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(advanced_slice_patterns)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![feature(advanced_slice_patterns)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn a() {
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
struct Foo {
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(advanced_slice_patterns)]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(slice_patterns)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error[E0506]: cannot assign to `vec[..]` because it is borrowed
|
||||
--> $DIR/borrowck-vec-pattern-nesting.rs:21:13
|
||||
--> $DIR/borrowck-vec-pattern-nesting.rs:20:13
|
||||
|
|
||||
LL | [box ref _a, _, _] => {
|
||||
| ------ borrow of `vec[..]` occurs here
|
||||
|
@ -8,7 +8,7 @@ LL | vec[0] = box 4; //~ ERROR cannot assign
|
|||
| ^^^^^^^^^^^^^^ assignment to borrowed `vec[..]` occurs here
|
||||
|
||||
error[E0506]: cannot assign to `vec[..]` because it is borrowed
|
||||
--> $DIR/borrowck-vec-pattern-nesting.rs:33:13
|
||||
--> $DIR/borrowck-vec-pattern-nesting.rs:32:13
|
||||
|
|
||||
LL | &mut [ref _b..] => {
|
||||
| ------ borrow of `vec[..]` occurs here
|
||||
|
@ -17,7 +17,7 @@ LL | vec[0] = box 4; //~ ERROR cannot assign
|
|||
| ^^^^^^^^^^^^^^ assignment to borrowed `vec[..]` occurs here
|
||||
|
||||
error[E0508]: cannot move out of type `[std::boxed::Box<isize>]`, a non-copy slice
|
||||
--> $DIR/borrowck-vec-pattern-nesting.rs:43:14
|
||||
--> $DIR/borrowck-vec-pattern-nesting.rs:42:14
|
||||
|
|
||||
LL | &mut [_a, //~ ERROR cannot move out
|
||||
| ^-- hint: to prevent move, use `ref _a` or `ref mut _a`
|
||||
|
@ -30,7 +30,7 @@ LL | | ] => {
|
|||
| |_________^ cannot move out of here
|
||||
|
||||
error[E0508]: cannot move out of type `[std::boxed::Box<isize>]`, a non-copy slice
|
||||
--> $DIR/borrowck-vec-pattern-nesting.rs:56:13
|
||||
--> $DIR/borrowck-vec-pattern-nesting.rs:55:13
|
||||
|
|
||||
LL | let a = vec[0]; //~ ERROR cannot move out
|
||||
| ^^^^^^
|
||||
|
@ -39,7 +39,7 @@ LL | let a = vec[0]; //~ ERROR cannot move out
|
|||
| help: consider using a reference instead: `&vec[0]`
|
||||
|
||||
error[E0508]: cannot move out of type `[std::boxed::Box<isize>]`, a non-copy slice
|
||||
--> $DIR/borrowck-vec-pattern-nesting.rs:64:14
|
||||
--> $DIR/borrowck-vec-pattern-nesting.rs:63:14
|
||||
|
|
||||
LL | &mut [ //~ ERROR cannot move out
|
||||
| ______________^
|
||||
|
@ -50,7 +50,7 @@ LL | | _b] => {}
|
|||
| hint: to prevent move, use `ref _b` or `ref mut _b`
|
||||
|
||||
error[E0508]: cannot move out of type `[std::boxed::Box<isize>]`, a non-copy slice
|
||||
--> $DIR/borrowck-vec-pattern-nesting.rs:69:13
|
||||
--> $DIR/borrowck-vec-pattern-nesting.rs:68:13
|
||||
|
|
||||
LL | let a = vec[0]; //~ ERROR cannot move out
|
||||
| ^^^^^^
|
||||
|
@ -59,7 +59,7 @@ LL | let a = vec[0]; //~ ERROR cannot move out
|
|||
| help: consider using a reference instead: `&vec[0]`
|
||||
|
||||
error[E0508]: cannot move out of type `[std::boxed::Box<isize>]`, a non-copy slice
|
||||
--> $DIR/borrowck-vec-pattern-nesting.rs:77:14
|
||||
--> $DIR/borrowck-vec-pattern-nesting.rs:76:14
|
||||
|
|
||||
LL | &mut [_a, _b, _c] => {} //~ ERROR cannot move out
|
||||
| ^--^^--^^--^
|
||||
|
@ -70,7 +70,7 @@ LL | &mut [_a, _b, _c] => {} //~ ERROR cannot move out
|
|||
| cannot move out of here
|
||||
|
||||
error[E0508]: cannot move out of type `[std::boxed::Box<isize>]`, a non-copy slice
|
||||
--> $DIR/borrowck-vec-pattern-nesting.rs:81:13
|
||||
--> $DIR/borrowck-vec-pattern-nesting.rs:80:13
|
||||
|
|
||||
LL | let a = vec[0]; //~ ERROR cannot move out
|
||||
| ^^^^^^
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn main() {
|
||||
let r = &[1, 2, 3, 4];
|
||||
match r {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error[E0527]: pattern requires 2 elements but array has 4
|
||||
--> $DIR/E0527.rs:16:10
|
||||
--> $DIR/E0527.rs:14:10
|
||||
|
|
||||
LL | &[a, b] => {
|
||||
| ^^^^^^ expected 4 elements
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn main() {
|
||||
let r: f32 = 1.0;
|
||||
match r {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error[E0529]: expected an array or slice, found `f32`
|
||||
--> $DIR/E0529.rs:16:9
|
||||
--> $DIR/E0529.rs:14:9
|
||||
|
|
||||
LL | [a, b] => {
|
||||
| ^^^^^^ pattern cannot match with input type `f32`
|
||||
|
|
|
@ -1,22 +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.
|
||||
|
||||
// gate-test-advanced_slice_patterns
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn main() {
|
||||
let x = [ 1, 2, 3, 4, 5 ];
|
||||
match x {
|
||||
[ xs.., 4, 5 ] => {} //~ ERROR multiple-element slice matches
|
||||
[ 1, xs.., 5 ] => {} //~ ERROR multiple-element slice matches
|
||||
[ 1, 2, xs.. ] => {} // OK without feature gate
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
error[E0658]: multiple-element slice matches anywhere but at the end of a slice (e.g. `[0, ..xs, 0]`) are experimental (see issue #23121)
|
||||
--> $DIR/feature-gate-advanced-slice-features.rs:18:9
|
||||
|
|
||||
LL | [ xs.., 4, 5 ] => {} //~ ERROR multiple-element slice matches
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: add #![feature(advanced_slice_patterns)] to the crate attributes to enable
|
||||
|
||||
error[E0658]: multiple-element slice matches anywhere but at the end of a slice (e.g. `[0, ..xs, 0]`) are experimental (see issue #23121)
|
||||
--> $DIR/feature-gate-advanced-slice-features.rs:19:9
|
||||
|
|
||||
LL | [ 1, xs.., 5 ] => {} //~ ERROR multiple-element slice matches
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: add #![feature(advanced_slice_patterns)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
|
@ -8,11 +8,20 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Test that slice pattern syntax is gated by `slice_patterns` feature gate
|
||||
// Test that slice pattern syntax with `..` is gated by `slice_patterns` feature gate
|
||||
|
||||
fn main() {
|
||||
let x = [1, 2, 3, 4, 5];
|
||||
match x {
|
||||
[1, 2, xs..] => {} //~ ERROR slice pattern syntax is experimental
|
||||
[1, 2, ..] => {} //~ ERROR syntax for subslices in slice patterns is not yet stabilized
|
||||
[1, .., 5] => {} //~ ERROR syntax for subslices in slice patterns is not yet stabilized
|
||||
[.., 4, 5] => {} //~ ERROR syntax for subslices in slice patterns is not yet stabilized
|
||||
}
|
||||
|
||||
let x = [ 1, 2, 3, 4, 5 ];
|
||||
match x {
|
||||
[ xs.., 4, 5 ] => {} //~ ERROR syntax for subslices in slice patterns is not yet stabilized
|
||||
[ 1, xs.., 5 ] => {} //~ ERROR syntax for subslices in slice patterns is not yet stabilized
|
||||
[ 1, 2, xs.. ] => {} //~ ERROR syntax for subslices in slice patterns is not yet stabilized
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,51 @@
|
|||
error[E0658]: slice pattern syntax is experimental (see issue #23121)
|
||||
--> $DIR/feature-gate-slice-patterns.rs:16:9
|
||||
error[E0658]: syntax for subslices in slice patterns is not yet stabilized (see issue #23121)
|
||||
--> $DIR/feature-gate-slice-patterns.rs:16:16
|
||||
|
|
||||
LL | [1, 2, xs..] => {} //~ ERROR slice pattern syntax is experimental
|
||||
| ^^^^^^^^^^^^
|
||||
LL | [1, 2, ..] => {} //~ ERROR syntax for subslices in slice patterns is not yet stabilized
|
||||
| ^^
|
||||
|
|
||||
= help: add #![feature(slice_patterns)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0658]: syntax for subslices in slice patterns is not yet stabilized (see issue #23121)
|
||||
--> $DIR/feature-gate-slice-patterns.rs:17:13
|
||||
|
|
||||
LL | [1, .., 5] => {} //~ ERROR syntax for subslices in slice patterns is not yet stabilized
|
||||
| ^^
|
||||
|
|
||||
= help: add #![feature(slice_patterns)] to the crate attributes to enable
|
||||
|
||||
error[E0658]: syntax for subslices in slice patterns is not yet stabilized (see issue #23121)
|
||||
--> $DIR/feature-gate-slice-patterns.rs:18:10
|
||||
|
|
||||
LL | [.., 4, 5] => {} //~ ERROR syntax for subslices in slice patterns is not yet stabilized
|
||||
| ^^
|
||||
|
|
||||
= help: add #![feature(slice_patterns)] to the crate attributes to enable
|
||||
|
||||
error[E0658]: syntax for subslices in slice patterns is not yet stabilized (see issue #23121)
|
||||
--> $DIR/feature-gate-slice-patterns.rs:23:11
|
||||
|
|
||||
LL | [ xs.., 4, 5 ] => {} //~ ERROR syntax for subslices in slice patterns is not yet stabilized
|
||||
| ^^
|
||||
|
|
||||
= help: add #![feature(slice_patterns)] to the crate attributes to enable
|
||||
|
||||
error[E0658]: syntax for subslices in slice patterns is not yet stabilized (see issue #23121)
|
||||
--> $DIR/feature-gate-slice-patterns.rs:24:14
|
||||
|
|
||||
LL | [ 1, xs.., 5 ] => {} //~ ERROR syntax for subslices in slice patterns is not yet stabilized
|
||||
| ^^
|
||||
|
|
||||
= help: add #![feature(slice_patterns)] to the crate attributes to enable
|
||||
|
||||
error[E0658]: syntax for subslices in slice patterns is not yet stabilized (see issue #23121)
|
||||
--> $DIR/feature-gate-slice-patterns.rs:25:17
|
||||
|
|
||||
LL | [ 1, 2, xs.. ] => {} //~ ERROR syntax for subslices in slice patterns is not yet stabilized
|
||||
| ^^
|
||||
|
|
||||
= help: add #![feature(slice_patterns)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
// <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.
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
|
||||
struct Foo {
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-38371.rs:16:8
|
||||
--> $DIR/issue-38371.rs:14:8
|
||||
|
|
||||
LL | fn foo(&foo: Foo) { //~ ERROR mismatched types
|
||||
| ^^^^ expected struct `Foo`, found reference
|
||||
|
@ -9,7 +9,7 @@ LL | fn foo(&foo: Foo) { //~ ERROR mismatched types
|
|||
= help: did you mean `foo: &Foo`?
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-38371.rs:30:9
|
||||
--> $DIR/issue-38371.rs:28:9
|
||||
|
|
||||
LL | fn agh(&&bar: &u32) { //~ ERROR mismatched types
|
||||
| ^^^^ expected u32, found reference
|
||||
|
@ -19,7 +19,7 @@ LL | fn agh(&&bar: &u32) { //~ ERROR mismatched types
|
|||
= help: did you mean `bar: &u32`?
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-38371.rs:33:8
|
||||
--> $DIR/issue-38371.rs:31:8
|
||||
|
|
||||
LL | fn bgh(&&bar: u32) { //~ ERROR mismatched types
|
||||
| ^^^^^ expected u32, found reference
|
||||
|
@ -28,7 +28,7 @@ LL | fn bgh(&&bar: u32) { //~ ERROR mismatched types
|
|||
found type `&_`
|
||||
|
||||
error[E0529]: expected an array or slice, found `u32`
|
||||
--> $DIR/issue-38371.rs:36:9
|
||||
--> $DIR/issue-38371.rs:34:9
|
||||
|
|
||||
LL | fn ugh(&[bar]: &u32) { //~ ERROR expected an array or slice
|
||||
| ^^^^^ pattern cannot match with input type `u32`
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(advanced_slice_patterns)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
struct Foo {
|
||||
|
|
|
@ -1,41 +1,41 @@
|
|||
error[E0004]: non-exhaustive patterns: `Foo { first: false, second: Some([_, _, _, _]) }` not covered
|
||||
--> $DIR/non-exhaustive-pattern-witness.rs:20:11
|
||||
--> $DIR/non-exhaustive-pattern-witness.rs:19:11
|
||||
|
|
||||
LL | match (Foo { first: true, second: None }) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `Foo { first: false, second: Some([_, _, _, _]) }` not covered
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `Red` not covered
|
||||
--> $DIR/non-exhaustive-pattern-witness.rs:36:11
|
||||
--> $DIR/non-exhaustive-pattern-witness.rs:35:11
|
||||
|
|
||||
LL | match Color::Red {
|
||||
| ^^^^^^^^^^ pattern `Red` not covered
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `East`, `South` and `West` not covered
|
||||
--> $DIR/non-exhaustive-pattern-witness.rs:48:11
|
||||
--> $DIR/non-exhaustive-pattern-witness.rs:47:11
|
||||
|
|
||||
LL | match Direction::North {
|
||||
| ^^^^^^^^^^^^^^^^ patterns `East`, `South` and `West` not covered
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `Second`, `Third`, `Fourth` and 8 more not covered
|
||||
--> $DIR/non-exhaustive-pattern-witness.rs:59:11
|
||||
--> $DIR/non-exhaustive-pattern-witness.rs:58:11
|
||||
|
|
||||
LL | match ExcessiveEnum::First {
|
||||
| ^^^^^^^^^^^^^^^^^^^^ patterns `Second`, `Third`, `Fourth` and 8 more not covered
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `CustomRGBA { a: true, .. }` not covered
|
||||
--> $DIR/non-exhaustive-pattern-witness.rs:67:11
|
||||
--> $DIR/non-exhaustive-pattern-witness.rs:66:11
|
||||
|
|
||||
LL | match Color::Red {
|
||||
| ^^^^^^^^^^ pattern `CustomRGBA { a: true, .. }` not covered
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `[Second(true), Second(false)]` not covered
|
||||
--> $DIR/non-exhaustive-pattern-witness.rs:83:11
|
||||
--> $DIR/non-exhaustive-pattern-witness.rs:82:11
|
||||
|
|
||||
LL | match *x {
|
||||
| ^^ pattern `[Second(true), Second(false)]` not covered
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `((), false)` not covered
|
||||
--> $DIR/non-exhaustive-pattern-witness.rs:96:11
|
||||
--> $DIR/non-exhaustive-pattern-witness.rs:95:11
|
||||
|
|
||||
LL | match ((), false) {
|
||||
| ^^^^^^^^^^^ pattern `((), false)` not covered
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
// NB: this test was introduced in #23121 and will have to change when default match binding modes
|
||||
// stabilizes.
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
fn slice_pat(x: &[u8]) {
|
||||
// OLD!
|
||||
match x {
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(match_default_bindings)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
pub fn main() {
|
||||
let sl: &[u8] = b"foo";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue