Skip to content

Commit b991723

Browse files
committed
Auto merge of rust-lang#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 rust-lang#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](rust-lang#32202) and @mikhail-m1 who [fixed one remaining class of codegen issues](rust-lang#47926). Reference PR rust-lang/reference#259 cc rust-lang#23121 fixes rust-lang#48836
2 parents 6bfa7d0 + 7c90189 commit b991723

File tree

75 files changed

+124
-226
lines changed

Some content is hidden

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

75 files changed

+124
-226
lines changed

src/doc/unstable-book/src/language-features/advanced-slice-patterns.md

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/doc/unstable-book/src/language-features/slice-patterns.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,29 @@ The tracking issue for this feature is: [#23121]
44

55
[#23121]: https://github.com/rust-lang/rust/issues/23121
66

7-
See also
8-
[`advanced_slice_patterns`](language-features/advanced-slice-patterns.html).
9-
107
------------------------
118

12-
13-
If you want to match against a slice or array, you can use `&` with the
14-
`slice_patterns` feature:
9+
The `slice_patterns` feature gate lets you use `..` to indicate any number of
10+
elements inside a pattern matching a slice. This wildcard can only be used once
11+
for a given array. If there's an pattern before the `..`, the subslice will be
12+
matched against that pattern. For example:
1513

1614
```rust
1715
#![feature(slice_patterns)]
1816

17+
fn is_symmetric(list: &[u32]) -> bool {
18+
match list {
19+
&[] | &[_] => true,
20+
&[x, ref inside.., y] if x == y => is_symmetric(inside),
21+
&[..] => false,
22+
}
23+
}
24+
1925
fn main() {
20-
let v = vec!["match_this", "1"];
26+
let sym = &[0, 1, 4, 2, 4, 1, 0];
27+
assert!(is_symmetric(sym));
2128

22-
match &v[..] {
23-
&["match_this", second] => println!("The second element is {}", second),
24-
_ => {},
25-
}
29+
let not_sym = &[0, 1, 7, 2, 4, 1, 0];
30+
assert!(!is_symmetric(not_sym));
2631
}
2732
```
28-

src/liballoc/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
#![feature(ptr_internals)]
112112
#![feature(rustc_attrs)]
113113
#![feature(slice_get_slice)]
114-
#![feature(slice_patterns)]
115114
#![feature(slice_rsplit)]
116115
#![feature(specialization)]
117116
#![feature(staged_api)]

src/libcore/benches/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#![deny(warnings)]
1212

1313
#![feature(flt2dec)]
14-
#![feature(slice_patterns)]
1514
#![feature(test)]
1615

1716
extern crate core;

src/libcore/tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#![feature(raw)]
3838
#![feature(refcell_replace_swap)]
3939
#![feature(slice_patterns)]
40+
#![feature(slice_rotate)]
4041
#![feature(sort_internals)]
4142
#![feature(specialization)]
4243
#![feature(step_trait)]

src/librustc/benches/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#![deny(warnings)]
1212

13-
#![feature(slice_patterns)]
1413
#![feature(test)]
1514

1615
extern crate test;

src/librustc_apfloat/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#![forbid(unsafe_code)]
4848

4949
#![feature(i128_type)]
50-
#![feature(slice_patterns)]
50+
#![cfg_attr(stage0, feature(slice_patterns))]
5151
#![feature(try_from)]
5252

5353
// See librustc_cratesio_shim/Cargo.toml for a comment explaining this.

src/librustc_const_eval/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#![deny(warnings)]
2121

2222
#![feature(rustc_diagnostic_macros)]
23-
#![feature(slice_patterns)]
2423
#![feature(box_patterns)]
2524
#![feature(box_syntax)]
2625
#![feature(macro_lifetime_matcher)]

src/librustc_lint/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#![feature(macro_vis_matcher)]
3232
#![feature(quote)]
3333
#![feature(rustc_diagnostic_macros)]
34-
#![feature(slice_patterns)]
3534
#![cfg_attr(stage0, feature(never_type))]
3635

3736
#[macro_use]

src/librustc_trans/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#![feature(libc)]
3131
#![feature(quote)]
3232
#![feature(rustc_diagnostic_macros)]
33-
#![feature(slice_patterns)]
33+
#![cfg_attr(stage0, feature(slice_patterns))]
3434
#![feature(conservative_impl_trait)]
3535
#![feature(optin_builtin_traits)]
3636
#![feature(inclusive_range_fields)]

0 commit comments

Comments
 (0)