Split slice part of feature(half_open_range_patterns) to [...]_in_slices
This commit is contained in:
parent
a688a0305f
commit
c084c26397
12 changed files with 63 additions and 8 deletions
|
@ -461,7 +461,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||||
if let PatKind::Range(Some(_), None, Spanned { .. }) = inner_pat.kind {
|
if let PatKind::Range(Some(_), None, Spanned { .. }) = inner_pat.kind {
|
||||||
gate_feature_post!(
|
gate_feature_post!(
|
||||||
&self,
|
&self,
|
||||||
half_open_range_patterns,
|
half_open_range_patterns_in_slices,
|
||||||
pat.span,
|
pat.span,
|
||||||
"`X..` patterns in slices are experimental"
|
"`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!(generators, "yield syntax is experimental");
|
||||||
gate_all!(raw_ref_op, "raw address of 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!(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, "inline-const is experimental");
|
||||||
gate_all!(inline_const_pat, "inline-const in pattern position is experimental");
|
gate_all!(inline_const_pat, "inline-const in pattern position is experimental");
|
||||||
gate_all!(associated_const_equality, "associated const equality is incomplete");
|
gate_all!(associated_const_equality, "associated const equality is incomplete");
|
||||||
|
|
|
@ -414,6 +414,8 @@ declare_features! (
|
||||||
(incomplete, generic_const_exprs, "1.56.0", Some(76560), None),
|
(incomplete, generic_const_exprs, "1.56.0", Some(76560), None),
|
||||||
/// Allows using `..X`, `..=X`, `...X`, and `X..` as a pattern.
|
/// Allows using `..X`, `..=X`, `...X`, and `X..` as a pattern.
|
||||||
(active, half_open_range_patterns, "1.41.0", Some(67264), None),
|
(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.
|
/// Allows `if let` guard in match arms.
|
||||||
(active, if_let_guard, "1.47.0", Some(51114), None),
|
(active, if_let_guard, "1.47.0", Some(51114), None),
|
||||||
/// Allows using imported `main` function
|
/// Allows using imported `main` function
|
||||||
|
|
|
@ -785,6 +785,7 @@ symbols! {
|
||||||
globs,
|
globs,
|
||||||
gt,
|
gt,
|
||||||
half_open_range_patterns,
|
half_open_range_patterns,
|
||||||
|
half_open_range_patterns_in_slices,
|
||||||
hash,
|
hash,
|
||||||
hexagon_target_feature,
|
hexagon_target_feature,
|
||||||
hidden,
|
hidden,
|
||||||
|
|
|
@ -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; };
|
||||||
|
}
|
||||||
|
```
|
|
@ -1,7 +1,7 @@
|
||||||
// compile-flags: -Zunleash-the-miri-inside-of-you
|
// compile-flags: -Zunleash-the-miri-inside-of-you
|
||||||
// aux-build:static_cross_crate.rs
|
// aux-build:static_cross_crate.rs
|
||||||
// stderr-per-bitwidth
|
// 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;
|
extern crate static_cross_crate;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![feature(half_open_range_patterns)]
|
#![feature(half_open_range_patterns_in_slices)]
|
||||||
#![feature(exclusive_range_pattern)]
|
#![feature(exclusive_range_pattern)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![feature(half_open_range_patterns)]
|
#![feature(half_open_range_patterns_in_slices)]
|
||||||
#![feature(exclusive_range_pattern)]
|
#![feature(exclusive_range_pattern)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
|
@ -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`.
|
|
@ -1,4 +1,4 @@
|
||||||
#![feature(half_open_range_patterns)]
|
#![feature(half_open_range_patterns_in_slices)]
|
||||||
#![feature(exclusive_range_pattern)]
|
#![feature(exclusive_range_pattern)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -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
|
= 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
|
error[E0658]: exclusive range pattern syntax is experimental
|
||||||
--> $DIR/slice_pattern_syntax_problem1.rs:4:23
|
--> $DIR/slice_pattern_syntax_problem1.rs:4:23
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![feature(half_open_range_patterns)]
|
#![feature(half_open_range_patterns_in_slices)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match [1, 2] {
|
match [1, 2] {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue