Skip to content
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

Merged
merged 6 commits into from
Jan 7, 2019
Merged

cast_ref_to_mut lint #3600

merged 6 commits into from
Jan 7, 2019

Conversation

KamilaBorowska
Copy link
Contributor

@KamilaBorowska KamilaBorowska commented Dec 29, 2018

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.

  • 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.

@KamilaBorowska KamilaBorowska force-pushed the cast-ref-to-mut branch 4 times, most recently from 15dc75f to cabac56 Compare December 29, 2018 22:42
@phansch phansch added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Dec 30, 2018
@KamilaBorowska
Copy link
Contributor Author

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); }
}

@bors
Copy link
Contributor

bors commented Jan 3, 2019

☔ The latest upstream changes (presumably #3603) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented Jan 5, 2019

☔ The latest upstream changes (presumably #3635) made this pull request unmergeable. Please resolve the merge conflicts.

@flip1995
Copy link
Member

flip1995 commented Jan 7, 2019

I'd approve this. Only two questions left:

  • Do you think this lint should stay in the nursery group? Isn't it ready for the correctness group?
  • Can you squash these merge commits? (kind of also my fault, because it took me so long to review, sorry about that. Thanks for keeping this up with the master branch!)

@KamilaBorowska
Copy link
Contributor Author

Sure.

@KamilaBorowska
Copy link
Contributor Author

Isn't it ready for the correctness group?

It probably is, but I wanted to be safe.

@flip1995
Copy link
Member

flip1995 commented Jan 7, 2019

@bors r+ Thanks!

@phansch
Copy link
Member

phansch commented Jan 7, 2019

@bors retry (bors seems to have been down for a bit)

@phansch
Copy link
Member

phansch commented Jan 7, 2019

@bors r=flip1995

@bors
Copy link
Contributor

bors commented Jan 7, 2019

📌 Commit 27ea638 has been approved by flip1995

@bors
Copy link
Contributor

bors commented Jan 7, 2019

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Contributor

bors commented Jan 7, 2019

📌 Commit 27ea638 has been approved by flip1995

@bors
Copy link
Contributor

bors commented Jan 7, 2019

⌛ Testing commit 27ea638 with merge 140c165...

bors added a commit that referenced this pull request Jan 7, 2019
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.
@bors
Copy link
Contributor

bors commented Jan 7, 2019

☀️ Test successful - status-appveyor, status-travis
Approved by: flip1995
Pushing 140c165 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants