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 size_hint for Range #10416

Merged
merged 2 commits into from
Nov 11, 2013
Merged

Implement size_hint for Range #10416

merged 2 commits into from
Nov 11, 2013

Conversation

emberian
Copy link
Member

No description provided.

// Blocked on #8605 Need numeric trait for converting to `Option<uint>`
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) {
match self.state.to_uint() {
Copy link
Member

Choose a reason for hiding this comment

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

let opt_bound = do self.state.to_uint().and_then |a| {
     do self.stop.to_uint().map(|b| b - a);
};
opt_bound.map_default((uint::max_value, None), |bound| (bound, Some(bound)))

maybe?

Also, what happens if b - a wraps? (Is it possible with a sane type A?)

Copy link
Member

Choose a reason for hiding this comment

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

Oh, also, what about range(-10i, -1i).size_hint()? Won't this give uint::max_value as the lower bound, incorrectly?

@bors bors closed this Nov 11, 2013
@bors bors merged commit fc01f20 into rust-lang:master Nov 11, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jun 30, 2023
…shearth

Extend `explicit_iter_loop` and `explicit_into_iter_loop`

fixes rust-lang#1518

Some included cleanups
* Split `for_loop` test into different files for each lint (partially).
* Move handling of some `into_iter` cases from `explicit_into_iter`.

---

changelog: Enhancement: [`explicit_iter_loop`]: Now also handles types that implement `IntoIterator`.
[rust-lang#10416](rust-lang/rust-clippy#10416)

changelog: Sugg: [`explicit_into_iter_loop`]: The suggestion now works on mutable references.
[rust-lang#10416](rust-lang/rust-clippy#10416)
<!-- changelog_checked -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants