Suboptimal diagnostics when "&function()" in const is rejected due to interior mutability
Open
Nobody has claimed this yet.
A-const-eval
A-diagnostics
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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:
- A disabled Backtrace is an empty enum variant without interior mutable data.
- The error refers to a library implementation detail which is a bit confusing.
- 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the reported const { &Backtrace::disabled() } case with Rust 1.88.0 and confirm the E0492 diagnostic. Trace the compiler handling for this rejection, then determine whether the intended resolution is to allow the reference or improve the diagnostic; completion should include regression coverage for the chosen behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100