Skip to content

Suboptimal diagnostics when "&function()" in const is rejected due to interior mutability #143345

Open
@camsteffen

Description

@camsteffen

I expected to be able to write

const { &Backtrace::disabled() }

but it yields the error

error[E0492]: constants cannot refer to interior mutable data

This is surprising because:

  1. A disabled Backtrace is an empty enum variant without interior mutable data.
  2. The error refers to a library implementation detail which is a bit confusing.
  3. This seems like something I ought to be able to do.

Although there is an easy workaround which is to use a static.

Rust version: 1.88.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions