3 ms·
https://repl.it/repls/SilverCarelessWearable https://repl.it/repls/SilverCarelessWearable error: attempt to divide by zero --> main.rs:2:16 | 2 |
by jaeh 7y ago
https://repl.it/repls/SilverCarelessWearable 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.
- gpm 7y agoThat'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&edition=2018&gist=9371c0ba9116c6d1fc33f90e2ba56a79 https://play.rust-lang.org/?version=stable&mode=release&edit...