Skip to content
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

Merged
merged 1 commit into from
Feb 14, 2025
Merged

add IntoBounds trait #136904

merged 1 commit into from
Feb 14, 2025

Conversation

pitaj
Copy link
Contributor

@pitaj pitaj commented Feb 12, 2025

for range_into_bounds feature

Tracking issue: #136903
ACP: rust-lang/libs-team#538

@rustbot
Copy link
Collaborator

rustbot commented Feb 12, 2025

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 12, 2025
@pitaj pitaj force-pushed the range-into_bounds branch from 2047de7 to 40d00c6 Compare February 12, 2025 05:04
Comment on lines 1028 to 1041
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)
},
)
}
}
Copy link
Contributor

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).

Copy link
Contributor Author

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>:

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.

Copy link
Contributor

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 :)

@tgross35
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Feb 12, 2025

📌 Commit 40d00c6 has been approved by tgross35

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 12, 2025
/// `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> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub trait IntoBounds<T: Sized>: RangeBounds<T> {
pub trait IntoBounds<T>: RangeBounds<T> {

<T> means <T: Sized>

@tgross35
Copy link
Contributor

@bors r- #136904 (comment)

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 12, 2025
for `range_into_bounds`  feature, rust-lang#136903
@pitaj pitaj force-pushed the range-into_bounds branch from 40d00c6 to 9c03369 Compare February 13, 2025 00:38
@pitaj
Copy link
Contributor Author

pitaj commented Feb 13, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 13, 2025
@tgross35
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Feb 13, 2025

📌 Commit 9c03369 has been approved by tgross35

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 13, 2025
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Feb 14, 2025
add `IntoBounds` trait

for `range_into_bounds`  feature

Tracking issue: rust-lang#136903
ACP: rust-lang/libs-team#538
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 14, 2025
…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
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 14, 2025
…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
@bors bors merged commit a82d7d6 into rust-lang:master Feb 14, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Feb 14, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 14, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants