-
Notifications
You must be signed in to change notification settings - Fork 59
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
Validity of ManuallyDrop, or: ManuallyDrop<Box<_>> is strange #245
Labels
A-validity
Topic: Related to validity invariants
C-open-question
Category: An open question that we should revisit
Comments
RalfJung
added
C-open-question
Category: An open question that we should revisit
A-validity
Topic: Related to validity invariants
labels
Aug 12, 2020
This was referenced Dec 26, 2020
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this issue
Sep 26, 2024
…homcc,traviscross Document subtleties of `ManuallyDrop` After seeing rust-lang#130140 and rust-lang#130141, I figured that `ManuallyDrop` needs documentation explaining its subtleties, hence this PR. See also rust-lang/unsafe-code-guidelines#245
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Sep 27, 2024
Rollup merge of rust-lang#130279 - theemathas:manually-drop-docs, r=thomcc,traviscross Document subtleties of `ManuallyDrop` After seeing rust-lang#130140 and rust-lang#130141, I figured that `ManuallyDrop` needs documentation explaining its subtleties, hence this PR. See also rust-lang/unsafe-code-guidelines#245
Of note, use std::mem::{ManuallyDrop, transmute};
fn main() {
let x = Box::new(123);
let y: &i32 = unsafe { transmute(&*x) };
let mut z = ManuallyDrop::new(y);
// Removing the following line does not affect the behavior
unsafe { ManuallyDrop::drop(&mut z); }
drop(x);
let _moved = z;
} |
Yeah, but it's less strange there since dropping |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-validity
Topic: Related to validity invariants
C-open-question
Category: An open question that we should revisit
The
ManuallyDrop
docs sayIn particular, this means that a
ManuallyDrop<Box<T>>
must not dangle. But that means that after callingdrop
on aManuallDrop<Box<T>>
, that value violates the validity invariant and must not be used or passed around any more! I don't think that is the behavior we want.We want
ManuallyDrop
to preserve niches, so we cannot really relax what it says about validity. But what we could relax is validity ofBox
-- we could say that validity is purely about the pointer value itself (it must be non-NULL and properly aligned). We could specify that the "dereferencability" only comes in through the aliasing model, and we could make that model stop looking intoManuallyDrop
.The text was updated successfully, but these errors were encountered: