File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,36 @@ ecosystem that would break if we just started enforcing this now. See
59
59
[ this issue] ( https://github.com/rust-lang/rust/issues/49206 ) and the
60
60
[ PR attempting to fix this] ( https://github.com/rust-lang/rust/pull/54424/ ) .
61
61
62
+ ### ` Drop `
63
+
64
+ Values of types that manually implement ` Drop ` (or contain fields/variants that do),
65
+ can only be used as the final initialization value of a ` const ` or ` static ` item.
66
+ They may not be used as intermediate values that would be dropped before the item
67
+ were initialized. As an example:
68
+
69
+ ``` rust
70
+ struct Foo ;
71
+
72
+ impl Drop for Foo {
73
+ fn drop (& mut self ) {
74
+ println! (" foo dropped" );
75
+ }
76
+ }
77
+
78
+ const FOO : Foo = Foo ; // Ok
79
+ static FOOO : Foo = Foo ; // Ok
80
+
81
+ // Not ok, cannot run `Foo::drop` because it's not a const fn
82
+ const BAR : i32 = (Foo , 42 ). 1 ;
83
+ ```
84
+
85
+ This restriction might be lifted in the future after trait impls
86
+ may be declared ` const ` (https://github.com/rust-rfcs/const-eval/pull/8 ).
87
+
88
+ Note that in promoteds this restriction can never be lifted, because
89
+ otherwise we would silently stop calling the ` Drop ` impl at runtime and
90
+ pull it to much earlier (compile-time).
91
+
62
92
## Reading statics
63
93
64
94
Beyond values of reference type, we have to be careful that * computing* a
You can’t perform that action at this time.
0 commit comments