Stabilize inclusive_range_syntax
language feature.
Stabilize the syntax `a..=b` and `..=b`.
This commit is contained in:
parent
b5913f2e76
commit
92d1f8d8e4
19 changed files with 19 additions and 138 deletions
|
@ -1,20 +0,0 @@
|
|||
# `inclusive_range_syntax`
|
||||
|
||||
The tracking issue for this feature is: [#28237]
|
||||
|
||||
[#28237]: https://github.com/rust-lang/rust/issues/28237
|
||||
|
||||
------------------------
|
||||
|
||||
To get a range that goes from 0 to 10 and includes the value 10, you
|
||||
can write `0..=10`:
|
||||
|
||||
```rust
|
||||
#![feature(inclusive_range_syntax)]
|
||||
|
||||
fn main() {
|
||||
for i in 0..=10 {
|
||||
println!("{}", i);
|
||||
}
|
||||
}
|
||||
```
|
|
@ -14,7 +14,7 @@
|
|||
#![feature(alloc_system)]
|
||||
#![feature(attr_literals)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(inclusive_range_syntax)]
|
||||
#![cfg_attr(stage0, feature(inclusive_range_syntax))]
|
||||
#![feature(collection_placement)]
|
||||
#![feature(const_fn)]
|
||||
#![feature(drain_filter)]
|
||||
|
|
|
@ -79,7 +79,7 @@
|
|||
#![feature(fn_must_use)]
|
||||
#![feature(fundamental)]
|
||||
#![feature(i128_type)]
|
||||
#![feature(inclusive_range_syntax)]
|
||||
#![cfg_attr(stage0, feature(inclusive_range_syntax))]
|
||||
#![feature(intrinsics)]
|
||||
#![feature(iterator_flatten)]
|
||||
#![feature(iterator_repeat_with)]
|
||||
|
|
|
@ -128,7 +128,7 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
|
|||
/// The range is empty if either side is incomparable:
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(range_is_empty,inclusive_range_syntax)]
|
||||
/// #![feature(range_is_empty)]
|
||||
///
|
||||
/// use std::f32::NAN;
|
||||
/// assert!(!(3.0..5.0).is_empty());
|
||||
|
@ -283,8 +283,6 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(inclusive_range_syntax)]
|
||||
///
|
||||
/// assert_eq!((3..=5), std::ops::RangeInclusive { start: 3, end: 5 });
|
||||
/// assert_eq!(3 + 4 + 5, (3..=5).sum());
|
||||
///
|
||||
|
@ -316,7 +314,7 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(range_contains,inclusive_range_syntax)]
|
||||
/// #![feature(range_contains)]
|
||||
///
|
||||
/// assert!(!(3..=5).contains(2));
|
||||
/// assert!( (3..=5).contains(3));
|
||||
|
@ -337,7 +335,7 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(range_is_empty,inclusive_range_syntax)]
|
||||
/// #![feature(range_is_empty)]
|
||||
///
|
||||
/// assert!(!(3..=5).is_empty());
|
||||
/// assert!(!(3..=3).is_empty());
|
||||
|
@ -347,7 +345,7 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
|
|||
/// The range is empty if either side is incomparable:
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(range_is_empty,inclusive_range_syntax)]
|
||||
/// #![feature(range_is_empty)]
|
||||
///
|
||||
/// use std::f32::NAN;
|
||||
/// assert!(!(3.0..=5.0).is_empty());
|
||||
|
@ -358,7 +356,7 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
|
|||
/// This method returns `true` after iteration has finished:
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(range_is_empty,inclusive_range_syntax)]
|
||||
/// #![feature(range_is_empty)]
|
||||
///
|
||||
/// let mut r = 3..=5;
|
||||
/// for _ in r.by_ref() {}
|
||||
|
@ -381,7 +379,6 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
|
|||
/// The `..=end` syntax is a `RangeToInclusive`:
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(inclusive_range_syntax)]
|
||||
/// assert_eq!((..=5), std::ops::RangeToInclusive{ end: 5 });
|
||||
/// ```
|
||||
///
|
||||
|
@ -389,8 +386,6 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
|
|||
/// `for` loop directly. This won't compile:
|
||||
///
|
||||
/// ```compile_fail,E0277
|
||||
/// #![feature(inclusive_range_syntax)]
|
||||
///
|
||||
/// // error[E0277]: the trait bound `std::ops::RangeToInclusive<{integer}>:
|
||||
/// // std::iter::Iterator` is not satisfied
|
||||
/// for i in ..=5 {
|
||||
|
@ -402,8 +397,6 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
|
|||
/// array elements up to and including the index indicated by `end`.
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(inclusive_range_syntax)]
|
||||
///
|
||||
/// let arr = [0, 1, 2, 3];
|
||||
/// assert_eq!(arr[ ..=2], [0,1,2 ]); // RangeToInclusive
|
||||
/// assert_eq!(arr[1..=2], [ 1,2 ]);
|
||||
|
@ -434,7 +427,7 @@ impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(range_contains,inclusive_range_syntax)]
|
||||
/// #![feature(range_contains)]
|
||||
///
|
||||
/// assert!( (..=5).contains(-1_000_000_000));
|
||||
/// assert!( (..=5).contains(5));
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#![feature(fmt_internals)]
|
||||
#![feature(iterator_step_by)]
|
||||
#![feature(i128_type)]
|
||||
#![feature(inclusive_range_syntax)]
|
||||
#![cfg_attr(stage0, feature(inclusive_range_syntax))]
|
||||
#![feature(iterator_try_fold)]
|
||||
#![feature(iterator_flatten)]
|
||||
#![feature(conservative_impl_trait)]
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
#![feature(fs_read_write)]
|
||||
#![feature(i128)]
|
||||
#![feature(i128_type)]
|
||||
#![feature(inclusive_range_syntax)]
|
||||
#![cfg_attr(stage0, feature(inclusive_range_syntax))]
|
||||
#![cfg_attr(windows, feature(libc))]
|
||||
#![feature(match_default_bindings)]
|
||||
#![feature(macro_lifetime_matcher)]
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#![feature(conservative_impl_trait)]
|
||||
#![feature(fs_read_write)]
|
||||
#![feature(i128_type)]
|
||||
#![feature(inclusive_range_syntax)]
|
||||
#![cfg_attr(stage0, feature(inclusive_range_syntax))]
|
||||
#![feature(specialization)]
|
||||
|
||||
extern crate graphviz;
|
||||
|
|
|
@ -28,7 +28,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
|
|||
#![feature(dyn_trait)]
|
||||
#![feature(fs_read_write)]
|
||||
#![feature(i128_type)]
|
||||
#![feature(inclusive_range_syntax)]
|
||||
#![cfg_attr(stage0, feature(inclusive_range_syntax))]
|
||||
#![feature(macro_vis_matcher)]
|
||||
#![feature(match_default_bindings)]
|
||||
#![feature(exhaustive_patterns)]
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#![allow(unused_attributes)]
|
||||
#![feature(i128_type)]
|
||||
#![feature(i128)]
|
||||
#![feature(inclusive_range_syntax)]
|
||||
#![cfg_attr(stage0, feature(inclusive_range_syntax))]
|
||||
#![feature(libc)]
|
||||
#![feature(quote)]
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
|
|
|
@ -218,8 +218,6 @@ An inclusive range was used with no end.
|
|||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0586
|
||||
#![feature(inclusive_range_syntax)]
|
||||
|
||||
fn main() {
|
||||
let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
|
||||
let x = &tmp[1..=]; // error: inclusive range was used with no end
|
||||
|
@ -239,8 +237,6 @@ fn main() {
|
|||
Or put an end to your inclusive range:
|
||||
|
||||
```
|
||||
#![feature(inclusive_range_syntax)]
|
||||
|
||||
fn main() {
|
||||
let tmp = vec![0, 1, 2, 3, 4, 4, 3, 3, 2, 1];
|
||||
let x = &tmp[1..=3]; // ok!
|
||||
|
|
|
@ -268,9 +268,6 @@ declare_features! (
|
|||
// rustc internal
|
||||
(active, abi_vectorcall, "1.7.0", None, None),
|
||||
|
||||
// a..=b and ..=b
|
||||
(active, inclusive_range_syntax, "1.7.0", Some(28237), None),
|
||||
|
||||
// X..Y patterns
|
||||
(active, exclusive_range_pattern, "1.11.0", Some(37854), None),
|
||||
|
||||
|
@ -554,6 +551,8 @@ declare_features! (
|
|||
(accepted, match_beginning_vert, "1.25.0", Some(44101), None),
|
||||
// Nested groups in `use` (RFC 2128)
|
||||
(accepted, use_nested_groups, "1.25.0", Some(44494), None),
|
||||
// a..=b and ..=b
|
||||
(accepted, inclusive_range_syntax, "1.26.0", Some(28237), None),
|
||||
);
|
||||
|
||||
// If you change this, please modify src/doc/unstable-book as well. You must
|
||||
|
@ -1592,11 +1591,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
|||
gate_feature_post!(&self, type_ascription, e.span,
|
||||
"type ascription is experimental");
|
||||
}
|
||||
ast::ExprKind::Range(_, _, ast::RangeLimits::Closed) => {
|
||||
gate_feature_post!(&self, inclusive_range_syntax,
|
||||
e.span,
|
||||
"inclusive range syntax is experimental");
|
||||
}
|
||||
ast::ExprKind::InPlace(..) => {
|
||||
gate_feature_post!(&self, placement_in_syntax, e.span, EXPLAIN_PLACEMENT_IN);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#![allow(warnings)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![crate_type="rlib"]
|
||||
#![feature(inclusive_range_syntax)]
|
||||
|
||||
// Change simple index ---------------------------------------------------------
|
||||
#[cfg(cfail1)]
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
// Make sure that inclusive ranges with no end point don't parse.
|
||||
|
||||
#![feature(inclusive_range_syntax)]
|
||||
|
||||
pub fn main() {
|
||||
for _ in 1..= {} //~ERROR inclusive range with no end
|
||||
//~^HELP bounded at the end
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
|
||||
// Make sure that inclusive ranges with `...` syntax don't parse.
|
||||
|
||||
#![feature(inclusive_range_syntax)]
|
||||
|
||||
use std::ops::RangeToInclusive;
|
||||
|
||||
fn return_range_to() -> RangeToInclusive<i32> {
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// gate-test-inclusive_range_syntax
|
||||
|
||||
// Make sure that #![feature(inclusive_range_syntax)] is required.
|
||||
|
||||
// #![feature(inclusive_range_syntax)]
|
||||
|
||||
macro_rules! m {
|
||||
() => { for _ in 1..=10 {} } //~ ERROR inclusive range syntax is experimental
|
||||
}
|
||||
|
||||
#[cfg(nope)]
|
||||
fn f() {}
|
||||
#[cfg(not(nope))]
|
||||
fn f() {
|
||||
for _ in 1..=10 {} //~ ERROR inclusive range syntax is experimental
|
||||
}
|
||||
|
||||
#[cfg(nope)]
|
||||
macro_rules! n { () => {} }
|
||||
#[cfg(not(nope))]
|
||||
macro_rules! n {
|
||||
() => { for _ in 1..=10 {} } //~ ERROR inclusive range syntax is experimental
|
||||
}
|
||||
|
||||
macro_rules! o {
|
||||
() => {{
|
||||
#[cfg(nope)]
|
||||
fn g() {}
|
||||
#[cfg(not(nope))]
|
||||
fn g() {
|
||||
for _ in 1..=10 {} //~ ERROR inclusive range syntax is experimental
|
||||
}
|
||||
|
||||
g();
|
||||
}}
|
||||
}
|
||||
|
||||
#[cfg(nope)]
|
||||
macro_rules! p { () => {} }
|
||||
#[cfg(not(nope))]
|
||||
macro_rules! p {
|
||||
() => {{
|
||||
#[cfg(nope)]
|
||||
fn h() {}
|
||||
#[cfg(not(nope))]
|
||||
fn h() {
|
||||
for _ in 1..=10 {} //~ ERROR inclusive range syntax is experimental
|
||||
}
|
||||
|
||||
h();
|
||||
}}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
for _ in 1..=10 {} //~ ERROR inclusive range syntax is experimental
|
||||
for _ in ..=10 {} //~ ERROR inclusive range syntax is experimental
|
||||
|
||||
f(); // not allowed in cfg'ed functions
|
||||
|
||||
m!(); // not allowed in macros
|
||||
n!(); // not allowed in cfg'ed macros
|
||||
o!(); // not allowed in macros that output cfgs
|
||||
p!(); // not allowed in cfg'ed macros that output cfgs
|
||||
}
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
// Test inclusive range syntax.
|
||||
|
||||
#![feature(inclusive_range_syntax, iterator_step_by)]
|
||||
#![feature(iterator_step_by)]
|
||||
|
||||
use std::ops::{RangeInclusive, RangeToInclusive};
|
||||
|
||||
|
|
|
@ -9,8 +9,7 @@
|
|||
// except according to those terms.
|
||||
|
||||
// Test that you only need the syntax gate if you don't mention the structs.
|
||||
|
||||
#![feature(inclusive_range_syntax)]
|
||||
// (Obsoleted since both features are stabilized)
|
||||
|
||||
fn main() {
|
||||
let mut count = 0;
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
|
||||
// Make sure that invalid ranges generate an error during HIR lowering, not an ICE
|
||||
|
||||
#![feature(inclusive_range_syntax)]
|
||||
|
||||
pub fn main() {
|
||||
..;
|
||||
0..;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error[E0586]: inclusive range with no end
|
||||
--> $DIR/impossible_range.rs:20:8
|
||||
--> $DIR/impossible_range.rs:18:8
|
||||
|
|
||||
LL | ..=; //~ERROR inclusive range with no end
|
||||
| ^
|
||||
|
@ -7,7 +7,7 @@ LL | ..=; //~ERROR inclusive range with no end
|
|||
= help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
|
||||
|
||||
error[E0586]: inclusive range with no end
|
||||
--> $DIR/impossible_range.rs:27:9
|
||||
--> $DIR/impossible_range.rs:25:9
|
||||
|
|
||||
LL | 0..=; //~ERROR inclusive range with no end
|
||||
| ^
|
||||
|
|
Loading…
Add table
Reference in a new issue