Skip to content

E0493 emitted without drop when destructuring #86897

Open
@CAD97

Description

@CAD97

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-destructorsArea: Destructors (`Drop`, …)A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions