Skip to content

Commit

Permalink
Stabilize exclusive_range
Browse files Browse the repository at this point in the history
  • Loading branch information
RossSmyth committed Apr 28, 2024
1 parent aed2187 commit 828dd00
Show file tree
Hide file tree
Showing 74 changed files with 300 additions and 619 deletions.
15 changes: 1 addition & 14 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_ast as ast;
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
use rustc_ast::{attr, AssocConstraint, AssocConstraintKind, NodeId};
use rustc_ast::{token, PatKind, RangeEnd};
use rustc_ast::{token, PatKind};
use rustc_feature::{AttributeGate, BuiltinAttribute, Features, GateIssue, BUILTIN_ATTRIBUTE_MAP};
use rustc_session::parse::{feature_err, feature_err_issue, feature_warn};
use rustc_session::Session;
Expand Down Expand Up @@ -418,15 +418,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
PatKind::Box(..) => {
gate!(&self, box_patterns, pattern.span, "box pattern syntax is experimental");
}
PatKind::Range(_, Some(_), Spanned { node: RangeEnd::Excluded, .. }) => {
gate!(
&self,
exclusive_range_pattern,
pattern.span,
"exclusive range pattern syntax is experimental",
"use an inclusive range pattern, like N..=M"
);
}
_ => {}
}
visit::walk_pat(self, pattern)
Expand Down Expand Up @@ -619,10 +610,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
// be too.
gate_all_legacy_dont_use!(return_type_notation, "return type notation is experimental");
gate_all_legacy_dont_use!(decl_macro, "`macro` is experimental");
gate_all_legacy_dont_use!(
exclusive_range_pattern,
"exclusive range pattern syntax is experimental"
);
gate_all_legacy_dont_use!(try_blocks, "`try` blocks are unstable");
gate_all_legacy_dont_use!(auto_traits, "`auto` traits are unstable");

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_error_codes/src/error_codes/E0579.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ A lower range wasn't less than the upper range.
Erroneous code example:

```compile_fail,E0579
#![feature(exclusive_range_pattern)]
fn main() {
match 5u32 {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ declare_features! (
(accepted, drop_types_in_const, "1.22.0", Some(33156)),
/// Allows using `dyn Trait` as a syntax for trait objects.
(accepted, dyn_trait, "1.27.0", Some(44662)),
/// Allows `X..Y` patterns.
(accepted, exclusive_range_pattern, "CURRENT_RUSTC_VERSION", Some(37854)),
/// Allows integer match exhaustiveness checking (RFC 2591).
(accepted, exhaustive_integer_patterns, "1.33.0", Some(50907)),
/// Allows explicit generic arguments specification with `impl Trait` present.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,6 @@ declare_features! (
(incomplete, dyn_star, "1.65.0", Some(102425)),
/// Uses generic effect parameters for ~const bounds
(unstable, effects, "1.72.0", Some(102090)),
/// Allows `X..Y` patterns.
(unstable, exclusive_range_pattern, "1.11.0", Some(37854)),
/// Allows exhaustive pattern matching on types that contain uninhabited types.
(unstable, exhaustive_patterns, "1.13.0", Some(51085)),
/// Allows explicit tail calls via `become` expression.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,6 @@ declare_lint! {
/// ### Example
///
/// ```rust
/// # #![feature(exclusive_range_pattern)]
/// let x = 123u32;
/// match x {
/// 0..100 => { println!("small"); }
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_pattern_analysis/src/usefulness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
//! This is enough to compute usefulness: a pattern in a `match` expression is redundant iff it is
//! not useful w.r.t. the patterns above it:
//! ```compile_fail,E0004
//! # #![feature(exclusive_range_pattern)]
//! # fn foo() {
//! match Some(0u32) {
//! Some(0..100) => {},
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
// Language features:
// tidy-alphabetical-start
#![cfg_attr(bootstrap, feature(associated_type_bounds))]
#![cfg_attr(bootstrap, feature(exclusive_range_pattern))]
#![cfg_attr(bootstrap, feature(inline_const))]
#![cfg_attr(not(bootstrap), rustc_preserve_ub_checks)]
#![cfg_attr(not(test), feature(coroutine_trait))]
Expand All @@ -183,7 +184,6 @@
#![feature(const_try)]
#![feature(decl_macro)]
#![feature(dropck_eyepatch)]
#![feature(exclusive_range_pattern)]
#![feature(fundamental)]
#![feature(hashmap_internals)]
#![feature(lang_items)]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# `half_open_range_patterns_in_slices`

