Skip to content

Commit 25f1916

Browse files
authored
Rollup merge of rust-lang#102275 - Urgau:stabilize-half_open_range_patterns, r=cjgillot
Stabilize `half_open_range_patterns` This PR stabilize `feature(half_open_range_patterns)`: ``` Allows using `..=X` as a pattern. ``` And adds a new `feature(half_open_range_patterns_in_slices)` for the slice part, rust-lang#102275 (comment). The FCP was completed in rust-lang#67264.
2 parents 1a7c203 + 5ae7363 commit 25f1916

File tree

54 files changed

+321
-406
lines changed

Some content is hidden

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

54 files changed

+321
-406
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
461461
if let PatKind::Range(Some(_), None, Spanned { .. }) = inner_pat.kind {
462462
gate_feature_post!(
463463
&self,
464-
half_open_range_patterns,
464+
half_open_range_patterns_in_slices,
465465
pat.span,
466466
"`X..` patterns in slices are experimental"
467467
);
@@ -589,7 +589,10 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
589589
gate_all!(generators, "yield syntax is experimental");
590590
gate_all!(raw_ref_op, "raw address of syntax is experimental");
591591
gate_all!(const_trait_impl, "const trait impls are experimental");
592-
gate_all!(half_open_range_patterns, "half-open range patterns are unstable");
592+
gate_all!(
593+
half_open_range_patterns_in_slices,
594+
"half-open range patterns in slices are unstable"
595+
);
593596
gate_all!(inline_const, "inline-const is experimental");
594597
gate_all!(inline_const_pat, "inline-const in pattern position is experimental");
595598
gate_all!(associated_const_equality, "associated const equality is incomplete");

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ declare_features! (
169169
(accepted, global_allocator, "1.28.0", Some(27389), None),
170170
// FIXME: explain `globs`.
171171
(accepted, globs, "1.0.0", None, None),
172+
/// Allows using `..=X` as a pattern.
173+
(accepted, half_open_range_patterns, "CURRENT_RUSTC_VERSION", Some(67264), None),
172174
/// Allows using the `u128` and `i128` types.
173175
(accepted, i128_type, "1.26.0", Some(35118), None),
174176
/// Allows the use of `if let` expressions.

compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ declare_features! (
414414
(incomplete, generic_const_exprs, "1.56.0", Some(76560), None),
415415
/// Allows using `..X`, `..=X`, `...X`, and `X..` as a pattern.
416416
(active, half_open_range_patterns, "1.41.0", Some(67264), None),
417+
/// Allows using `..=X` as a patterns in slices.
418+
(active, half_open_range_patterns_in_slices, "CURRENT_RUSTC_VERSION", Some(67264), None),
417419
/// Allows `if let` guard in match arms.
418420
(active, if_let_guard, "1.47.0", Some(51114), None),
419421
/// Allows using imported `main` function

compiler/rustc_middle/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#![feature(type_alias_impl_trait)]
4545
#![feature(associated_type_bounds)]
4646
#![feature(rustc_attrs)]
47-
#![feature(half_open_range_patterns)]
47+
#![cfg_attr(bootstrap, feature(half_open_range_patterns))]
4848
#![feature(control_flow_enum)]
4949
#![feature(associated_type_defaults)]
5050
#![feature(trusted_step)]

compiler/rustc_parse/src/parser/pat.rs

-1
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,6 @@ impl<'a> Parser<'a> {
777777
/// expression syntax `...expr` for splatting in expressions.
778778
fn parse_pat_range_to(&mut self, mut re: Spanned<RangeEnd>) -> PResult<'a, PatKind> {
779779
let end = self.parse_pat_range_end()?;
780-
self.sess.gated_spans.gate(sym::half_open_range_patterns, re.span.to(self.prev_token.span));
781780
if let RangeEnd::Included(ref mut syn @ RangeSyntax::DotDotDot) = &mut re.node {
782781
*syn = RangeSyntax::DotDotEq;
783782
self.struct_span_err(re.span, "range-to patterns with `...` are not allowed")

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ symbols! {
785785
globs,
786786
gt,
787787
half_open_range_patterns,
788+
half_open_range_patterns_in_slices,
788789
hash,
789790
hexagon_target_feature,
790791
hidden,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# `half_open_range_patterns_in_slices`
2+
3+
The tracking issue for this feature is: [#67264]
4+
It is part of the `exclusive_range_pattern` feature,
5+
tracked at [#37854].
6+
7+
[#67264]: https://github.com/rust-lang/rust/issues/67264
8+
[#37854]: https://github.com/rust-lang/rust/issues/37854
9+
-----
10+
11+
This feature allow using top-level half-open range patterns in slices.
12+
13+
```rust
14+
#![feature(half_open_range_patterns_in_slices)]
15+
#![feature(exclusive_range_pattern)]
16+
17+
fn main() {
18+
let xs = [13, 1, 5, 2, 3, 1, 21, 8];
19+
let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs else { return; };
20+
}
21+
```
22+
23+
Note that this feature is not required if the patterns are wrapped between parenthesis.
24+
25+
```rust
26+
fn main() {
27+
let xs = [13, 1];
28+
let [(a @ 3..), c] = xs else { return; };
29+
}
30+
```

src/doc/unstable-book/src/language-features/half-open-range-patterns.md

-27
This file was deleted.

src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// compile-flags: -Zunleash-the-miri-inside-of-you
22
// aux-build:static_cross_crate.rs
33
// stderr-per-bitwidth
4-
#![feature(exclusive_range_pattern, half_open_range_patterns)]
4+
#![feature(exclusive_range_pattern, half_open_range_patterns_in_slices)]
55

66
extern crate static_cross_crate;
77

src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(half_open_range_patterns)]
1+
#![feature(half_open_range_patterns_in_slices)]
22
#![feature(exclusive_range_pattern)]
33

44
fn main() {

src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(half_open_range_patterns)]
1+
#![feature(half_open_range_patterns_in_slices)]
22
#![feature(exclusive_range_pattern)]
33

44
fn main() {

src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(half_open_range_patterns)]
21
#![feature(exclusive_range_pattern)]
32

43
fn main() {

src/test/ui/half-open-range-patterns/exclusive_range_pattern_syntax_collision3.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:12
2+
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:12
33
|
44
LL | match [5..4, 99..105, 43..44] {
55
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
@@ -10,7 +10,7 @@ LL | [..9, 99..100, _] => {},
1010
found type `{integer}`
1111

1212
error[E0308]: mismatched types
13-
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:15
13+
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:15
1414
|
1515
LL | match [5..4, 99..105, 43..44] {
1616
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
@@ -23,7 +23,7 @@ LL | [..9, 99..100, _] => {},
2323
found type `{integer}`
2424

2525
error[E0308]: mismatched types
26-
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:19
26+
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:19
2727
|
2828
LL | match [5..4, 99..105, 43..44] {
2929
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(exclusive_range_pattern)]
2+
3+
fn main() {
4+
let xs = [13, 1, 5, 2, 3, 1, 21, 8];
5+
let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs;
6+
//~^ `X..` patterns in slices are experimental
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: `X..` patterns in slices are experimental
2+
--> $DIR/feature-gate-half-open-range-patterns-in-slices.rs:5:10
3+
|
4+
LL | let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs;
5+
| ^^^^^^^
6+
|
7+
= note: see issue #67264 <https://github.com/rust-lang/rust/issues/67264> for more information
8+
= help: add `#![feature(half_open_range_patterns_in_slices)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns.rs

-18
This file was deleted.

src/test/ui/half-open-range-patterns/feature-gate-half-open-range-patterns.stderr

-53
This file was deleted.

src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(half_open_range_patterns)]
21
#![feature(exclusive_range_pattern)]
32

43
fn main() {

src/test/ui/half-open-range-patterns/half-open-range-pats-bad-types.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error[E0029]: only `char` and numeric types are allowed in range patterns
2-
--> $DIR/half-open-range-pats-bad-types.rs:5:9
2+
--> $DIR/half-open-range-pats-bad-types.rs:4:9
33
|
44
LL | let "a".. = "a";
55
| ^^^ this is of type `&'static str` but it should be `char` or numeric
66

77
error[E0029]: only `char` and numeric types are allowed in range patterns
8-
--> $DIR/half-open-range-pats-bad-types.rs:6:11
8+
--> $DIR/half-open-range-pats-bad-types.rs:5:11
99
|
1010
LL | let .."a" = "a";
1111
| ^^^ this is of type `&'static str` but it should be `char` or numeric
1212

1313
error[E0029]: only `char` and numeric types are allowed in range patterns
14-
--> $DIR/half-open-range-pats-bad-types.rs:7:12
14+
--> $DIR/half-open-range-pats-bad-types.rs:6:12
1515
|
1616
LL | let ..="a" = "a";
1717
| ^^^ this is of type `&'static str` but it should be `char` or numeric

src/test/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Test various non-exhaustive matches for `X..`, `..=X` and `..X` ranges.
22

3-
#![feature(half_open_range_patterns)]
43
#![feature(exclusive_range_pattern)]
54
#![allow(illegal_floating_point_literal_pattern)]
65

0 commit comments

Comments
 (0)