Skip to content

Silent overflow on debug beta/nightly #36110

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

Closed
talchas opened this issue Aug 29, 2016 · 12 comments
Closed

Silent overflow on debug beta/nightly #36110

talchas opened this issue Aug 29, 2016 · 12 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@talchas
Copy link

talchas commented Aug 29, 2016

The standard wishlist

fn main() {
    let mut it = 255u8..;
    println!("{:?}", it.next());
}

no longer panics, but AFAICT from the code this is not due to any deliberate change. The Iterator implementation is start.add_one()/swap, and add_one() is self + 1. This sounds like some overflow checks are being lost somehow.

@TimNN
Copy link
Contributor

TimNN commented Aug 29, 2016

related: #35589

@durka
Copy link
Contributor

durka commented Aug 31, 2016

This was indeed caused by MIR:

seas779:cargo-script alex$ RUSTFLAGS=-Zorbit=off mr ru nightly-2016-08-23 cargo script --force --use-shared-binary-cache no --debug -e '(255u8..).next()'
   Compiling expr v0.1.0 (file:///Users/alex/.multirust/toolchains/nightly-2016-08-23/cargo/.cargo/script-cache/expr-24db503e5185c33f)
    Finished debug [unoptimized + debuginfo] target(s) in 0.41 secs
thread 'main' panicked at 'attempt to add with overflow', ../src/libcore/iter/range.rs:103
note: Run with `RUST_BACKTRACE=1` for a backtrace.
seas779:cargo-script alex$ RUSTFLAGS=-Zorbit=on mr ru nightly-2016-08-23 cargo script --force --use-shared-binary-cache no --debug -e '(255u8..).next()'
   Compiling expr v0.1.0 (file:///Users/alex/.multirust/toolchains/nightly-2016-08-23/cargo/.cargo/script-cache/expr-24db503e5185c33f)
    Finished debug [unoptimized + debuginfo] target(s) in 0.39 secs
Some(255)

cc @eddyb

@eddyb
Copy link
Member

eddyb commented Aug 31, 2016

Missing #[rustc_inherit_overflow_checks] on the Step methods that do arithmetic (add_one and sub_one), introduced in #34530.

@eddyb eddyb added A-libs E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Aug 31, 2016
@ashrwin
Copy link

ashrwin commented Sep 1, 2016

Can I work on this ?

@eddyb
Copy link
Member

eddyb commented Sep 1, 2016

@ashrko619 Sure! The only change needed here is adding #[rustc_inherit_overflow_checks] before those 2 methods in all 3 implementations of Step and writing a test (not sure if it can be #[test] - cc @rust-lang/libs).

@ashrwin
Copy link

ashrwin commented Sep 1, 2016

@eddyb Thanks. About the test - why shouldn't it be #[test] ?

@eddyb
Copy link
Member

eddyb commented Sep 1, 2016

I don't know where we can put a #[test] for this, that's all. Also, it's dependent on having it in a separate crate, so #[test] might invalidate that requirement (i.e. it would have a local copy of Step).

However, it looks like libcoretest has the tests and it's a separate crate, so you should be able to add a test in that file.

@matthew-piziak
Copy link
Contributor

@ashrko619 Any update on this issue? If not I might like to work on it.

@ashrwin
Copy link

ashrwin commented Sep 11, 2016

@matthew-piziak Feel free to work on it. I have been caught up at work this week :)

bors added a commit that referenced this issue Nov 7, 2016
fix silent overflows on `Step` impls

Part of #36110

r? @eddyb
@cramertj
Copy link
Member

@matthew-piziak Is issue fixed? I noticed your PR said "part of"-- is there more that needs to be done?

@matthew-piziak
Copy link
Contributor

@cramertj I think we're done here. The "part of" idiom is just to identify the parent of the PR.

@talchas @eddyb What still needs to be done for this issue, if anything?

@brson
Copy link
Contributor

brson commented Feb 24, 2017

Closing per @matthew-piziak !

@brson brson closed this as completed Feb 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

8 participants