Skip to content

inaccurate const drop error doesn't mention #![feature(const_precise_live_drops)] #79166

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

Open
meithecatte opened this issue Nov 18, 2020 · 3 comments
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-destructors Area: Destructors (`Drop`, …) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@meithecatte
Copy link
Contributor

struct Test<T>(T);

impl<T> Test<T> {
    const fn unpack(self) -> T {
        self.0
    }
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0493]: destructors cannot be evaluated at compile-time
 --> src/lib.rs:4:21
  |
4 |     const fn unpack(self) -> T {
  |                     ^^^^ constant functions cannot evaluate destructors
5 |         self.0
6 |     }
  |     - value is dropped here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0493`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.

However, no destructors are actually ran, as can be seen in the MIR output:

fn <impl at src/lib.rs:3:1: 7:2>::unpack(_1: Test<T>) -> T {
    debug self => _1;                    // in scope 0 at src/lib.rs:4:15: 4:19
    let mut _0: T;                       // return place in scope 0 at src/lib.rs:4:24: 4:25

    bb0: {
        _0 = move (_1.0: T);             // scope 0 at src/lib.rs:5:9: 5:15
        return;                          // scope 0 at src/lib.rs:6:6: 6:6
    }
}

The same effect can be observed if the field access is replaced by pattern matching, either in let or match.

@meithecatte
Copy link
Contributor Author

@rustbot modify labels: A-const-fn C-bug T-compiler

@rustbot rustbot added A-const-fn C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 18, 2020
@jonas-schievink jonas-schievink added the A-destructors Area: Destructors (`Drop`, …) label Nov 18, 2020
@meithecatte
Copy link
Contributor Author

After a source code dive (!) I found out that this is governed by the const_precise_live_drops feature flag (#73255). Perhaps it would be useful for the error to mention this feature when relevant?

@meithecatte
Copy link
Contributor Author

@rustbot modify labels: -C-bug A-diagnostics

@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints and removed C-bug Category: This is a bug. labels Nov 18, 2020
@meithecatte meithecatte changed the title rustc complains about destructors in const fn even when no destructors are ran inaccurate const drop error doesn't mention #![feature(const_precise_live_drops)] Nov 18, 2020
@jonas-schievink jonas-schievink added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label May 15, 2021
@RalfJung RalfJung added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) and removed A-const-fn labels Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-destructors Area: Destructors (`Drop`, …) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants