rust-lang / rust-lang/rust-clippy
`missing_const_for_fn` disagrees with rustc on `const` inherent impls
@Kokoro2336 is already working on this.
Since May 1, 2026.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.