-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reestablish feature gate for RangeFrom in slices
- Loading branch information
1 parent
45d9dd6
commit 43bad44
Showing
6 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem0.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#![feature(half_open_range_patterns)] | ||
#![feature(exclusive_range_pattern)] | ||
|
||
fn main() { | ||
let xs = [13, 1, 5, 2, 3, 1, 21, 8]; | ||
let [a, b, c, rest @ ..] = xs; | ||
// Consider the following example: | ||
assert!(a == 13 && b == 1 && c == 5 && rest.len() == 5); | ||
|
||
// What if we wanted to pull this apart without individually binding a, b, and c? | ||
let [first_three @ ..3, rest @ 2..] = xs; | ||
//~^ pattern requires 2 elements but array has 8 | ||
// This is somewhat unintuitive and makes slice patterns exceedingly verbose. | ||
// We want to stabilize half-open RangeFrom (`X..`) patterns | ||
// but without banning us from using them for a more efficient slice pattern syntax. | ||
} |
9 changes: 9 additions & 0 deletions
9
src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem0.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error[E0527]: pattern requires 2 elements but array has 8 | ||
--> $DIR/slice_pattern_syntax_problem0.rs:11:9 | ||
| | ||
LL | let [first_three @ ..3, rest @ 2..] = xs; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 8 elements | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0527`. |
9 changes: 9 additions & 0 deletions
9
src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem1.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Instead of allowing the previous case, maintain the feature gate for slice patterns for now. | ||
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 | ||
//~| half-open range patterns are unstable | ||
//~| exclusive range pattern syntax is experimental | ||
//~| exclusive range pattern syntax is experimental | ||
} |
39 changes: 39 additions & 0 deletions
39
src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem1.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
error[E0658]: half-open range patterns are unstable | ||
--> $DIR/slice_pattern_syntax_problem1.rs:4:23 | ||
| | ||
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 | ||
|
||
error[E0658]: `X..` patterns in slices are experimental | ||
--> $DIR/slice_pattern_syntax_problem1.rs:4: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)]` to the crate attributes to enable | ||
|
||
error[E0658]: exclusive range pattern syntax is experimental | ||
--> $DIR/slice_pattern_syntax_problem1.rs:4:23 | ||
| | ||
LL | let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs; | ||
| ^^^ | ||
| | ||
= note: see issue #37854 <https://github.com/rust-lang/rust/issues/37854> for more information | ||
= help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable | ||
|
||
error[E0658]: exclusive range pattern syntax is experimental | ||
--> $DIR/slice_pattern_syntax_problem1.rs:4:32 | ||
| | ||
LL | let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs; | ||
| ^^^^ | ||
| | ||
= note: see issue #37854 <https://github.com/rust-lang/rust/issues/37854> for more information | ||
= help: add `#![feature(exclusive_range_pattern)]` to the crate attributes to enable | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
10 changes: 10 additions & 0 deletions
10
src/test/ui/half-open-range-patterns/slice_pattern_syntax_problem2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// run-pass | ||
|
||
fn main() { | ||
let xs = [13, 1, 5, 2, 3, 1, 21, 8]; | ||
if let [3..=14, ..] = xs { | ||
/* this variant must pass for now, unfortunately. | ||
* This test is included here to help inform a future plan for these. | ||
*/ | ||
}; | ||
} |