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

"0u8.." panics #35589

Closed
Christopher22 opened this issue Aug 11, 2016 · 5 comments
Closed

"0u8.." panics #35589

Christopher22 opened this issue Aug 11, 2016 · 5 comments
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@Christopher22
Copy link

The range for u8 does not work properly, it panics at the (valid) value 255. If this behavior is expected for bytes it should be documentated.

I tried this code to check correctness and it panics:
fn main() { assert_eq!((0u8..).last(), Some(255)); }

thread 'main' panicked at 'arithmetic operation overflowed', ../src/libcore/ops.rs:211
note: Run with RUST_BACKTRACE=1 for a backtrace.

Rusty greedings, Christopher
#24119

@arielb1 arielb1 added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Aug 11, 2016
@TimNN
Copy link
Contributor

TimNN commented Aug 11, 2016

Mh, this issue looks interesting. Frist of all, in my opinition, (0..).last() would always overflow / be an "endless loop" since you're trying to get the last element of an open ended sequence.

I've been trying some things and found the following "interesting behaviour":

The code println!("{:?}", (255u8..).next());:

  • tiggers arithmetic operation overflowed on stable/debug
  • causes timeout triggered! (playpen) on beta/debug
  • prints Some(255) on nightly/debug
  • prints Some(255) on */release

@nagisa
Copy link
Member

nagisa commented Aug 11, 2016

prints Some(255) on nightly/debug

That’s amusing. I feel like overflow on debug was intentional (i.e. the stable/debug behaviour is the intended one).

@nagisa
Copy link
Member

nagisa commented Aug 11, 2016

Duplicate of #25708 by the way, but @TimNN points out a regression, so probably shouldn’t be closed?

@Mark-Simulacrum
Copy link
Member

Looks like another regression that slipped through. cc @alexcrichton @brson; I don't know what we want to do about this issue, but if the regression is no longer a priority, it can be closed as a duplicate. Nightly output today, without release optimizations, is below. With them, it simply hangs.

thread 'main' panicked at 'attempt to add with overflow', /home/mark/BuildDisk/rust/src/libcore/ops.rs:264
note: Run with `RUST_BACKTRACE=1` for a backtrace.

@nagisa
Copy link
Member

nagisa commented Jun 9, 2017

This is what the documentation for last has to say:

This method will evaluate the iterator until it returns None. While doing so, it keeps track of the current element. After None is returned, last() will then return the last element it saw.

Iterator 0u8.. can never return a None by definition, making last on this iterator divergent.

The fact that 0u8.. cannot yield 255 at all is tracked at issue #25708. Therefore closing as a duplicate.

@nagisa nagisa closed this as completed Jun 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants