From 03df73e7472e69b22909b5493b2250cc424486a7 Mon Sep 17 00:00:00 2001 From: Frances Wingerter <91758128+fw-immunant@users.noreply.github.com> Date: Tue, 6 May 2025 15:55:05 +0000 Subject: [PATCH] unsafe: mutable-static: do not create reference (#2736) `println!` adds references (&) to its arguments, to avoid moving them. This is undesirable here, because it is extremely error-prone to take references to `static mut`s. We could `println!("{}", {counter})`, but this is somewhat exotic syntax and just sticking with `dbg!` also avoids this problem as it does not add references. --- src/unsafe-rust/mutable-static.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unsafe-rust/mutable-static.md b/src/unsafe-rust/mutable-static.md index 1d3e7baa..31ec9bad 100644 --- a/src/unsafe-rust/mutable-static.md +++ b/src/unsafe-rust/mutable-static.md @@ -32,7 +32,7 @@ fn main() { // SAFETY: There are no other threads which could be accessing `COUNTER`. unsafe { - println!("COUNTER: {COUNTER}"); + dbg!(COUNTER); } } ```