You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/0000-drop-types-in-const.md
+6-4Lines changed: 6 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -11,8 +11,8 @@ Allow types with destructors to be used in `static` items and in `const` functio
11
11
# Motivation
12
12
[motivation]: #motivation
13
13
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).
16
16
17
17
Allowing types with destructors to be directly used in `const` functions and stored in `static`s will remove the need to have
18
18
runtime-initialisation for global variables.
@@ -21,6 +21,7 @@ runtime-initialisation for global variables.
21
21
[design]: #detailed-design
22
22
23
23
- 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.
24
25
- (Optionally adding a lint that warn about the possibility of resource leak)
25
26
- Alloc instantiating structures with destructors in constant expressions,
26
27
- 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
59
60
60
61
- Runtime initialisation of a raw pointer can be used instead (as the `lazy_static` crate currently does on stable)
61
62
- 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.
0 commit comments