Skip to content

cast_ref_to_mut lint#3600

Merged
bors merged 6 commits into
rust-lang:masterfrom
sugar700:cast-ref-to-mut
Jan 7, 2019
Merged

cast_ref_to_mut lint#3600
bors merged 6 commits into
rust-lang:masterfrom
sugar700:cast-ref-to-mut

Conversation

@sugar700

@sugar700 sugar700 commented Dec 29, 2018

Copy link
Copy Markdown
Contributor

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.

@sugar700
sugar700 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
Comment thread clippy_lints/src/types.rs Outdated
Comment thread clippy_lints/src/types.rs
Comment thread clippy_lints/src/types.rs Outdated
Comment thread clippy_lints/src/types.rs Outdated
@sugar700

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

bors commented Jan 3, 2019

Copy link
Copy Markdown
Contributor

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

@bors

bors commented Jan 5, 2019

Copy link
Copy Markdown
Contributor

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

@flip1995

flip1995 commented Jan 7, 2019

Copy link
Copy Markdown
Member

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!)

@sugar700

sugar700 commented Jan 7, 2019

Copy link
Copy Markdown
Contributor Author

Sure.

@sugar700

sugar700 commented Jan 7, 2019

Copy link
Copy Markdown
Contributor Author

Isn't it ready for the correctness group?

It probably is, but I wanted to be safe.

@flip1995

flip1995 commented Jan 7, 2019

Copy link
Copy Markdown
Member

@bors r+ Thanks!

@phansch

phansch commented Jan 7, 2019

Copy link
Copy Markdown
Contributor

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

@phansch

phansch commented Jan 7, 2019

Copy link
Copy Markdown
Contributor

@bors r=flip1995

@bors

bors commented Jan 7, 2019

Copy link
Copy Markdown
Contributor

📌 Commit 27ea638 has been approved by flip1995

@bors

bors commented Jan 7, 2019

Copy link
Copy Markdown
Contributor

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

@bors

bors commented Jan 7, 2019

Copy link
Copy Markdown
Contributor

📌 Commit 27ea638 has been approved by flip1995

@bors

bors commented Jan 7, 2019

Copy link
Copy Markdown
Contributor

⌛ 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

bors commented Jan 7, 2019

Copy link
Copy Markdown
Contributor

☀️ 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