Skip to content

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

Closed
@matthiaskrgr

Description

@matthiaskrgr

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions