Skip to content

FP missing-const-for-fn: `the destructor for this type cannot be evaluated in constant functions #13013

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
matthiaskrgr opened this issue Jun 28, 2024 · 4 comments
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jun 28, 2024

Summary

.

Reproducer

I tried this code:

use std::cell::Cell;

const NONE_CELL_STRING: Option<Cell<String>> = None;

fn a() { // clippy suggests this to be const
    let _: &'static Option<Cell<String>> = &NONE_CELL_STRING;
}

I expected to see this happen:

Instead, this happened:

error[E0493]: destructor of `std::option::Option<std::cell::Cell<std::string::String>>` cannot be evaluated at compile-time
 --> a.rs:6:45
  |
6 |     let _: &'static Option<Cell<String>> = &NONE_CELL_STRING;
  |                                             ^^^^^^^^^^^^^^^^ the destructor for this type cannot be evaluated in constant functions
7 | }
  | - value is dropped here

Version

rustc 1.81.0-nightly (9c3bc805d 2024-06-27)
binary: rustc
commit-hash: 9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9
commit-date: 2024-06-27
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

Additional Labels

No response

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jun 28, 2024
@J-ZhengLi
Copy link
Member

@rustbot claim

@blyxyas
Copy link
Member

blyxyas commented Jul 8, 2024

Not related to the lint, but I just an idea I had: Wouldn't this type of FP be solved by re-evaluating the expression recursively after the change?

@J-ZhengLi
Copy link
Member

Not related to the lint, but I just an idea I had: Wouldn't this type of FP be solved by re-evaluating the expression recursively after the change?

Wouldn't that be the key to all suggestion-causes-error?

@blyxyas
Copy link
Member

blyxyas commented Jul 10, 2024

Yes, it would be the solution. But it's waaaaay faster to do some extra processing before emitting a suggestion than to reevaluate the whole expression (and then evaluate its parent, and its parent's parent, all the way to the root)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

No branches or pull requests

3 participants