rust-clippy
rust-clippy copied to clipboard
`[missing_const_for_fn]` is triggered when a function uses a `Drop` parameter
Summary
The lint says that the function below could be made into a const fn
. Following this suggestion results in a compiler error, which points at x and says, "destructors cannot be evaluated at compile-time"
Lint Name
[`missing_const_for_fn`]
Reproducer
I tried this code:
#![allow(clippy::all)]
#![allow(dead_code)]
#![warn(clippy::missing_const_for_fn)]
fn foo(x: Box<usize>) -> usize {
*x + 5
}
I saw this happen:
Checking playground v0.0.1 (/playground)
warning: this could be a `const fn`
--> src/lib.rs:5:1
|
5 | / fn foo(x: Box<usize>) -> usize {
6 | | *x + 5
7 | | }
| |_^
|
note: the lint level is defined here
--> src/lib.rs:3:9
|
3 | #![warn(clippy::missing_const_for_fn)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn
warning: `playground` (lib) generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.36s
I expected to see this happen: No output
Version
rustc 1.64.0-nightly (f8588549c 2022-07-18)
PS C:\Users\epice\Projects\lunars> rustc -Vv
rustc 1.64.0-nightly (f8588549c 2022-07-18)
binary: rustc
commit-hash: f8588549c3c3d45c32b404210cada01e2a45def3
commit-date: 2022-07-18
host: x86_64-pc-windows-msvc
release: 1.64.0-nightly
LLVM version: 14.0.6
Additional Labels
@rustbot label +I-suggestion-causes-error