Skip to content

LazyLock not working as expected with deref #140340

Closed
@Norlock

Description

@Norlock

I'm not sure if this is a bug inside uuid or LazyLock, but I believe LazyLock should prevent any changes without the lock being acquired.

I tried this code:

<code>
const TA: LazyLock<uuid::Uuid> = LazyLock::new(|| Uuid::new_v4());

pub fn main() {
  info!("{:?} {:?}", *TA, *TA);

}

I expected to see this happen:
Two similar UUID's

Instead, this happened:
[2025-04-26T15:38:56Z INFO splittable_be::templates] 3b9bd2f5-c2e1-433b-962e-1f662acdf5b1 c6258c4c-5bec-4ad5-a5f9-0818ec13537c

Meta

rustc --version --verbose:

rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-discussionCategory: Discussion or questions that doesn't represent real issues.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions