Error in Rust execution on official Web Page


#1

There are a code in the official principal page of Rust that I modify before Run.
The code I Run is:

// This code is editable and runnable!
fn main() {
// A simple integer calculator:
// `+` or `-` means add or subtract by 1
// `*` or `/` means multiply or divide by 2

let program = "+ + + * * - /";
let mut accumulator = 526;

for token in program.chars() {
    match token {
        '+' => accumulator += 1,
        '-' => accumulator -= 1,
        '*' => accumulator *= accumulator,
        '/' => accumulator /= 1,
        _ => { /* ignore everything else */ }
    }
}

println!("The program \"{}\" calculates the value {}",
          program, accumulator);
}

The error after run this code is:

rustc 1.16.0-beta.2 (bc15d5281 2017-02-16)
thread 'main' panicked at 'attempt to multiply with overflow', <anon>:14
stack backtrace:
1: 0x55aafddc0edc - std::sys::imp::backtrace::tracing::imp::write::h23bcdb89e70c5bbf
at /buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
2: 0x55aafddc2ece - std::panicking::default_hook::{{closure}}::he7b82439fd2d2bb6
at /buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/src/libstd/panicking.rs:351
3: 0x55aafddc2ad4 - std::panicking::default_hook::he1cd4269c1558f23
at /buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/src/libstd/panicking.rs:367
4: 0x55aafddc32ab - std::panicking::rust_panic_with_hook::h006b37e36b7c8982
at /buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/src/libstd/panicking.rs:555
5: 0x55aafddc30f4 - std::panicking::begin_panic::h043cddfdd3933cc4
at /buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/src/libstd/panicking.rs:517
6: 0x55aafddc3069 - std::panicking::begin_panic_fmt::h34e588bba6b8a2c2
at /buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/src/libstd/panicking.rs:501
7: 0x55aafddc2ff7 - rust_begin_unwind
at /buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/src/libstd/panicking.rs:477
8: 0x55aafdde8ead - core::panicking::panic_fmt::he52644573ecd78ff
at /buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/src/libcore/panicking.rs:69
9: 0x55aafdde8de4 - core::panicking::panic::hab2712470c117667
at /buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/src/libcore/panicking.rs:49
10: 0x55aafddba82d - rust_out::main::h2ca3ad78a267f4b5
at /tmp/<anon>:14
11: 0x55aafddcabfa - __rust_maybe_catch_panic
at /buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/src/libpanic_unwind/lib.rs:98
12: 0x55aafddc37b6 - std::rt::lang_start::h1ef940195e3c010e
at /buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/src/libstd/panicking.rs:436
at /buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/src/libstd/panic.rs:361
at /buildslave/rust-buildbot/slave/beta-dist-rustc-linux/build/src/libstd/rt.rs:57
13: 0x55aafddba882 - main
14: 0x7f91a3bfd82f - __libc_start_main
15: 0x55aafddb9948 - _start
16: 0x0 - <unknown>

┬┐Can anybody tell me about this error?


#2

accumulator is a 32 bit integer, and the final * operation produces a number larger than what can be stored in 32 bits. Rust checks for these kinds of overflow when compiling in debug mode.