top | item 22230782

(no title)

jaeh | 6 years ago

https://repl.it/repls/SilverCarelessWearable

  error: attempt to divide by zero
   --> main.rs:2:16
    |
  2 |   let result = 1 / 0;
    |                ^^^^^
    |
    = note: #[deny(const_err)] on by default

  error: this expression will panic at runtime
   --> main.rs:2:16
    |
  2 |   let result = 1 / 0;
    |                ^^^^^ attempt to divide by zero

  error: aborting due to 2 previous errors
very simple example though, no idea what happens when that value comes via socket or file, guess that would panic! then.

discuss

order

gpm|6 years ago

That's actually just a lint that you can turn off with #[allow(const_err)], though obviously you shouldn't turn it off on a real project since it catches stupid mistakes like this.

And yep, the result is a panic, even with debug_assertions off (i.e. you make overflows wrap instead of panic).

https://play.rust-lang.org/?version=stable&mode=release&edit...