Skip to content

Commit 511c3de

Browse files
Rollup merge of rust-lang#59152 - smmalis37:range_contains, r=SimonSapin
Stabilize Range*::contains. Closes rust-lang#32311. There's also a bit of rustfmt on range.rs thrown in for good measure (I forgot to turn off format-on-save in VSCode).
2 parents 935a9cf + 266ca31 commit 511c3de

File tree

5 files changed

+20
-34
lines changed

5 files changed

+20
-34
lines changed

src/libcore/ops/range.rs

+19-30
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl fmt::Debug for RangeFull {
7171
/// assert_eq!(arr[1..=3], [ 1,2,3 ]);
7272
/// ```
7373
#[doc(alias = "..")]
74-
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
74+
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
7575
#[stable(feature = "rust1", since = "1.0.0")]
7676
pub struct Range<Idx> {
7777
/// The lower bound of the range (inclusive).
@@ -95,8 +95,6 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
9595
/// # Examples
9696
///
9797
/// ```
98-
/// #![feature(range_contains)]
99-
///
10098
/// use std::f32;
10199
///
102100
/// assert!(!(3..5).contains(&2));
@@ -112,7 +110,7 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
112110
/// assert!(!(0.0..f32::NAN).contains(&0.5));
113111
/// assert!(!(f32::NAN..1.0).contains(&0.5));
114112
/// ```
115-
#[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")]
113+
#[stable(feature = "range_contains", since = "1.35.0")]
116114
pub fn contains<U>(&self, item: &U) -> bool
117115
where
118116
Idx: PartialOrd<U>,
@@ -175,7 +173,7 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
175173
///
176174
/// [`Iterator`]: ../iter/trait.IntoIterator.html
177175
#[doc(alias = "..")]
178-
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
176+
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
179177
#[stable(feature = "rust1", since = "1.0.0")]
180178
pub struct RangeFrom<Idx> {
181179
/// The lower bound of the range (inclusive).
@@ -196,8 +194,6 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
196194
/// # Examples
197195
///
198196
/// ```
199-
/// #![feature(range_contains)]
200-
///
201197
/// use std::f32;
202198
///
203199
/// assert!(!(3..).contains(&2));
@@ -208,7 +204,7 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
208204
/// assert!(!(0.0..).contains(&f32::NAN));
209205
/// assert!(!(f32::NAN..).contains(&0.5));
210206
/// ```
211-
#[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")]
207+
#[stable(feature = "range_contains", since = "1.35.0")]
212208
pub fn contains<U>(&self, item: &U) -> bool
213209
where
214210
Idx: PartialOrd<U>,
@@ -280,8 +276,6 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
280276
/// # Examples
281277
///
282278
/// ```
283-
/// #![feature(range_contains)]
284-
///
285279
/// use std::f32;
286280
///
287281
/// assert!( (..5).contains(&-1_000_000_000));
@@ -292,7 +286,7 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
292286
/// assert!(!(..1.0).contains(&f32::NAN));
293287
/// assert!(!(..f32::NAN).contains(&0.5));
294288
/// ```
295-
#[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")]
289+
#[stable(feature = "range_contains", since = "1.35.0")]
296290
pub fn contains<U>(&self, item: &U) -> bool
297291
where
298292
Idx: PartialOrd<U>,
@@ -329,7 +323,7 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
329323
/// assert_eq!(arr[1..=3], [ 1,2,3 ]); // RangeInclusive
330324
/// ```
331325
#[doc(alias = "..=")]
332-
#[derive(Clone)] // not Copy -- see #27186
326+
#[derive(Clone)] // not Copy -- see #27186
333327
#[stable(feature = "inclusive_range", since = "1.26.0")]
334328
pub struct RangeInclusive<Idx> {
335329
pub(crate) start: Idx,
@@ -365,7 +359,8 @@ impl<T: PartialOrd> RangeInclusiveEquality for T {
365359
impl<Idx: PartialEq> PartialEq for RangeInclusive<Idx> {
366360
#[inline]
367361
fn eq(&self, other: &Self) -> bool {
368-
self.start == other.start && self.end == other.end
362+
self.start == other.start
363+
&& self.end == other.end
369364
&& RangeInclusiveEquality::canonicalized_is_empty(self)
370365
== RangeInclusiveEquality::canonicalized_is_empty(other)
371366
}
@@ -397,7 +392,11 @@ impl<Idx> RangeInclusive<Idx> {
397392
#[inline]
398393
#[rustc_promotable]
399394
pub const fn new(start: Idx, end: Idx) -> Self {
400-
Self { start, end, is_empty: None }
395+
Self {
396+
start,
397+
end,
398+
is_empty: None,
399+
}
401400
}
402401

403402
/// Returns the lower bound of the range (inclusive).
@@ -478,8 +477,6 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
478477
/// # Examples
479478
///
480479
/// ```
481-
/// #![feature(range_contains)]
482-
///
483480
/// use std::f32;
484481
///
485482
/// assert!(!(3..=5).contains(&2));
@@ -496,7 +493,7 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
496493
/// assert!(!(0.0..=f32::NAN).contains(&0.0));
497494
/// assert!(!(f32::NAN..=1.0).contains(&1.0));
498495
/// ```
499-
#[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")]
496+
#[stable(feature = "range_contains", since = "1.35.0")]
500497
pub fn contains<U>(&self, item: &U) -> bool
501498
where
502499
Idx: PartialOrd<U>,
@@ -609,15 +606,12 @@ impl<Idx: fmt::Debug> fmt::Debug for RangeToInclusive<Idx> {
609606
}
610607
}
611608

612-
#[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")]
613609
impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
614610
/// Returns `true` if `item` is contained in the range.
615611
///
616612
/// # Examples
617613
///
618614
/// ```
619-
/// #![feature(range_contains)]
620-
///
621615
/// use std::f32;
622616
///
623617
/// assert!( (..=5).contains(&-1_000_000_000));
@@ -628,7 +622,7 @@ impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
628622
/// assert!(!(..=1.0).contains(&f32::NAN));
629623
/// assert!(!(..=f32::NAN).contains(&0.5));
630624
/// ```
631-
#[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")]
625+
#[stable(feature = "range_contains", since = "1.35.0")]
632626
pub fn contains<U>(&self, item: &U) -> bool
633627
where
634628
Idx: PartialOrd<U>,
@@ -730,14 +724,11 @@ pub trait RangeBounds<T: ?Sized> {
730724
#[stable(feature = "collections_range", since = "1.28.0")]
731725
fn end_bound(&self) -> Bound<&T>;
732726

733-
734727
/// Returns `true` if `item` is contained in the range.
735728
///
736729
/// # Examples
737730
///
738731
/// ```
739-
/// #![feature(range_contains)]
740-
///
741732
/// use std::f32;
742733
///
743734
/// assert!( (3..5).contains(&4));
@@ -747,7 +738,7 @@ pub trait RangeBounds<T: ?Sized> {
747738
/// assert!(!(0.0..1.0).contains(&f32::NAN));
748739
/// assert!(!(0.0..f32::NAN).contains(&0.5));
749740
/// assert!(!(f32::NAN..1.0).contains(&0.5));
750-
#[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")]
741+
#[stable(feature = "range_contains", since = "1.35.0")]
751742
fn contains<U>(&self, item: &U) -> bool
752743
where
753744
T: PartialOrd<U>,
@@ -757,9 +748,7 @@ pub trait RangeBounds<T: ?Sized> {
757748
Included(ref start) => *start <= item,
758749
Excluded(ref start) => *start < item,
759750
Unbounded => true,
760-
})
761-
&&
762-
(match self.end_bound() {
751+
}) && (match self.end_bound() {
763752
Included(ref end) => item <= *end,
764753
Excluded(ref end) => item < *end,
765754
Unbounded => true,
@@ -835,15 +824,15 @@ impl<T> RangeBounds<T> for (Bound<T>, Bound<T>) {
835824
match *self {
836825
(Included(ref start), _) => Included(start),
837826
(Excluded(ref start), _) => Excluded(start),
838-
(Unbounded, _) => Unbounded,
827+
(Unbounded, _) => Unbounded,
839828
}
840829
}
841830

842831
fn end_bound(&self) -> Bound<&T> {
843832
match *self {
844833
(_, Included(ref end)) => Included(end),
845834
(_, Excluded(ref end)) => Excluded(end),
846-
(_, Unbounded) => Unbounded,
835+
(_, Unbounded) => Unbounded,
847836
}
848837
}
849838
}

src/librustc_codegen_llvm/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#![allow(unused_attributes)]
1616
#![feature(libc)]
1717
#![feature(nll)]
18-
#![feature(range_contains)]
1918
#![feature(rustc_diagnostic_macros)]
2019
#![feature(optin_builtin_traits)]
2120
#![feature(concat_idents)]

src/librustc_errors/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#![feature(custom_attribute)]
44
#![allow(unused_attributes)]
5-
#![feature(range_contains)]
65
#![cfg_attr(unix, feature(libc))]
76
#![feature(nll)]
87
#![feature(optin_builtin_traits)]

src/librustc_mir/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
1414
#![feature(const_fn)]
1515
#![feature(decl_macro)]
1616
#![feature(exhaustive_patterns)]
17-
#![feature(range_contains)]
1817
#![feature(rustc_diagnostic_macros)]
1918
#![feature(rustc_attrs)]
2019
#![feature(never_type)]

src/libstd/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221

222222
#![cfg_attr(test, feature(print_internals, set_stdio, test, update_panic_count))]
223223
#![cfg_attr(all(target_vendor = "fortanix", target_env = "sgx"),
224-
feature(global_asm, range_contains, slice_index_methods,
224+
feature(global_asm, slice_index_methods,
225225
decl_macro, coerce_unsized, sgx_platform, ptr_wrapping_offset_from))]
226226

227227
// std is implemented with unstable features, many of which are internal

0 commit comments

Comments
 (0)