Closed
Conversation
In other words, makes the language 100 times safer 🚀 🚀
Contributor
|
(rust-highfive has picked a reviewer for you, use r? to override) |
Member
|
At MIR level division by zero is UB. Explicit checks for 0 are inserted are inserted to allow it to not be UB for the surface language. // WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
fn foo(_1: u8, _2: u8) -> u8 {
debug a => _1; // in scope 0 at [src/lib.rs:1:8: 1:9](https://play.rust-lang.org/#)
debug b => _2; // in scope 0 at [src/lib.rs:1:15: 1:16](https://play.rust-lang.org/#)
let mut _0: u8; // return place in scope 0 at [src/lib.rs:1:25: 1:27](https://play.rust-lang.org/#)
let mut _3: u8; // in scope 0 at [src/lib.rs:2:5: 2:6](https://play.rust-lang.org/#)
let mut _4: u8; // in scope 0 at [src/lib.rs:2:9: 2:10](https://play.rust-lang.org/#)
let mut _5: bool; // in scope 0 at [src/lib.rs:2:5: 2:10](https://play.rust-lang.org/#)
bb0: {
_3 = _1; // scope 0 at [src/lib.rs:2:5: 2:6](https://play.rust-lang.org/#)
_4 = _2; // scope 0 at [src/lib.rs:2:9: 2:10](https://play.rust-lang.org/#)
_5 = Eq(_4, const 0_u8); // scope 0 at [src/lib.rs:2:5: 2:10](https://play.rust-lang.org/#)
assert(!move _5, "attempt to divide `{}` by zero", _3) -> bb1; // scope 0 at [src/lib.rs:2:5: 2:10](https://play.rust-lang.org/#)
}
bb1: {
_0 = Div(move _3, move _4); // scope 0 at [src/lib.rs:2:5: 2:10](https://play.rust-lang.org/#)
return; // scope 0 at [src/lib.rs:3:2: 3:2](https://play.rust-lang.org/#)
}
} |
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.