Skip to content

Remove UB statement - #94013

Closed
fee1-dead wants to merge 1 commit into
rust-lang:masterfrom
fee1-dead-contrib:unub
Closed

Remove UB statement#94013
fee1-dead wants to merge 1 commit into
rust-lang:masterfrom
fee1-dead-contrib:unub

Conversation

@fee1-dead

@fee1-deadfee1-dead commented Feb 15, 2022

Copy link
Copy Markdown
Member

No description provided.

In other words, makes the language 100 times safer 🚀 🚀
@rustbotrustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 15, 2022
@rust-highfive

Copy link
Copy Markdown
Contributor

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 15, 2022
@fee1-deadfee1-dead added T-lang Relevant to the language team and removed T-lang Relevant to the language team labels Feb 15, 2022
@bjorn3

Copy link
Copy Markdown
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.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1d680261de85ff6b6e19b15d570d636c

// WARNING: This output format is intended for human consumers only// and is subject to change without notice. Knock yourself out.fnfoo(_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/#)letmut _0:u8;// return place in scope 0 at [src/lib.rs:1:25: 1:27](https://play.rust-lang.org/#)letmut _3:u8;// in scope 0 at [src/lib.rs:2:5: 2:6](https://play.rust-lang.org/#)letmut _4:u8;// in scope 0 at [src/lib.rs:2:9: 2:10](https://play.rust-lang.org/#)letmut _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,const0_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/#)}}

@fee1-dead
fee1-dead deleted the unub branch February 15, 2022 11:12
@fee1-dead
fee1-dead restored the unub branch February 15, 2022 11:16
@fee1-deadfee1-dead changed the title Remove outdated UB claims in compilerClarify confusing UB statementFeb 15, 2022
@fee1-deadfee1-dead changed the title Clarify confusing UB statementRemove UB statementFeb 15, 2022
@fee1-dead

fee1-dead commented Feb 15, 2022

Copy link
Copy Markdown
MemberAuthor

@bjorn3: Thanks for the explanation! I have #94017 up which clarifies the UB part a bit more so that it is easier to understand.

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

Labels

S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@fee1-dead@rust-highfive@bjorn3@Mark-Simulacrum@rustbot