Skip to content

PhantomData<fn()> is unstable in const fn #69459

Closed
@WaffleLapkin

Description

@WaffleLapkin

I tried this code:

use core::marker::PhantomData;

const fn test() {
    let _: PhantomData<fn()> = PhantomData;
}

(playground)

I expected it to work, but it doesn't work.

Error:

error[E0723]: function pointers in const fn are unstable
 --> src/lib.rs:4:32
  |
4 |     let _: PhantomData<fn()> = PhantomData;
  |                                ^^^^^^^^^^^
  |
  = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
  = help: add `#![feature(const_fn)]` to the crate attributes to enable

I use PhantomData<fn(T) -> T> to make type invariant over T & mark that I don't own T. I see no reason for this code to be unstable.

Meta

rustc --version --verbose:

rustc 1.43.0-nightly (433aae93e 2020-02-14)
binary: rustc
commit-hash: 433aae93e4ef866a1fdfefad136b32ed89acd3e7
commit-date: 2020-02-14
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions