Skip to content

missing-const-for-fn : const_refs_to_cell is not stable yet #13016

@matthiaskrgr

Description

@matthiaskrgr

Summary

use std::mem::forget;

#[allow(dead_code)]
 fn test_generic_fn_forget<T>(val: T) {
    forget(&val);
    forget(val);
}

=>

warning: this could be a `const fn`
 --> a.rs:5:2
  |
5 | /  fn test_generic_fn_forget<T>(val: T) {
6 | |     forget(&val);
7 | |     forget(val);
8 | | }
  | |_^
  |
  = 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`
  |
5 |  const fn test_generic_fn_forget<T>(val: T) {

=>

error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability
 --> a.rs:5:12
  |
5 |     forget(&val);
  |            ^^^^
  |
  = note: see issue #80384 <https://github.com/rust-lang/rust/issues/80384> for more information
  = help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable
  = note: this compiler was built on 2024-06-27; consider upgrading it if it is out of date

error: aborting due to 1 previous error

Lint Name

No response

Reproducer

I tried this code:

<code>

I saw this happen:

<output>

I expected to see this happen:

Version

rustc 1.81.0-nightly (9c3bc805d 2024-06-27)
binary: rustc
commit-hash: 9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9
commit-date: 2024-06-27
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-nurseryLint: Currently in the nursery group

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions