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

Implement useful steps_between for all integers #59444

Merged
merged 3 commits into from Apr 2, 2019

Conversation

Projects
None yet
7 participants
@cuviper
Copy link
Member

commented Mar 26, 2019

We can use usize::try_from to convert steps from any size of integer.
This enables a meaningful size_hint() for larger ranges, rather than
always just (0, None). Now they return the true (len, Some(len))
when it fits, otherwise (usize::MAX, None) for overflow.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Mar 26, 2019

r? @kennytm

(rust_highfive has picked a reviewer for you, use r? to override)

Implement useful steps_between for all integers
We can use `usize::try_from` to convert steps from any size of integer.
This enables a meaningful `size_hint()` for larger ranges, rather than
always just `(0, None)`. Now they return the true `(len, Some(len))`
when it fits, otherwise `(usize::MAX, None)` for overflow.

@cuviper cuviper force-pushed the cuviper:steps_between branch from cc29b44 to 01162d8 Mar 26, 2019

@Centril

This comment has been minimized.

Copy link
Contributor

commented Mar 26, 2019

@rust-highfive rust-highfive assigned scottmcm and unassigned kennytm Mar 26, 2019

@cuviper

This comment has been minimized.

Copy link
Member Author

commented Mar 26, 2019

rather than always just (0, None).

Note, this former behavior meant that a lot of the TrustedLen impls failed the contract -- e.g. Range<u64> was wrong for platforms with less than 64-bit usize. But I think it would now be correct to have TrustedLen for all integers -- should I expand that? (edit: done)

@Centril

This comment has been minimized.

Copy link
Contributor

commented Mar 30, 2019

Ping from triage, @scottmcm :)

@scottmcm

This comment has been minimized.

Copy link
Member

commented Apr 2, 2019

It looks like #43127 was worried about TryFrom previously, but #43248 has probably resolved that, so I like getting these fixed up and removing the platform-dependence.

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

commented Apr 2, 2019

📌 Commit a548d83 has been approved by scottmcm

Centril added a commit to Centril/rust that referenced this pull request Apr 2, 2019

Rollup merge of rust-lang#59444 - cuviper:steps_between, r=scottmcm
Implement useful steps_between for all integers

We can use `usize::try_from` to convert steps from any size of integer.
This enables a meaningful `size_hint()` for larger ranges, rather than
always just `(0, None)`. Now they return the true `(len, Some(len))`
when it fits, otherwise `(usize::MAX, None)` for overflow.

@Centril Centril referenced this pull request Apr 2, 2019

Merged

Rollup of 8 pull requests #59632

bors added a commit that referenced this pull request Apr 2, 2019

Auto merge of #59632 - Centril:rollup, r=Centril
Rollup of 8 pull requests

Successful merges:

 - #59262 (Remove duplicated code from Iterator::{ne, lt, le, gt, ge})
 - #59286 (Refactor async fn return type lowering)
 - #59444 (Implement useful steps_between for all integers)
 - #59452 (Speed up rustdoc run a bit)
 - #59533 (Support allocating iterators with arenas)
 - #59585 (Fixes for shallow borrows)
 - #59607 (Renames `EvalErrorKind` to `InterpError`)
 - #59613 (SGX target: convert a bunch of panics to aborts)

Failed merges:

 - #59630 (Shrink `mir::Statement`.)

r? @ghost

@bors bors merged commit a548d83 into rust-lang:master Apr 2, 2019

@cuviper

This comment has been minimized.

Copy link
Member Author

commented Apr 2, 2019

@scottmcm great, thanks for the added background!

@cuviper cuviper deleted the cuviper:steps_between branch Apr 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.