-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Open
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code:
pub struct Wrap(String);
impl Wrap {
pub const fn into_inner(self) -> String {
self.0
}
}
The current output is:
error[E0493]: destructors cannot be evaluated at compile-time
--> src/lib.rs:4:29
|
4 | pub const fn into_inner(self) -> String {
| ^^^^ constant functions cannot evaluate destructors
5 | self.0
6 | }
| - value is dropped here
This error is clearly wrong: self
is not dropped, as it's been moved out of. In fact, no destructors are run, so this should be able to compile. If it shouldn't compile, the error should be changed to not be incorrect.
This seems to be an issue in the drop suppression when moving out field-wise; using e.g. mem::forget
works to suppress the destructor and allow the function to compile. I was unable to trick the compiler to accept the function with ManuallyDrop
, as extracting the wrapped value requires manifesting a wrapper again, which triggers E0493 "destructors cannot be evaluated at compile-time".
@rustbot label: +A-const-fn +A-destructors
mpfaff, nvzqz, trentj, TimNN and ryanavella
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-destructorsArea: Destructors (`Drop`, …)Area: Destructors (`Drop`, …)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.