File tree 1 file changed +6
-6
lines changed
src/librustc_error_codes/error_codes
1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change 1
- A type with a ` Drop ` implementation was destructured when trying to initialize
2
- a static item.
1
+ A value with a custom ` Drop ` implementation may be dropped during const-eval.
3
2
4
3
Erroneous code example:
5
4
@@ -16,13 +15,14 @@ struct Foo {
16
15
field1: DropType,
17
16
}
18
17
19
- static FOO: Foo = Foo { ..Foo { field1: DropType::A } }; // error!
18
+ static FOO: Foo = Foo { field1: ( DropType::A, DropType::A).1 }; // error!
20
19
```
21
20
22
21
The problem here is that if the given type or one of its fields implements the
23
- ` Drop ` trait, this ` Drop ` implementation cannot be called during the static
24
- type initialization which might cause a memory leak. To prevent this issue,
25
- you need to instantiate all the static type's fields by hand.
22
+ ` Drop ` trait, this ` Drop ` implementation cannot be called within a const
23
+ context since it may run arbitrary, non-const-checked code. To prevent this
24
+ issue, ensure all values with custom a custom ` Drop ` implementation escape the
25
+ initializer.
26
26
27
27
```
28
28
enum DropType {
You can’t perform that action at this time.
0 commit comments