The tracking issue for this feature is: [#67264]
It is part of the `exclusive_range_pattern` feature,
It is a future part of the `exclusive_range_pattern` feature,
tracked at [#37854].

[#67264]: https://github.com/rust-lang/rust/issues/67264
Expand All @@ -12,7 +12,6 @@ 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];
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/building/match/sort_candidates.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Check specific cases of sorting candidates in match lowering.
#![feature(exclusive_range_pattern)]

// EMIT_MIR sort_candidates.constant_eq.SimplifyCfg-initial.after.mir
fn constant_eq(s: &str, b: bool) -> u32 {
Expand Down
1 change: 0 additions & 1 deletion tests/ui/binding/match-range.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ run-pass
#![feature(exclusive_range_pattern)]

pub fn main() {
match 5_usize {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//@ aux-build:static_cross_crate.rs
//@ normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
//@ normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"
#![feature(exclusive_range_pattern, half_open_range_patterns_in_slices)]
#![feature(half_open_range_patterns_in_slices)]
#![allow(static_mut_refs)]

extern crate static_cross_crate;
Expand Down

This file was deleted.

14 changes: 0 additions & 14 deletions tests/ui/feature-gates/feature-gate-exclusive-range-pattern.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(half_open_range_patterns_in_slices)]
#![feature(exclusive_range_pattern)]

fn main() {
match [5..4, 99..105, 43..44] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/exclusive_range_pattern_syntax_collision.rs:6:13
--> $DIR/exclusive_range_pattern_syntax_collision.rs:5:13
|
LL | match [5..4, 99..105, 43..44] {
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(half_open_range_patterns_in_slices)]
#![feature(exclusive_range_pattern)]

fn main() {
match [5..4, 99..105, 43..44] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0527]: pattern requires 2 elements but array has 3
--> $DIR/exclusive_range_pattern_syntax_collision2.rs:6:9
--> $DIR/exclusive_range_pattern_syntax_collision2.rs:5:9
|
LL | [_, 99..] => {},
| ^^^^^^^^^ expected 3 elements

error[E0308]: mismatched types
--> $DIR/exclusive_range_pattern_syntax_collision2.rs:6:13
--> $DIR/exclusive_range_pattern_syntax_collision2.rs:5:13
|
LL | match [5..4, 99..105, 43..44] {
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(exclusive_range_pattern)]

fn main() {
match [5..4, 99..105, 43..44] {
[..9, 99..100, _] => {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:12
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:3:12
|
LL | match [5..4, 99..105, 43..44] {
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
Expand All @@ -10,7 +10,7 @@ LL | [..9, 99..100, _] => {},
found type `{integer}`

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

error[E0308]: mismatched types
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:19
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:3:19
|
LL | match [5..4, 99..105, 43..44] {
| ----------------------- this expression has type `[std::ops::Range<{integer}>; 3]`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: `X..` patterns in slices are experimental
--> $DIR/feature-gate-half-open-range-patterns-in-slices.rs:5:10
--> $DIR/feature-gate-half-open-range-patterns-in-slices.rs:3:10
|
LL | let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs;
| ^^^^^^^
Expand All @@ -9,7 +9,7 @@ LL | let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs;
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0005]: refutable pattern in local binding
--> $DIR/feature-gate-half-open-range-patterns-in-slices.rs:5:9
--> $DIR/feature-gate-half-open-range-patterns-in-slices.rs:3:9
|
LL | let [a @ 3.., b @ ..3, c @ 4..6, ..] = xs;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pattern `[i32::MIN..=2_i32, ..]` not covered
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(exclusive_range_pattern)]

fn main() {
let "a".. = "a"; //~ ERROR only `char` and numeric types are allowed in range patterns
let .."a" = "a"; //~ ERROR only `char` and numeric types are allowed in range patterns
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error[E0029]: only `char` and numeric types are allowed in range patterns
--> $DIR/half-open-range-pats-bad-types.rs:4:9
--> $DIR/half-open-range-pats-bad-types.rs:2:9
|
LL | let "a".. = "a";
| ^^^ this is of type `&'static str` but it should be `char` or numeric

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

error[E0029]: only `char` and numeric types are allowed in range patterns
--> $DIR/half-open-range-pats-bad-types.rs:6:12
--> $DIR/half-open-range-pats-bad-types.rs:4:12
|
LL | let ..="a" = "a";
| ^^^ this is of type `&'static str` but it should be `char` or numeric
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Test various non-exhaustive matches for `X..`, `..=X` and `..X` ranges.

#![feature(exclusive_range_pattern)]
#![allow(non_contiguous_range_endpoints)]

fn main() {}
Expand Down
Loading

0 comments on commit 828dd00

Please sign in to comment.