rust-lang / nomicon

The Dark Arts of Advanced and Unsafe Rust Programming
https://doc.rust-lang.org/nomicon/
Apache License 2.0
1.75k stars 258 forks source link

Add an explanation shared to exclusive transmute #344

Closed ramnivas closed 2 years ago

ramnivas commented 2 years ago

The current version mentions that "Transmuting an & to &mut is UB" and then the sub-bullets (passionately!) dissuades people from doing so, but without explaining a possible failure scenario. This change alludes to the fact that such transmutation will run afoul of the assumptions that the optimizer may legitimately make.

ramnivas commented 2 years ago

Context: https://users.rust-lang.org/t/unsafe-code-review-request/73105.