Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add long error explanation for E0493 #64377

Merged
merged 2 commits into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion src/librustc_mir/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,51 @@ Remember this solution is unsafe! You will have to ensure that accesses to the
cell are synchronized.
"##,

E0493: r##"
A type with a `Drop` implementation was destructured when trying to initialize
a static item.

Erroneous code example:

```compile_fail,E0493
enum DropType {
A,
}

impl Drop for DropType {
fn drop(&mut self) {}
}

struct Foo {
field1: DropType,
}

static FOO: Foo = Foo { ..Foo { field1: DropType::A } }; // error!
```

The problem here is that if the given type or one of its fields implements the
`Drop` trait, this `Drop` implementation cannot be called during the static
type initialization which might cause a memory leak. To prevent this issue,
you need to instantiate all the static type's fields by hand.

```
enum DropType {
A,
}

impl Drop for DropType {
fn drop(&mut self) {}
}

struct Foo {
field1: DropType,
}

static FOO: Foo = Foo { field1: DropType::A }; // We initialize all fields
// by hand.
```
"##,

E0499: r##"
A variable was borrowed as mutable more than once. Erroneous code example:

Expand Down Expand Up @@ -2391,7 +2436,6 @@ There are some known bugs that trigger this message.
// E0299, // mismatched types between arms
// E0471, // constant evaluation error (in pattern)
// E0385, // {} in an aliasable location
E0493, // destructors cannot be evaluated at compile-time
E0521, // borrowed data escapes outside of closure
E0524, // two closures require unique access to `..` at the same time
E0526, // shuffle indices are not constant
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/check-static-values-constraints.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,5 @@ LL | let y = { static x: Box<isize> = box 3; x };

error: aborting due to 17 previous errors

Some errors have detailed explanations: E0010, E0015, E0019, E0507.
Some errors have detailed explanations: E0010, E0015, E0019, E0493, E0507.
For more information about an error, try `rustc --explain E0010`.
1 change: 1 addition & 0 deletions src/test/ui/consts/const-eval/const_let.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ LL | const Z2: () = { let mut x; x = None; x = Some(FakeNeedsDrop); };

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0493`.
4 changes: 2 additions & 2 deletions src/test/ui/consts/min_const_fn/min_const_fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,5 @@ LL | const fn no_fn_ptrs2() -> fn() { fn foo() {} foo }

error: aborting due to 36 previous errors

Some errors have detailed explanations: E0515, E0723.
For more information about an error, try `rustc --explain E0515`.
Some errors have detailed explanations: E0493, E0515, E0723.
For more information about an error, try `rustc --explain E0493`.
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ LL | const X: Vec<u32> = Vec::new();

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0493`.
1 change: 1 addition & 0 deletions src/test/ui/span/E0493.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | const F : Foo = (Foo { a : 0 }, Foo { a : 1 }).1;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0493`.
3 changes: 2 additions & 1 deletion src/test/ui/static/static-drop-scope.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ LL | const EARLY_DROP_C_OPTION_CONSTANT: i32 = (HELPER, 0).1;

error: aborting due to 10 previous errors

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