-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Do not automatically DerefMut ManuallyDrop through union references #151920
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
base: main
Are you sure you want to change the base?
Do not automatically DerefMut ManuallyDrop through union references #151920
Conversation
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
|
Hm. Well, that build failure isn't wrong... the |
|
That said, reading the motivating Potential pitfalls around Not sure who needs to be brought in on resolving this? @RalfJung (as author of the RFC and current implementation), can you point me the right way or ping the relevant team? |
|
I lost all context for this.^^ Can you summarize what the problem is? |
|
On reflection, I'm not sure that there's an issue here after all. The reporting issue cited the following discrepancy: use std::mem::ManuallyDrop;
union U {
x: (),
f: ManuallyDrop<(Vec<u8>,)>,
}
fn main() {
let mut u = U { x: () };
// Errors about the implicit deref of the ManuallyDrop
unsafe { u.f.0 = Vec::new() };
// equivalent to (*u.f).0
let r = &mut u;
// implicitly derefs the ManuallyDrop but does not error
unsafe { r.f.0 = Vec::new() };
// equivalent to (*(*r).f).0
}The reason for the error is that assignment might cause a drop handler to execute on an uninitialised value. But, if I (now) understand correctly, the error in the former case is necessary because the If consistency is required, then perhaps the error should be suppressed in the former case when it's already in an Feel free to close if there's nothing more here. |
|
I'm not sure I follow -- the assignment is unsafe either way precisely because the destructor gets called. Can you explain what smallvec does and why it triggers your version of the lint? |
Extends #75584 to situations where the union itself is accessed through a reference.
Fixes #141621
r? compiler