-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
stabilize new RangeToInclusive type #152304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+120
−19
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -43,7 +43,7 @@ pub use iter::{RangeFromIter, RangeIter}; | |
| // pub use crate::ops::{Bound, IntoBounds, OneSidedRange, RangeBounds, RangeFull, RangeTo}; | ||
| use crate::iter::Step; | ||
| use crate::ops::Bound::{self, Excluded, Included, Unbounded}; | ||
| use crate::ops::{IntoBounds, RangeBounds}; | ||
| use crate::ops::{IntoBounds, OneSidedRange, OneSidedRangeBound, RangeBounds}; | ||
|
|
||
| /// A (half-open) range bounded inclusively below and exclusively above | ||
| /// (`start..end` in a future edition). | ||
|
|
@@ -546,6 +546,18 @@ impl<T> const IntoBounds<T> for RangeFrom<T> { | |
| } | ||
| } | ||
|
|
||
| #[unstable(feature = "one_sided_range", issue = "69780")] | ||
| // #[unstable(feature = "new_range_api", issue = "125687")] | ||
| #[rustc_const_unstable(feature = "const_range", issue = "none")] | ||
| impl<T> const OneSidedRange<T> for RangeFrom<T> | ||
| where | ||
| Self: RangeBounds<T>, | ||
| { | ||
| fn bound(self) -> (OneSidedRangeBound, T) { | ||
| (OneSidedRangeBound::StartInclusive, self.start) | ||
| } | ||
| } | ||
|
|
||
| #[unstable(feature = "new_range_api", issue = "125687")] | ||
| #[rustc_const_unstable(feature = "const_index", issue = "143775")] | ||
| impl<T> const From<RangeFrom<T>> for legacy::RangeFrom<T> { | ||
|
|
@@ -573,9 +585,8 @@ impl<T> const From<legacy::RangeFrom<T>> for RangeFrom<T> { | |
| /// The `..=last` syntax is a `RangeToInclusive`: | ||
| /// | ||
| /// ``` | ||
| /// #![feature(new_range_api)] | ||
| /// #![feature(new_range)] | ||
| /// assert_eq!((..=5), std::range::RangeToInclusive{ last: 5 }); | ||
| /// assert_eq!((..=5), std::range::RangeToInclusive { last: 5 }); | ||
| /// ``` | ||
| /// | ||
| /// It does not have an [`IntoIterator`] implementation, so you can't use it in a | ||
|
|
@@ -606,14 +617,14 @@ impl<T> const From<legacy::RangeFrom<T>> for RangeFrom<T> { | |
| #[lang = "RangeToInclusiveCopy"] | ||
| #[doc(alias = "..=")] | ||
| #[derive(Copy, Clone, PartialEq, Eq, Hash)] | ||
| #[unstable(feature = "new_range_api", issue = "125687")] | ||
| #[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")] | ||
| pub struct RangeToInclusive<Idx> { | ||
| /// The upper bound of the range (inclusive) | ||
| #[unstable(feature = "new_range_api", issue = "125687")] | ||
| #[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")] | ||
| pub last: Idx, | ||
| } | ||
|
|
||
| #[unstable(feature = "new_range_api", issue = "125687")] | ||
| #[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")] | ||
| impl<Idx: fmt::Debug> fmt::Debug for RangeToInclusive<Idx> { | ||
| fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| write!(fmt, "..=")?; | ||
|
|
@@ -637,7 +648,7 @@ impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> { | |
| /// assert!(!(..=f32::NAN).contains(&0.5)); | ||
| /// ``` | ||
| #[inline] | ||
| #[unstable(feature = "new_range_api", issue = "125687")] | ||
| #[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")] | ||
| #[rustc_const_unstable(feature = "const_range", issue = "none")] | ||
| pub const fn contains<U>(&self, item: &U) -> bool | ||
| where | ||
|
|
@@ -648,13 +659,13 @@ impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> { | |
| } | ||
| } | ||
|
|
||
| #[unstable(feature = "new_range_api", issue = "125687")] | ||
| #[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")] | ||
| impl<T> From<legacy::RangeToInclusive<T>> for RangeToInclusive<T> { | ||
| fn from(value: legacy::RangeToInclusive<T>) -> Self { | ||
| Self { last: value.end } | ||
| } | ||
| } | ||
| #[unstable(feature = "new_range_api", issue = "125687")] | ||
| #[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")] | ||
| impl<T> From<RangeToInclusive<T>> for legacy::RangeToInclusive<T> { | ||
| fn from(value: RangeToInclusive<T>) -> Self { | ||
| Self { end: value.last } | ||
|
|
@@ -664,7 +675,7 @@ impl<T> From<RangeToInclusive<T>> for legacy::RangeToInclusive<T> { | |
| // RangeToInclusive<Idx> cannot impl From<RangeTo<Idx>> | ||
| // because underflow would be possible with (..0).into() | ||
|
|
||
| #[unstable(feature = "new_range_api", issue = "125687")] | ||
| #[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")] | ||
| #[rustc_const_unstable(feature = "const_range", issue = "none")] | ||
| impl<T> const RangeBounds<T> for RangeToInclusive<T> { | ||
| fn start_bound(&self) -> Bound<&T> { | ||
|
|
@@ -675,10 +686,34 @@ impl<T> const RangeBounds<T> for RangeToInclusive<T> { | |
| } | ||
| } | ||
|
|
||
| #[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")] | ||
| #[rustc_const_unstable(feature = "const_range", issue = "none")] | ||
| impl<T> const RangeBounds<T> for RangeToInclusive<&T> { | ||
| fn start_bound(&self) -> Bound<&T> { | ||
| Unbounded | ||
| } | ||
| fn end_bound(&self) -> Bound<&T> { | ||
| Included(self.last) | ||
| } | ||
| } | ||
|
|
||
| // #[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")] | ||
| #[unstable(feature = "range_into_bounds", issue = "136903")] | ||
| #[rustc_const_unstable(feature = "const_range", issue = "none")] | ||
| impl<T> const IntoBounds<T> for RangeToInclusive<T> { | ||
tgross35 marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+700
to
703
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably no need to have this comment, we can't have >1 |
||
| fn into_bounds(self) -> (Bound<T>, Bound<T>) { | ||
| (Unbounded, Included(self.last)) | ||
| } | ||
| } | ||
|
|
||
| // #[stable(feature = "new_range_to_inclusive_api", since = "CURRENT_RUSTC_VERSION")] | ||
| #[unstable(feature = "one_sided_range", issue = "69780")] | ||
| #[rustc_const_unstable(feature = "const_range", issue = "none")] | ||
| impl<T> const OneSidedRange<T> for RangeToInclusive<T> | ||
| where | ||
| Self: RangeBounds<T>, | ||
| { | ||
| fn bound(self) -> (OneSidedRangeBound, T) { | ||
| (OneSidedRangeBound::EndInclusive, self.last) | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This impl can probably forward to
ops::RangeFromso we don't have the same thing twice, or vice versa