From f5a367c7bb50f74d82c3909d5c961baac879242e Mon Sep 17 00:00:00 2001 From: Steven Malis Date: Sat, 7 Apr 2018 15:47:18 -0700 Subject: [PATCH 1/5] Update based on RangeBounds trait being moved to libcore. --- src/libcore/ops/range.rs | 75 ++++++++++++++++--- src/librustc_errors/emitter.rs | 4 +- .../borrow_check/nll/universal_regions.rs | 8 +- 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs index 3f667407125..210a0e118d5 100644 --- a/src/libcore/ops/range.rs +++ b/src/libcore/ops/range.rs @@ -109,8 +109,12 @@ impl> Range { /// assert!(!(3..2).contains(3)); /// ``` #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] - pub fn contains(&self, item: Idx) -> bool { - (self.start <= item) && (item < self.end) + pub fn contains(&self, item: &U) -> bool + where + Idx: PartialOrd, + U: ?Sized, + { + >::contains(self, item) } /// Returns `true` if the range contains no items. @@ -179,7 +183,6 @@ impl fmt::Debug for RangeFrom { } } -#[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] impl> RangeFrom { /// Returns `true` if `item` is contained in the range. /// @@ -192,8 +195,13 @@ impl> RangeFrom { /// assert!( (3..).contains(3)); /// assert!( (3..).contains(1_000_000_000)); /// ``` - pub fn contains(&self, item: Idx) -> bool { - (self.start <= item) + #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] + pub fn contains(&self, item: &U) -> bool + where + Idx: PartialOrd, + U: ?Sized, + { + >::contains(self, item) } } @@ -250,7 +258,6 @@ impl fmt::Debug for RangeTo { } } -#[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] impl> RangeTo { /// Returns `true` if `item` is contained in the range. /// @@ -263,8 +270,13 @@ impl> RangeTo { /// assert!( (..5).contains(4)); /// assert!(!(..5).contains(5)); /// ``` - pub fn contains(&self, item: Idx) -> bool { - (item < self.end) + #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] + pub fn contains(&self, item: &U) -> bool + where + Idx: PartialOrd, + U: ?Sized, + { + >::contains(self, item) } } @@ -328,8 +340,12 @@ impl> RangeInclusive { /// assert!(!(3..=2).contains(3)); /// ``` #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] - pub fn contains(&self, item: Idx) -> bool { - self.start <= item && item <= self.end + pub fn contains(&self, item: &U) -> bool + where + Idx: PartialOrd, + U: ?Sized, + { + >::contains(self, item) } /// Returns `true` if the range contains no items. @@ -435,8 +451,13 @@ impl> RangeToInclusive { /// assert!( (..=5).contains(5)); /// assert!(!(..=5).contains(6)); /// ``` - pub fn contains(&self, item: Idx) -> bool { - (item <= self.end) + #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] + pub fn contains(&self, item: &U) -> bool + where + Idx: PartialOrd, + U: ?Sized, + { + >::contains(self, item) } } @@ -537,6 +558,36 @@ pub trait RangeBounds { /// # } /// ``` fn end(&self) -> Bound<&T>; + + /// Returns `true` if `item` is contained in the range. + #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] + fn contains(&self, item: &U) -> bool + where + T: PartialOrd, + U: ?Sized, + { + match self.start() { + Included(ref start) => if *start > item { + return false; + }, + Excluded(ref start) => if *start >= item { + return false; + }, + Unbounded => (), + }; + + match self.end() { + Included(ref end) => if *end < item { + return false; + }, + Excluded(ref end) => if *end <= item { + return false; + }, + Unbounded => (), + } + + true + } } use self::Bound::{Excluded, Included, Unbounded}; diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index ca5d3f55a0f..91075ddcfa4 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -1389,8 +1389,8 @@ fn num_overlap(a_start: usize, a_end: usize, b_start: usize, b_end:usize, inclus } else { 0 }; - (b_start..b_end + extra).contains(a_start) || - (a_start..a_end + extra).contains(b_start) + (b_start..b_end + extra).contains(&a_start) || + (a_start..a_end + extra).contains(&b_start) } fn overlaps(a1: &Annotation, a2: &Annotation, padding: usize) -> bool { num_overlap(a1.start_col, a1.end_col + padding, a2.start_col, a2.end_col, false) diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index 39dc29ba18b..0fe6265345d 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -259,18 +259,18 @@ impl<'tcx> UniversalRegions<'tcx> { /// True if `r` is a member of this set of universal regions. pub fn is_universal_region(&self, r: RegionVid) -> bool { - (FIRST_GLOBAL_INDEX..self.num_universals).contains(r.index()) + (FIRST_GLOBAL_INDEX..self.num_universals).contains(&r.index()) } /// Classifies `r` as a universal region, returning `None` if this /// is not a member of this set of universal regions. pub fn region_classification(&self, r: RegionVid) -> Option { let index = r.index(); - if (FIRST_GLOBAL_INDEX..self.first_extern_index).contains(index) { + if (FIRST_GLOBAL_INDEX..self.first_extern_index).contains(&index) { Some(RegionClassification::Global) - } else if (self.first_extern_index..self.first_local_index).contains(index) { + } else if (self.first_extern_index..self.first_local_index).contains(&index) { Some(RegionClassification::External) - } else if (self.first_local_index..self.num_universals).contains(index) { + } else if (self.first_local_index..self.num_universals).contains(&index) { Some(RegionClassification::Local) } else { None From 16f30c2da2a92ff9264935ac309b3e94bbd83ddf Mon Sep 17 00:00:00 2001 From: Steven Malis Date: Sat, 7 Apr 2018 18:34:12 -0700 Subject: [PATCH 2/5] fix tests --- src/libcore/ops/range.rs | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs index 210a0e118d5..97b476fa5b6 100644 --- a/src/libcore/ops/range.rs +++ b/src/libcore/ops/range.rs @@ -100,13 +100,13 @@ impl> Range { /// ``` /// #![feature(range_contains)] /// - /// assert!(!(3..5).contains(2)); - /// assert!( (3..5).contains(3)); - /// assert!( (3..5).contains(4)); - /// assert!(!(3..5).contains(5)); + /// assert!(!(3..5).contains(&2)); + /// assert!( (3..5).contains(&3)); + /// assert!( (3..5).contains(&4)); + /// assert!(!(3..5).contains(&5)); /// - /// assert!(!(3..3).contains(3)); - /// assert!(!(3..2).contains(3)); + /// assert!(!(3..3).contains(&3)); + /// assert!(!(3..2).contains(&3)); /// ``` #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] pub fn contains(&self, item: &U) -> bool @@ -191,9 +191,9 @@ impl> RangeFrom { /// ``` /// #![feature(range_contains)] /// - /// assert!(!(3..).contains(2)); - /// assert!( (3..).contains(3)); - /// assert!( (3..).contains(1_000_000_000)); + /// assert!(!(3..).contains(&2)); + /// assert!( (3..).contains(&3)); + /// assert!( (3..).contains(&1_000_000_000)); /// ``` #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] pub fn contains(&self, item: &U) -> bool @@ -266,9 +266,9 @@ impl> RangeTo { /// ``` /// #![feature(range_contains)] /// - /// assert!( (..5).contains(-1_000_000_000)); - /// assert!( (..5).contains(4)); - /// assert!(!(..5).contains(5)); + /// assert!( (..5).contains(&-1_000_000_000)); + /// assert!( (..5).contains(&4)); + /// assert!(!(..5).contains(&5)); /// ``` #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] pub fn contains(&self, item: &U) -> bool @@ -330,14 +330,14 @@ impl> RangeInclusive { /// ``` /// #![feature(range_contains)] /// - /// assert!(!(3..=5).contains(2)); - /// assert!( (3..=5).contains(3)); - /// assert!( (3..=5).contains(4)); - /// assert!( (3..=5).contains(5)); - /// assert!(!(3..=5).contains(6)); + /// assert!(!(3..=5).contains(&2)); + /// assert!( (3..=5).contains(&3)); + /// assert!( (3..=5).contains(&4)); + /// assert!( (3..=5).contains(&5)); + /// assert!(!(3..=5).contains(&6)); /// - /// assert!( (3..=3).contains(3)); - /// assert!(!(3..=2).contains(3)); + /// assert!( (3..=3).contains(&3)); + /// assert!(!(3..=2).contains(&3)); /// ``` #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] pub fn contains(&self, item: &U) -> bool @@ -447,9 +447,9 @@ impl> RangeToInclusive { /// ``` /// #![feature(range_contains)] /// - /// assert!( (..=5).contains(-1_000_000_000)); - /// assert!( (..=5).contains(5)); - /// assert!(!(..=5).contains(6)); + /// assert!( (..=5).contains(&-1_000_000_000)); + /// assert!( (..=5).contains(&5)); + /// assert!(!(..=5).contains(&6)); /// ``` #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] pub fn contains(&self, item: &U) -> bool From 249dc9e5cd5abaea710345fcabca815e5e59eec6 Mon Sep 17 00:00:00 2001 From: Steven Malis Date: Sat, 7 Apr 2018 21:09:26 -0700 Subject: [PATCH 3/5] Add float NaN tests. --- src/libcore/ops/range.rs | 80 +++++++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 21 deletions(-) diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs index 97b476fa5b6..868308cafd1 100644 --- a/src/libcore/ops/range.rs +++ b/src/libcore/ops/range.rs @@ -100,6 +100,8 @@ impl> Range { /// ``` /// #![feature(range_contains)] /// + /// use std::f32; + /// /// assert!(!(3..5).contains(&2)); /// assert!( (3..5).contains(&3)); /// assert!( (3..5).contains(&4)); @@ -107,6 +109,11 @@ impl> Range { /// /// assert!(!(3..3).contains(&3)); /// assert!(!(3..2).contains(&3)); + /// + /// assert!( (0.0..1.0).contains(&0.5)); + /// assert!(!(0.0..1.0).contains(&f32::NAN)); + /// assert!(!(0.0..f32::NAN).contains(&0.5)); + /// assert!(!(f32::NAN..1.0).contains(&0.5)); /// ``` #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] pub fn contains(&self, item: &U) -> bool @@ -191,9 +198,15 @@ impl> RangeFrom { /// ``` /// #![feature(range_contains)] /// + /// use std::f32; + /// /// assert!(!(3..).contains(&2)); /// assert!( (3..).contains(&3)); /// assert!( (3..).contains(&1_000_000_000)); + /// + /// assert!( (0.0..).contains(&0.5)); + /// assert!(!(0.0..).contains(&f32::NAN)); + /// assert!(!(f32::NAN..).contains(&0.5)); /// ``` #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] pub fn contains(&self, item: &U) -> bool @@ -266,9 +279,15 @@ impl> RangeTo { /// ``` /// #![feature(range_contains)] /// + /// use std::f32; + /// /// assert!( (..5).contains(&-1_000_000_000)); /// assert!( (..5).contains(&4)); /// assert!(!(..5).contains(&5)); + /// + /// assert!( (..1.0).contains(&0.5)); + /// assert!(!(..1.0).contains(&f32::NAN)); + /// assert!(!(..f32::NAN).contains(&0.5)); /// ``` #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] pub fn contains(&self, item: &U) -> bool @@ -330,6 +349,8 @@ impl> RangeInclusive { /// ``` /// #![feature(range_contains)] /// + /// use std::f32; + /// /// assert!(!(3..=5).contains(&2)); /// assert!( (3..=5).contains(&3)); /// assert!( (3..=5).contains(&4)); @@ -338,6 +359,11 @@ impl> RangeInclusive { /// /// assert!( (3..=3).contains(&3)); /// assert!(!(3..=2).contains(&3)); + /// + /// assert!( (0.0..=1.0).contains(&1.0)); + /// assert!(!(0.0..=1.0).contains(&f32::NAN)); + /// assert!(!(0.0..=f32::NAN).contains(&0.0)); + /// assert!(!(f32::NAN..=1.0).contains(&1.0)); /// ``` #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] pub fn contains(&self, item: &U) -> bool @@ -447,9 +473,15 @@ impl> RangeToInclusive { /// ``` /// #![feature(range_contains)] /// + /// use std::f32; + /// /// assert!( (..=5).contains(&-1_000_000_000)); /// assert!( (..=5).contains(&5)); /// assert!(!(..=5).contains(&6)); + /// + /// assert!( (..=1.0).contains(&1.0)); + /// assert!(!(..=1.0).contains(&f32::NAN)); + /// assert!(!(..=f32::NAN).contains(&0.5)); /// ``` #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] pub fn contains(&self, item: &U) -> bool @@ -559,34 +591,40 @@ pub trait RangeBounds { /// ``` fn end(&self) -> Bound<&T>; + /// Returns `true` if `item` is contained in the range. + /// + /// # Examples + /// + /// ``` + /// #![feature(range_contains)] + /// + /// use std::f32; + /// + /// assert!( (3..5).contains(&4)); + /// assert!(!(3..5).contains(&2)); + /// + /// assert!( (0.0..1.0).contains(&0.5)); + /// assert!(!(0.0..1.0).contains(&f32::NAN)); + /// assert!(!(0.0..f32::NAN).contains(&0.5)); + /// assert!(!(f32::NAN..1.0).contains(&0.5)); #[unstable(feature = "range_contains", reason = "recently added as per RFC", issue = "32311")] fn contains(&self, item: &U) -> bool where T: PartialOrd, U: ?Sized, { - match self.start() { - Included(ref start) => if *start > item { - return false; - }, - Excluded(ref start) => if *start >= item { - return false; - }, - Unbounded => (), - }; - - match self.end() { - Included(ref end) => if *end < item { - return false; - }, - Excluded(ref end) => if *end <= item { - return false; - }, - Unbounded => (), - } - - true + (match self.start() { + Included(ref start) => *start <= item, + Excluded(ref start) => *start < item, + Unbounded => true, + }) + && + (match self.end() { + Included(ref end) => *end >= item, + Excluded(ref end) => *end > item, + Unbounded => true, + }) } } From 51f24ec7f01b6a636750baff5ab5a12ec6bfe6cd Mon Sep 17 00:00:00 2001 From: Steven Malis Date: Tue, 10 Apr 2018 19:26:25 -0700 Subject: [PATCH 4/5] Add symmetric requirement of PartialOrd. --- src/libcore/ops/range.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs index 868308cafd1..6f3e3b50885 100644 --- a/src/libcore/ops/range.rs +++ b/src/libcore/ops/range.rs @@ -119,7 +119,7 @@ impl> Range { pub fn contains(&self, item: &U) -> bool where Idx: PartialOrd, - U: ?Sized, + U: ?Sized + PartialOrd, { >::contains(self, item) } @@ -212,7 +212,7 @@ impl> RangeFrom { pub fn contains(&self, item: &U) -> bool where Idx: PartialOrd, - U: ?Sized, + U: ?Sized + PartialOrd, { >::contains(self, item) } @@ -293,7 +293,7 @@ impl> RangeTo { pub fn contains(&self, item: &U) -> bool where Idx: PartialOrd, - U: ?Sized, + U: ?Sized + PartialOrd, { >::contains(self, item) } @@ -369,7 +369,7 @@ impl> RangeInclusive { pub fn contains(&self, item: &U) -> bool where Idx: PartialOrd, - U: ?Sized, + U: ?Sized + PartialOrd, { >::contains(self, item) } @@ -487,7 +487,7 @@ impl> RangeToInclusive { pub fn contains(&self, item: &U) -> bool where Idx: PartialOrd, - U: ?Sized, + U: ?Sized + PartialOrd, { >::contains(self, item) } @@ -612,7 +612,7 @@ pub trait RangeBounds { fn contains(&self, item: &U) -> bool where T: PartialOrd, - U: ?Sized, + U: ?Sized + PartialOrd, { (match self.start() { Included(ref start) => *start <= item, @@ -621,8 +621,8 @@ pub trait RangeBounds { }) && (match self.end() { - Included(ref end) => *end >= item, - Excluded(ref end) => *end > item, + Included(ref end) => item <= *end, + Excluded(ref end) => item < *end, Unbounded => true, }) } From 6c3e1d75553a4b2dbafb8d62a565d10a09c61fc2 Mon Sep 17 00:00:00 2001 From: kennytm Date: Wed, 4 Apr 2018 18:43:00 +0800 Subject: [PATCH 5/5] Remove `underscore_lifetimes` and `match_default_bindings` from active feature list These are already stabilized in 1.26. --- src/librustc_trans/lib.rs | 1 - src/librustc_typeck/lib.rs | 1 - src/libsyntax/feature_gate.rs | 6 ------ 3 files changed, 8 deletions(-) diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index a38d51e7546..49d0f638f20 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -29,7 +29,6 @@ #![feature(slice_sort_by_cached_key)] #![feature(optin_builtin_traits)] #![feature(inclusive_range_fields)] -#![feature(underscore_lifetimes)] use rustc::dep_graph::WorkProduct; use syntax_pos::symbol::Symbol; diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index a4477e80b98..4b66939963e 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -82,7 +82,6 @@ This API is completely unstable and subject to change. #![feature(slice_patterns)] #![feature(slice_sort_by_cached_key)] #![feature(dyn_trait)] -#![feature(underscore_lifetimes)] #[macro_use] extern crate log; #[macro_use] extern crate syntax; diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 73ebfc20876..eaa2050f608 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -378,12 +378,6 @@ declare_features! ( // Future-proofing enums/structs with #[non_exhaustive] attribute (RFC 2008) (active, non_exhaustive, "1.22.0", Some(44109), None), - // allow `'_` placeholder lifetimes - (active, underscore_lifetimes, "1.22.0", Some(44524), None), - - // Default match binding modes (RFC 2005) - (active, match_default_bindings, "1.22.0", Some(42640), None), - // Trait object syntax with `dyn` prefix (active, dyn_trait, "1.22.0", Some(44662), Some(Edition::Edition2018)),