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

False Positive of clippy::missing_const_for_fn #14013

Open
yhx-12243 opened this issue Jan 17, 2025 · 1 comment
Open

False Positive of clippy::missing_const_for_fn #14013

yhx-12243 opened this issue Jan 17, 2025 · 1 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

Comments

@yhx-12243
Copy link

yhx-12243 commented Jan 17, 2025

Summary

The following function could not be const now:

pub fn get(x: &Arc<()>) -> &() {
    x
}

Lint Name

missing_const_for_fn

Reproducer

I tried this code:

#![warn(clippy::missing_const_for_fn)]

use std::sync::Arc;

pub fn get(x: &Arc<()>) -> &() {
    x
}

fn main() {}

I saw this happen:

warning: this could be a `const fn`
 --> 1.rs:5:1
  |
5 | / pub fn get(x: &Arc<()>) -> &() {
6 | |     x
7 | | }
  | |_^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn
note: the lint level is defined here
 --> 1.rs:1:9
  |
1 | #![warn(clippy::missing_const_for_fn)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: make the function `const`
  |
5 | pub const fn get(x: &Arc<()>) -> &() {
  |     +++++

warning: 1 warning emitted

I expected to see this happen:

<nothing> (because adding const will cause a compilation error)

Version

rustc 1.86.0-nightly (99db2737c 2025-01-16)
binary: rustc
commit-hash: 99db2737c91d1e4b36b2ffc17dcda5878bcae625
commit-date: 2025-01-16
host: aarch64-apple-darwin
release: 1.86.0-nightly
LLVM version: 19.1.7

Additional Labels

No response

@yhx-12243 yhx-12243 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 Jan 17, 2025
@alex-semenyuk
Copy link
Member

Suppose can be considered as duplication #14020

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
Projects
None yet
Development

No branches or pull requests

2 participants