Skip to content
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

[missing_const_for_fn] is triggered when a function uses a Drop parameter #9271

Closed
botahamec opened this issue Aug 1, 2022 · 4 comments
Closed
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

@botahamec
Copy link
Contributor

botahamec commented Aug 1, 2022

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

@botahamec botahamec added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Aug 1, 2022
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Aug 1, 2022
@satvikpendem
Copy link

satvikpendem commented Aug 24, 2022

I get this often for some basic String conversion methods I have, so I have to do this each time:

#[allow(clippy::missing_const_for_fn)]
pub fn into_inner(self) -> String {
    self.0
}

Looks like this is related to this issue on the rust repository: rust-lang/rust#60964

FreezyLemon added a commit to FreezyLemon/yuvxyb that referenced this issue Nov 23, 2022
shssoichiro pushed a commit to rust-av/yuvxyb that referenced this issue Dec 8, 2022
* separate structs out into files

* no direct access to modules

* fix a clippy error

* lots of clippy warnings

* add `into_data()`

* make Yuv fields not crate-public

* remove doc(hidden) and turn modules not-public

* rustfmt

* Allow clippy::missing_const_for_fn for into_data
See rust-lang/rust-clippy#9271, this is a bug in clippy

* fix legitimate clippy errors
@JarredAllen
Copy link
Contributor

Are there any plans to fix this false positive? Or are we just waiting for rust-lang/rust#73255 to let these functions be const? I've just hit this issue with something similar to @satvikpendem's example.

@Centri3
Copy link
Member

Centri3 commented Jul 11, 2023

@JarredAllen
Copy link
Contributor

Neat! Looking forward to when it hits stable!

@Jarcho Jarcho closed this as completed Jul 11, 2023
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

6 participants