New destructor semantics · Issue #8861 · rust-lang/rust (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Description
Tracking issue for RFC #769, Sound Generic Drop.
Original description follows:
We agreed in a meeting to replace the unsafe destructor code with the rule that a value with a destructor must only contain values of lifetime strictly greater than the value to be destructed. The idea is to prevent values from referencing one another. Permitting borrowed values in destructors enables a number of RAII causes and helps to eliminate the need for once fns. This also relies on the change to prevent &
pointers from being placed within managed boxes (which I think has already been made).
I have to figure out precisely how to formalize this rule still. =)
Nominating for backwards compat.
Update from @pnkfelix : Much of this is implemented, and so pnkfelix is listing out specific subtasks, issues, and/or PRs, to try to track what is done and what is left to do:
- Track finer-grained scopes (i.e. block suffixes): See PR Add CodeExtent::Remainder variant; pre-req for new scoping/drop rules. #21657
- Land the drop-checker ("dropck"). See PR dropck and new scoping rules for safe destruction #21972
- Keep
Drop
from adding new bounds on a type param; Issue Prohibit specialized drops #8142 - Revise for-loops so that temporaries from the
<iterator-expr>
only live for the for-loop itself. (i.e. turn for-loops into a terminating scope). Addresses the bulk Issue new scoping rules for safe dtors can yield spurious semi-colon or trailing unit expr #21114. Resolved by make for PAT in ITER_EXPR { ... } a terminating-scope for ITER_EXPR. #21984 - Remove
#[unsafe_destructor]
attribute entirely; Issue Once confident in dropck: remove #[unsafe_destructor] attribute #22196
Far future / No longer deemed necessary
- Make
Vec<T>
,Box<T>
,Rc<T>
, etc, covariant with respect toT
. Discussed on issue new scoping rules for safe dtors may benefit from variance on type params #21198 (may not be a strict requirement for landing new destructor semantics). - Track even finer grained scopes, e.g. destruction order of temporary rvalues in an expression. Issue dropck: track order of destruction for r-value temporaries #22323
(See also #22321)