Skip to content

Unexpected behaviour of const atomics #146644

@im-0

Description

@im-0

I tried this code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=139b1c685d63e315c4e7140bcfc6694f

use std::sync::atomic::{AtomicBool, Ordering};

fn main() {
    const ATOMIC_BOOL: AtomicBool = AtomicBool::new(true);
    ATOMIC_BOOL.store(false, Ordering::SeqCst);
    eprintln!("ATOMIC_BOOL == {}", ATOMIC_BOOL.load(Ordering::SeqCst));
}

I expected to see this happen:

Either fail to compile, or compile with warning, or print ATOMIC_BOOL == false

Instead, this happened:

Compiled without any warnings, output is ATOMIC_BOOL == false, which is unexpected.

Meta

rustc --version --verbose:

rustc 1.89.0 (29483883e 2025-08-04) (Fedora 1.89.0-2.fc42)
binary: rustc
commit-hash: 29483883eed69d5fb4db01964cdf2af4d86e9cb2
commit-date: 2025-08-04
host: x86_64-unknown-linux-gnu
release: 1.89.0
LLVM version: 20.1.8

P.S. There is a Clippy lint about this, but I believe that it should be a rustc warning instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions