Skip to content

missing-const-for-fn false positives incoming #14020

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

Closed
matthiaskrgr opened this issue Jan 17, 2025 · 2 comments · Fixed by #14294
Closed

missing-const-for-fn false positives incoming #14020

matthiaskrgr opened this issue Jan 17, 2025 · 2 comments · Fixed by #14294
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

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jan 17, 2025

Summary

A change in the rust compiler rust-lang/rust#135541 caused clippy to issue a bunch of false positives for missing-const-for-fn for traits that are unstably const.

This is not yet reproducible with clippy inside the repo until the next sync happens.

rust-lang/rust#135541 (comment)

Lint Name

missing-const-for-fn false

Reproducer

I tried this code:

use std::ops::Add;

fn f<T: Add>(a: T, b: T) -> <T as Add>::Output {
    a + b
}

fn main() {
    println!("a + b is {}", f::<f32>(100f32, 200f32));
}

I saw this happen:

warning: this could be a `const fn`
 --> ./tests/ui/issues/issue-22258.rs:4:1
  |
4 | / fn f<T: Add>(a: T, b: T) -> <T as Add>::Output {
5 | |     a + b
6 | | }
  | |_^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn
  = note: requested on the command line with `-W clippy::missing-const-for-fn`
help: make the function `const`
  |
4 | const fn f<T: Add>(a: T, b: T) -> <T as Add>::Output {
  | +++++

I expected to see this happen:

the suggested code will not compile

Version

rustc 1.86.0-nightly (99db2737c 2025-01-16)
binary: rustc
commit-hash: 99db2737c91d1e4b36b2ffc17dcda5878bcae625
commit-date: 2025-01-16
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7

Additional Labels

No response

@profetia
Copy link
Contributor

Looks like it is reproducible in clippy now, I will take a look. I'm not very familiar to this const trait thing, do you expect clippy to silence on unstable ones?

@profetia
Copy link
Contributor

@rustbot claim

@yhx-12243 yhx-12243 marked this as a duplicate of #14013 Feb 26, 2025
github-merge-queue bot pushed a commit that referenced this issue Mar 20, 2025
Closes #14020
Closes #14290
Closes #14091

Add checks for unstable const traits.

changelog: [`missing_const_for_fn`] fix FP on unstable const traits
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

Successfully merging a pull request may close this issue.

2 participants