-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
add IntoBounds
trait
#136904
add IntoBounds
trait
#136904
Conversation
2047de7
to
40d00c6
Compare
library/core/src/ops/range.rs
Outdated
impl<T> IntoBounds<T> for RangeInclusive<T> { | ||
fn into_bounds(self) -> (Bound<T>, Bound<T>) { | ||
( | ||
Included(self.start), | ||
if self.exhausted { | ||
// When the iterator is exhausted, we usually have start == end, | ||
// but we want the range to appear empty, containing nothing. | ||
Excluded(self.end) | ||
} else { | ||
Included(self.end) | ||
}, | ||
) | ||
} | ||
} |
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.
Wouldn't it be a bit surprising that this provides different results from RangeBounds
?
Other than this lgtm, with an optional tiny nit that it may be nice to interleave RangeBounds
and IntoBounds
impls in this file, as you did for ops/range.rs
(just nicer to see implementations for the same type side by side).
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.
What do you mean? This follows the same pattern in impl<T> RangeBounds<T> for RangeInclusive<T>
:
rust/library/core/src/ops/range.rs
Lines 881 to 889 in 34a5ea9
fn end_bound(&self) -> Bound<&T> { | |
if self.exhausted { | |
// When the iterator is exhausted, we usually have start == end, | |
// but we want the range to appear empty, containing nothing. | |
Excluded(&self.end) | |
} else { | |
Included(&self.end) | |
} | |
} |
as you did for
ops/range.rs
I assume you mean src/range.rs
. I also prefer the organization there, but I felt this better matched the existing style in this file.
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.
You're right, I was reading a different impl. Case in point regarding the sorting I guess :)
@bors r+ |
library/core/src/ops/range.rs
Outdated
/// `IntoBounds` is implemented by Rust’s built-in range types, produced | ||
/// by range syntax like `..`, `a..`, `..b`, `..=c`, `d..e`, or `f..=g`. | ||
#[unstable(feature = "range_into_bounds", issue = "136903")] | ||
pub trait IntoBounds<T: Sized>: RangeBounds<T> { |
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.
pub trait IntoBounds<T: Sized>: RangeBounds<T> { | |
pub trait IntoBounds<T>: RangeBounds<T> { |
<T>
means <T: Sized>
for `range_into_bounds` feature, rust-lang#136903
40d00c6
to
9c03369
Compare
@rustbot ready |
@bors r+ |
add `IntoBounds` trait for `range_into_bounds` feature Tracking issue: rust-lang#136903 ACP: rust-lang/libs-team#538
…kingjubilee Rollup of 13 pull requests Successful merges: - rust-lang#135439 (Make `-O` mean `OptLevel::Aggressive`) - rust-lang#136460 (Simplify `rustc_span` `analyze_source_file`) - rust-lang#136642 (Put the alloc unit tests in a separate alloctests package) - rust-lang#136904 (add `IntoBounds` trait) - rust-lang#136908 ([AIX] expect `EINVAL` for `pthread_mutex_destroy`) - rust-lang#136924 (Add profiling of bootstrap commands using Chrome events) - rust-lang#136951 (Use the right binder for rebinding `PolyTraitRef`) - rust-lang#136956 (add vendor directory to .gitignore) - rust-lang#136967 (Use `slice::fill` in `io::Repeat` implementation) - rust-lang#136976 (alloc boxed: docs: use MaybeUninit::write instead of as_mut_ptr) - rust-lang#136981 (ci: switch loongarch jobs to free runners) - rust-lang#136992 (Update backtrace) - rust-lang#136993 ([cg_llvm] Remove dead error message) r? `@ghost` `@rustbot` modify labels: rollup
…kingjubilee Rollup of 9 pull requests Successful merges: - rust-lang#135439 (Make `-O` mean `OptLevel::Aggressive`) - rust-lang#136460 (Simplify `rustc_span` `analyze_source_file`) - rust-lang#136904 (add `IntoBounds` trait) - rust-lang#136908 ([AIX] expect `EINVAL` for `pthread_mutex_destroy`) - rust-lang#136924 (Add profiling of bootstrap commands using Chrome events) - rust-lang#136951 (Use the right binder for rebinding `PolyTraitRef`) - rust-lang#136981 (ci: switch loongarch jobs to free runners) - rust-lang#136992 (Update backtrace) - rust-lang#136993 ([cg_llvm] Remove dead error message) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#136904 - pitaj:range-into_bounds, r=tgross35 add `IntoBounds` trait for `range_into_bounds` feature Tracking issue: rust-lang#136903 ACP: rust-lang/libs-team#538
for
range_into_bounds
featureTracking issue: #136903
ACP: rust-lang/libs-team#538