Skip to content

Function pointer signature containing &mut T should work in const context #114994

Closed
@nayeemrmn

Description

@nayeemrmn

Proposing to extract this from #57349.

The following examples shouldn't error:

const fn get_some_fn() -> fn(&mut String) {
  String::clear
}

const fn use_const_fn(_f: fn(&mut String)) {
  ()
}

const fn some_const_fn() {
  let _f: fn(&mut String) = String::clear;
}

// mutable references are not allowed in constant functions      x3

While this has been considered part of #57349 for a while, it's also been acknowledged as a bug and suggested by @RalfJung to address separately ahead of stabilizing const_mut_refs. Indeed it's surprising for users that this would count as handling a mutable reference in const contexts.

See:
#57349 (comment)
#57349 (comment)

Metadata

Metadata

Assignees

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions