`super let` in `const` with interior mutability has inconsistent behavior
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
#![feature(super_let)]
use std::sync::atomic::AtomicI32;
const WORKS: &Option<AtomicI32> = {
super let a: Option<AtomicI32> = None;
&a
};
const WORKS2: &Option<AtomicI32> = {
super let a: Option<AtomicI32> = None;
let x = &a;
&*x
};
const FAILS: &Option<AtomicI32> = {
super let a: Option<AtomicI32> = None;
let _x = &a;
&a
};
I expected to see this happen: Either all three constants compile, or all three fail.
Instead, this happened: Only the FAILS constant fails to compile
error[E0492]: constants cannot refer to interior mutable data
--> src/lib.rs:19:5
|
19 | &a
| ^^ this borrow of an interior mutable value may end up in the final value
For more information about this error, try `rustc --explain E0492`.
error: could not compile `playground` (lib) due to 1 previous error
See also #142229, which also involves super let in const, and issues with mutability.
Meta
Reproducible on the playground with 1.89.0-nightly (2025-06-11 e703dff8fe220b78195c)
@rustbot labels +F-super_let +A-const-eval
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
Start by compiling the provided three-constant reproducer on the noted nightly and compare the handling of WORKS, WORKS2, and FAILS, including E0492. Trace the const-evaluation and interior-mutability checks involved in super let; done means the three cases have consistent behavior and a regression test covers it.
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
- Mostly clear
- Newbie friendliness
- 38/100