-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cast_ref_to_mut lint #3600
cast_ref_to_mut lint #3600
Conversation
15dc75f
to
cabac56
Compare
Okay, added the new error message "casting &T to &mut T may cause undefined behaviour, consider instead using an UnsafeCell". This matches the error message when using the following in rustc: fn main() {
unsafe { std::mem::transmute::<&i32, &mut i32>(&3); }
} |
☔ The latest upstream changes (presumably #3603) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #3635) made this pull request unmergeable. Please resolve the merge conflicts. |
d0b3616
to
df090fe
Compare
I'd approve this. Only two questions left:
|
This matches mem::transmute::<&T, &mut T> lint in rustc.
df090fe
to
21d3045
Compare
Sure. |
It probably is, but I wanted to be safe. |
@bors r+ Thanks! |
@bors retry (bors seems to have been down for a bit) |
@bors r=flip1995 |
📌 Commit 27ea638 has been approved by |
💡 This pull request was already approved, no need to approve it again.
|
📌 Commit 27ea638 has been approved by |
cast_ref_to_mut lint I see this pattern way too often, and it's completely wrong. In fact, due to how common this incorrect pattern is, [the Rustonomicon specifically points this out](https://doc.rust-lang.org/nomicon/transmutes.html). > - Transmuting an & to &mut is UB > - Transmuting an & to &mut is always UB > - No you can't do it > - No you're not special This is my first lint.
☀️ Test successful - status-appveyor, status-travis |
I see this pattern way too often, and it's completely wrong. In fact, due to how common this incorrect pattern is, the Rustonomicon specifically points this out.
This is my first lint.