Skip to content

missing_const_for_fn triggers for derives #8854

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
CryZe opened this issue May 20, 2022 · 0 comments · Fixed by #9308
Closed

missing_const_for_fn triggers for derives #8854

CryZe opened this issue May 20, 2022 · 0 comments · Fixed by #9308
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

@CryZe
Copy link

CryZe commented May 20, 2022

Summary

missing_const_for_fn accidentally triggers for code generated by derives which you generally don't have any influence on.

Lint Name

missing_const_for_fn

Reproducer

I tried this code:

Playground

#![warn(clippy::missing_const_for_fn)]

#[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
#[repr(C)]
struct Header {
    version: u16,
    count: u16,
    storage_offset: u16,
}

I saw this happen:

warning: this could be a `const fn`
 --> src\layout\parser\font_resolving\name.rs:7:1
  |
7 | #[repr(C)]
  | ^
  |
note: the lint level is defined here
 --> src\lib.rs:6:5
  |
6 |     clippy::missing_const_for_fn,
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn

Weirdly the span is a bit different on the playground.

I expected to see this happen:

The lint shouldn't trigger. Also even if it would trigger, the span is somehow on the repr and not on the derive.

Version

rustc 1.61.0 (fe5b13d68 2022-05-18)
binary: rustc
commit-hash: fe5b13d681f25ee6474be29d748c65adcd91f69e
commit-date: 2022-05-18
host: x86_64-pc-windows-msvc
release: 1.61.0
LLVM version: 14.0.0

Additional Labels

No response

@CryZe CryZe 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 May 20, 2022
@CryZe CryZe changed the title [False Positive] missing_const_for_fn triggers for derives missing_const_for_fn triggers for derives May 20, 2022
@bors bors closed this as completed in f7e2cb4 Aug 9, 2022
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.

1 participant