Skip to content

Silent overflow on debug beta/nightly #36110

Closed
@talchas

Description

@talchas

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.

Activity

TimNN

TimNN commented on Aug 29, 2016

@TimNN
Contributor

related: #35589

durka

durka commented on Aug 31, 2016

@durka
Contributor

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

eddyb commented on Aug 31, 2016

@eddyb
Member

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

added
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
on Aug 31, 2016
ashrwin

ashrwin commented on Sep 1, 2016

@ashrwin

Can I work on this ?

eddyb

eddyb commented on Sep 1, 2016

@eddyb
Member

@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

ashrwin commented on Sep 1, 2016

@ashrwin

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

eddyb

eddyb commented on Sep 1, 2016

@eddyb
Member

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

matthew-piziak commented on Sep 9, 2016

@matthew-piziak
Contributor

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

ashrwin

ashrwin commented on Sep 11, 2016

@ashrwin

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

added a commit that references this issue on Nov 7, 2016

Auto merge of #36365 - matthew-piziak:silent-overflow, r=eddyb

4 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @durka@eddyb@brson@TimNN@talchas

        Issue actions

          Silent overflow on debug beta/nightly · Issue #36110 · rust-lang/rust