Skip to content

Commit 30ba6fd

Browse files
authored
Rollup merge of rust-lang#64377 - GuillaumeGomez:E0493, r=estebank
Add long error explanation for E0493 Part of rust-lang#61137.
2 parents 22bc9e1 + 9f978b7 commit 30ba6fd

File tree

7 files changed

+53
-5
lines changed

7 files changed

+53
-5
lines changed

src/librustc_mir/error_codes.rs

+45-1
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,51 @@ Remember this solution is unsafe! You will have to ensure that accesses to the
11281128
cell are synchronized.
11291129
"##,
11301130

1131+
E0493: r##"
1132+
A type with a `Drop` implementation was destructured when trying to initialize
1133+
a static item.
1134+
1135+
Erroneous code example:
1136+
1137+
```compile_fail,E0493
1138+
enum DropType {
1139+
A,
1140+
}
1141+
1142+
impl Drop for DropType {
1143+
fn drop(&mut self) {}
1144+
}
1145+
1146+
struct Foo {
1147+
field1: DropType,
1148+
}
1149+
1150+
static FOO: Foo = Foo { ..Foo { field1: DropType::A } }; // error!
1151+
```
1152+
1153+
The problem here is that if the given type or one of its fields implements the
1154+
`Drop` trait, this `Drop` implementation cannot be called during the static
1155+
type initialization which might cause a memory leak. To prevent this issue,
1156+
you need to instantiate all the static type's fields by hand.
1157+
1158+
```
1159+
enum DropType {
1160+
A,
1161+
}
1162+
1163+
impl Drop for DropType {
1164+
fn drop(&mut self) {}
1165+
}
1166+
1167+
struct Foo {
1168+
field1: DropType,
1169+
}
1170+
1171+
static FOO: Foo = Foo { field1: DropType::A }; // We initialize all fields
1172+
// by hand.
1173+
```
1174+
"##,
1175+
11311176
E0499: r##"
11321177
A variable was borrowed as mutable more than once. Erroneous code example:
11331178
@@ -2454,7 +2499,6 @@ There are some known bugs that trigger this message.
24542499
// E0299, // mismatched types between arms
24552500
// E0471, // constant evaluation error (in pattern)
24562501
// E0385, // {} in an aliasable location
2457-
E0493, // destructors cannot be evaluated at compile-time
24582502
E0521, // borrowed data escapes outside of closure
24592503
E0526, // shuffle indices are not constant
24602504
E0594, // cannot assign to {}

src/test/ui/check-static-values-constraints.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,5 @@ LL | let y = { static x: Box<isize> = box 3; x };
108108

109109
error: aborting due to 17 previous errors
110110

111-
Some errors have detailed explanations: E0010, E0015, E0019, E0507.
111+
Some errors have detailed explanations: E0010, E0015, E0019, E0493, E0507.
112112
For more information about an error, try `rustc --explain E0010`.

src/test/ui/consts/const-eval/const_let.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ LL | const Z2: () = { let mut x; x = None; x = Some(FakeNeedsDrop); };
2424

2525
error: aborting due to 4 previous errors
2626

27+
For more information about this error, try `rustc --explain E0493`.

src/test/ui/consts/min_const_fn/min_const_fn.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -324,5 +324,5 @@ LL | const fn no_fn_ptrs2() -> fn() { fn foo() {} foo }
324324

325325
error: aborting due to 37 previous errors
326326

327-
Some errors have detailed explanations: E0515, E0723.
328-
For more information about an error, try `rustc --explain E0515`.
327+
Some errors have detailed explanations: E0493, E0515, E0723.
328+
For more information about an error, try `rustc --explain E0493`.

src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | const F: u32 = (U::X, 42).1;
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0493`.

src/test/ui/span/E0493.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | const F : Foo = (Foo { a : 0 }, Foo { a : 1 }).1;
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0493`.

src/test/ui/static/static-drop-scope.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,5 @@ LL | const EARLY_DROP_C_OPTION_CONSTANT: i32 = (HELPER, 0).1;
6868

6969
error: aborting due to 10 previous errors
7070

71-
For more information about this error, try `rustc --explain E0716`.
71+
Some errors have detailed explanations: E0493, E0716.
72+
For more information about an error, try `rustc --explain E0493`.

0 commit comments

Comments
 (0)