Skip to content

Commit ccd4a78

Browse files
committed
Clarify collection types with non-allocating constructors, note that destructors will never run, acknowledge .dtors as alternative
1 parent 1c9c699 commit ccd4a78

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

text/0000-drop-types-in-const.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Allow types with destructors to be used in `static` items and in `const` functio
1111
# Motivation
1212
[motivation]: #motivation
1313

14-
Most collection types do not allocate any memory when constructed empty. With the change to make leaking safe, the restriction on `static` items with destructors
15-
is no longer required to be a hard error.
14+
Some of the collection types do not allocate any memory when constructed empty (most notably `Vec`). With the change to make leaking safe, the restriction on `static` items with destructors
15+
is no longer required to be a hard error (as it is safe and accepted that these destructors may never run).
1616

1717
Allowing types with destructors to be directly used in `const` functions and stored in `static`s will remove the need to have
1818
runtime-initialisation for global variables.
@@ -21,6 +21,7 @@ runtime-initialisation for global variables.
2121
[design]: #detailed-design
2222

2323
- Lift the restriction on types with destructors being used in statics.
24+
- `static`s containing Drop-types will not run the destructor upon program/thread exit.
2425
- (Optionally adding a lint that warn about the possibility of resource leak)
2526
- Alloc instantiating structures with destructors in constant expressions,
2627
- Continue to prevent `const` items from holding types with destructors.
@@ -59,8 +60,9 @@ Destructors do not run on `static` items (by design), so this can lead to unexpe
5960

6061
- Runtime initialisation of a raw pointer can be used instead (as the `lazy_static` crate currently does on stable)
6162
- On nightly, a bug related to `static` and `UnsafeCell<Option<T>>` can be used to remove the dynamic allocation.
62-
63-
Both of these alternatives require runtime initialisation, and incur a checking overhead on subsequent accesses.
63+
- Both of these alternatives require runtime initialisation, and incur a checking overhead on subsequent accesses.
64+
- Leaking of objects could be addressed by using C++-style `.dtors` support
65+
- This is undesirable, as it introduces confusion around destructor execution order.
6466

6567
# Unresolved questions
6668
[unresolved]: #unresolved-questions

0 commit comments

Comments
 (0)