-
Notifications
You must be signed in to change notification settings - Fork 13k
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
MIRI disagree with the documentation of ptr::drop_in_place
#112015
Comments
Neither function has a "real" Rust implementation, but it does seem like their internal instantiation occurs in different places within the compiler. Probably this is related to that in some way. |
Yeah the documentation is imprecise and conservative. It mostly wants to make sure people don't cause UB.^^ So we document the safety constraint as equivalent to This is a somewhat dubious use of "semantically equivalent" -- basically the equivalence is a library-level spec and what you are doing causes library UB, but currently does not cause language UB. The library might change in a way that it can become language UB in the future. |
Also the claim "This is semantically equivalent to calling ptr::read and discarding the result" is definitely wrong for pinned types, where it is important that we do the drop in-place. It might be better to just remove this sentence. EDI: Actually that part is spelled out in the docs. |
Rollup merge of rust-lang#125739 - RalfJung:drop-in-place-docs, r=workingjubilee drop_in_place: weaken the claim of equivalence with drop(ptr.read()) The two are *not* semantically equivalent in all cases, so let's not be so definite about this. Fixes rust-lang#112015
drop_in_place: weaken the claim of equivalence with drop(ptr.read()) The two are *not* semantically equivalent in all cases, so let's not be so definite about this. Fixes rust-lang/rust#112015
Location
https://doc.rust-lang.org/stable/std/ptr/fn.drop_in_place.html
Summary
The documentation for
ptr::drop_in_place
claims that:However when tested in a playground MIRI complained about the use of
ptr::read
but not ofptr::drop_in_place
: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=c3dfe878ef015b93f051785b67239752Although the
ptr::drop_in_place
documentation lists a bunch of cases where they differ, none of them seems to apply to this one.Some details of the reproduction:
#[may_dangle]
both because the issue derived from this user.rust-lang.com thread on#[may_dangle]
and because I didn't find a quicker way to create a dangling reference. However this doesn't seem fundamental to the issue and likely is not required.The text was updated successfully, but these errors were encountered: