Skip to content

super let in const with interior mutability has inconsistent behavior #142607

Open
@theemathas

Description

@theemathas

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.F-super_letit's super, let's go!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