Skip to content

missing_const_for_fn disagrees with rustc on const inherent impls #16946

@ElementW

Description

@ElementW

Summary

#![feature(const_trait_impl)] has its const impl/impl const functionality extend to inherent impls as per the dedicated section on that topic in the RFC, where const implicitly gets applied to all fns within.
Denying clippy::missing_const_for_fn puts you in a no-escape situation where neither rustc nor clippy can be happy.

Lint Name

missing_const_for_fn

Reproducer

I tried this code:

#![feature(const_trait_impl)]
#![deny(clippy::missing_const_for_fn)]
const trait Bits {
    fn bits() -> usize;
}
// Issue does not apply to regular trait impls
impl const Bits for i32 {
    fn bits() -> usize {
        32
    }
}

struct Bobs;
impl const Bobs {
    fn bobs() -> usize {
        1234
    }
}

I saw this happen:

error: this could be a `const fn`
  --> src/main.rs:14:5
   |
14 | /     fn bobs() -> usize {
15 | |         1234
16 | |     }
   | |_____^
   |
   = 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
  --> src/main.rs:2:9
   |
 2 | #![deny(clippy::missing_const_for_fn)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: make the function `const`
   |
14 |     const fn bobs() -> usize {
   |     +++++

Applying Clippy's suggestion makes rustc angry:

error: redundant `const` fn marker in const impl
  --> src/main.rs:14:5
   |
13 | const impl Bobs {
   | ----- this declares all associated functions implicitly const
14 |     const fn bobs() -> usize {
   |     ^^^^^^ help: remove the `const`

Changing Bobs' impl to conditionally be const depending on a trait impl's effective constness (as below) does not change the lint result.

struct Bobs<T>(T);
impl<T: [const] Bits> const Bobs<T> {
    fn bobs() -> usize { // <-+- "this could be a `const fn`"
        1234             //   |
    }                    // <-/
    fn bats() -> usize {
        T::bits()
    }
}

I expected to see this happen:
Lint to pass, missing_const_for_fn not to apply on const inherent impls

Version

rustc 1.97.0-nightly (37d85e592 2026-04-28)
binary: rustc
commit-hash: 37d85e592f9ae5f20f7d9a9f99785246fa7298da
commit-date: 2026-04-28
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.

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
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions