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 when const fn would require unstable features #8864

Closed
clubby789 opened this issue May 21, 2022 · 1 comment · Fixed by #12713
Closed

missing-const-for-fn when const fn would require unstable features #8864

clubby789 opened this issue May 21, 2022 · 1 comment · Fixed by #12713
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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-nursery Lint: Currently in the nursery group

Comments

@clubby789
Copy link
Contributor

clubby789 commented May 21, 2022

Summary

missing-const-for-fn warns 'this could be a const fn' on code that cannot be due to the required feature being unstable.

Lint Name

missing-const-for-fn

Reproducer

I tried this code:

pub struct Holder {
    val: *const u8
}
impl Holder {
    pub fn func(self) -> usize {
        unsafe {*self.val as usize}
    }
}

I saw this happen:

> cargo +1.54 clippy -- -W clippy::missing_const_for_fn
    Checking repro v0.1.0 (/tmp/repro)
warning: this could be a `const fn`
 --> src/lib.rs:5:5
  |
5 | /     pub fn func(self) -> usize {
6 | |         unsafe {*self.val as usize}
7 | |     }
  | |_____^
  |
  = note: requested on the command line with `-W clippy::missing-const-for-fn`

When adding the suggested const header:

> cargo +1.54 build
   Compiling repro v0.1.0 (/tmp/repro)
error[E0658]: dereferencing raw pointers in constant functions is unstable
 --> src/lib.rs:6:17
  |
6 |         unsafe {*self.val as usize}
  |                 ^^^^^^^^^
  |
  = note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information

Version

rustc 1.54.0 (a178d0322 2021-07-26)
binary: rustc
commit-hash: a178d0322ce20e33eac124758e837cbd80a6f633
commit-date: 2021-07-26
host: x86_64-unknown-linux-gnu
release: 1.54.0
LLVM version: 12.0.1

Additional Labels

@rustbot label +I-suggestion-causes-error

@clubby789 clubby789 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 21, 2022
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label May 21, 2022
@giraffate
Copy link
Contributor

This needs msrv: https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-1580-2022-01-13

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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-nursery Lint: Currently in the nursery group
Projects
None yet
4 participants