Split slice part of feature(half_open_range_patterns) to [...]_in_slices

This commit is contained in:
Urgau 2022-10-05 23:18:22 +02:00
parent a688a0305f
commit c084c26397
12 changed files with 63 additions and 8 deletions

View file

@ -461,7 +461,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
if let PatKind::Range(Some(_), None, Spanned { .. }) = inner_pat.kind {
gate_feature_post!(
&self,
half_open_range_patterns,
half_open_range_patterns_in_slices,
pat.span,
"`X..` patterns in slices are experimental"
);
@ -589,7 +589,10 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
gate_all!(generators, "yield syntax is experimental");
gate_all!(raw_ref_op, "raw address of syntax is experimental");
gate_all!(const_trait_impl, "const trait impls are experimental");
gate_all!(half_open_range_patterns, "half-open range patterns are unstable");
gate_all!(
half_open_range_patterns_in_slices,
"half-open range patterns in slices are unstable"
);
gate_all!(inline_const, "inline-const is experimental");
gate_all!(inline_const_pat, "inline-const in pattern position is experimental");
gate_all!(associated_const_equality, "associated const equality is incomplete");

View file

@ -414,6 +414,8 @@ declare_features! (
(incomplete, generic_const_exprs, "1.56.0", Some(76560), None),
/// Allows using `..X`, `..=X`, `...X`, and `X..` as a pattern.
(active, half_open_range_patterns, "1.41.0", Some(67264), None),
/// Allows using `..=X` as a patterns in slices.
(active, half_open_range_patterns_in_slices, "CURRENT_RUSTC_VERSION", Some(67264), None),
/// Allows `if let` guard in match arms.
(active, if_let_guard, "1.47.0", Some(51114), None),
/// Allows using imported `main` function

View file

@ -785,6 +785,7 @@ symbols! {
globs,
gt,
half_open_range_patterns,
half_open_range_patterns_in_slices,
hash,
hexagon_target_feature,
hidden,

View file

@ -0,0 +1,30 @@
# `half_open_range_patterns_in_slices`
The tracking issue for this feature is: [#67264]
It is part of the `exclusive_range_pattern` feature,
tracked at [#37854].
[#67264]: https://github.com/rust-lang/rust/issues/67264
[#37854]: https://github.com/rust-lang/rust/issues/37854
-----
This feature allow using top-level half-open range patterns in slices.
```rust
#![feature(half_open_range_patterns_in_slices)]
#![feature(exclusive_range_pattern)]
fn main() {
let xs = [13, 1, 5, 2, 3, 1, 21, 8];
let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs else { return; };
}
```
Note that this feature is not required if the patterns are wrapped between parenthesis.
```rust
fn main() {
let xs = [13, 1];
let [(a @ 3..), c] = xs else { return; };
}
```

View file

@ -1,7 +1,7 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
// aux-build:static_cross_crate.rs
// stderr-per-bitwidth
#![feature(exclusive_range_pattern, half_open_range_patterns)]
#![feature(exclusive_range_pattern, half_open_range_patterns_in_slices)]
extern crate static_cross_crate;

View file

@ -1,4 +1,4 @@
#![feature(half_open_range_patterns)]
#![feature(half_open_range_patterns_in_slices)]
#![feature(exclusive_range_pattern)]
fn main() {

View file

@ -1,4 +1,4 @@
#![feature(half_open_range_patterns)]
#![feature(half_open_range_patterns_in_slices)]
#![feature(exclusive_range_pattern)]
fn main() {

View file

@ -0,0 +1,7 @@
#![feature(exclusive_range_pattern)]
fn main() {
let xs = [13, 1, 5, 2, 3, 1, 21, 8];
let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs;
//~^ `X..` patterns in slices are experimental
}

View file

@ -0,0 +1,12 @@
error[E0658]: `X..` patterns in slices are experimental
--> $DIR/feature-gate-half-open-range-patterns-in-slices.rs:5:10
|
LL | let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs;
| ^^^^^^^
|
= note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information
= help: add `#![feature(half_open_range_patterns_in_slices)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View file

@ -1,4 +1,4 @@
#![feature(half_open_range_patterns)]
#![feature(half_open_range_patterns_in_slices)]
#![feature(exclusive_range_pattern)]
fn main() {

View file

@ -14,7 +14,7 @@ LL | let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs;
| ^^^^^^^
|
= note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information
= help: add `#![feature(half_open_range_patterns)]` to the crate attributes to enable
= help: add `#![feature(half_open_range_patterns_in_slices)]` to the crate attributes to enable
error[E0658]: exclusive range pattern syntax is experimental
--> $DIR/slice_pattern_syntax_problem1.rs:4:23

View file

@ -1,4 +1,4 @@
#![feature(half_open_range_patterns)]
#![feature(half_open_range_patterns_in_slices)]
fn main() {
match [1, 2] {