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 false positives incoming #14020

Open
matthiaskrgr opened this issue Jan 17, 2025 · 0 comments
Open

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

matthiaskrgr opened this issue Jan 17, 2025 · 0 comments
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

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

@matthiaskrgr matthiaskrgr 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
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

1 participant