-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking issue for drop_in_place #27908
Comments
Are there any plans to stabilize this? |
@nagy24 it seems your message got garbbled up? |
This won't really work with |
@arielb1 it would definitely have to be unsafe. Making the value invalid isn't necessarily a problem unless you're picturing more advanced analysis. I do kind've like the idea of a convention where invalidating ops are only exposed on raw pointers, though. |
🔔 This issue is now entering its cycle final comment period to be stabilization in 1.8 🔔 The libs team is somewhat up in the air about whether this function should take One one hand this method is only actually safe to call if you have a valid unique reference (e.g. We're curious if others have opinions! |
Is there a lint to warn about use after drop? |
Since For the choice between |
@KalitaAlexey not currently, no. @Marwes perhaps yeah, although the placement of My thinking for using a raw pointer is that if you're calling |
Why not change how |
@briansmith this isn't necessarily related to compiler optimizations, it's just replacing the old method of dropping a value by doing so via |
The libs team discussed this during triage yesterday and the conclusion was to stabilize in the |
This commit is the result of the FCPs ending for the 1.8 release cycle for both the libs and the lang suteams. The full list of changes are: Stabilized * `braced_empty_structs` * `augmented_assignments` * `str::encode_utf16` - renamed from `utf16_units` * `str::EncodeUtf16` - renamed from `Utf16Units` * `Ref::map` * `RefMut::map` * `ptr::drop_in_place` * `time::Instant` * `time::SystemTime` * `{Instant,SystemTime}::now` * `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier` * `{Instant,SystemTime}::elapsed` * Various `Add`/`Sub` impls for `Time` and `SystemTime` * `SystemTimeError` * `SystemTimeError::duration` * Various impls for `SystemTimeError` * `UNIX_EPOCH` * `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign` Deprecated * Scoped TLS (the `scoped_thread_local!` macro) * `Ref::filter_map` * `RefMut::filter_map` * `RwLockReadGuard::map` * `RwLockWriteGuard::map` * `Condvar::wait_timeout_with` Closes rust-lang#27714 Closes rust-lang#27715 Closes rust-lang#27746 Closes rust-lang#27748 Closes rust-lang#27908 Closes rust-lang#29866
This commit is the result of the FCPs ending for the 1.8 release cycle for both the libs and the lang suteams. The full list of changes are: Stabilized * `braced_empty_structs` * `augmented_assignments` * `str::encode_utf16` - renamed from `utf16_units` * `str::EncodeUtf16` - renamed from `Utf16Units` * `Ref::map` * `RefMut::map` * `ptr::drop_in_place` * `time::Instant` * `time::SystemTime` * `{Instant,SystemTime}::now` * `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier` * `{Instant,SystemTime}::elapsed` * Various `Add`/`Sub` impls for `Time` and `SystemTime` * `SystemTimeError` * `SystemTimeError::duration` * Various impls for `SystemTimeError` * `UNIX_EPOCH` * `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign` Deprecated * Scoped TLS (the `scoped_thread_local!` macro) * `Ref::filter_map` * `RefMut::filter_map` * `RwLockReadGuard::map` * `RwLockWriteGuard::map` * `Condvar::wait_timeout_with` Closes #27714 Closes #27715 Closes #27746 Closes #27748 Closes #27908 Closes #29866 Closes #28235 Closes #29720
This commit is the result of the FCPs ending for the 1.8 release cycle for both the libs and the lang suteams. The full list of changes are: Stabilized * `braced_empty_structs` * `augmented_assignments` * `str::encode_utf16` - renamed from `utf16_units` * `str::EncodeUtf16` - renamed from `Utf16Units` * `Ref::map` * `RefMut::map` * `ptr::drop_in_place` * `time::Instant` * `time::SystemTime` * `{Instant,SystemTime}::now` * `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier` * `{Instant,SystemTime}::elapsed` * Various `Add`/`Sub` impls for `Time` and `SystemTime` * `SystemTimeError` * `SystemTimeError::duration` * Various impls for `SystemTimeError` * `UNIX_EPOCH` * `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign` Deprecated * Scoped TLS (the `scoped_thread_local!` macro) * `Ref::filter_map` * `RefMut::filter_map` * `RwLockReadGuard::map` * `RwLockWriteGuard::map` * `Condvar::wait_timeout_with` Closes rust-lang#27714 Closes rust-lang#27715 Closes rust-lang#27746 Closes rust-lang#27748 Closes rust-lang#27908 Closes rust-lang#29866
This calls the "drop glue" for a given type without having to explicitly read it out onto the stack to be dropped. All types have a drop glue implementation, which involves calling the types Drop impl (if it exists), and the recursively running drop glue on its fields.
drop_in_place is both a performance improvement (in the case of e.g. Vec, it avoids ptr::reading the elements out), and a semantic necessity (in the case of DSTs, it's impossible to ptr::read the value, but the vtable always contains a drop glue impl).
It is currently exposed in the
ptr
module because it's maximally expressive to take a*mut
and because "that's what the intrinsic took" at the time it was exposed outside of std::intrinsics. It may be desirable to instead expose it inmem
to parallelmem::drop
, and require an&mut
. For most cases you probably already have an &mut anyway, and it's trivial to upgrade.The text was updated successfully, but these errors were encountered: