Skip to content

rust complains about "const fn" which was never declared as such #97082

Closed
@matthiaskrgr

Description

@matthiaskrgr

Given the following code:

fn f() { dbg!(); }
static A: fn() = f;
static B: () = A();

fn main() {
    println!("Hello, world!");
    B
}

The current output is:

error: function pointers are not allowed in const fn
 --> src/main.rs:3:16
  |
3 | static B: () = A();
  |                ^^^

error: could not compile `f` due to previous error

IMO it's a bit weird that rust tells me about a "const fn" since there is none in the code snippet...? 😅

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions