From d93d49f94a06b6317ceed0738dd5f10f811d832c Mon Sep 17 00:00:00 2001 From: Frances Wingerter Date: Mon, 5 May 2025 19:16:25 +0000 Subject: [PATCH] unsafe: mutable-static: do not create reference `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 1d3e7baaec05..31ec9baddeb1 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); } } ```