1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-05-16 07:36:05 +02:00

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.
This commit is contained in:
Frances Wingerter 2025-05-06 15:55:05 +00:00 committed by GitHub
parent 384b892092
commit 03df73e747
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -32,7 +32,7 @@ fn main() {
// SAFETY: There are no other threads which could be accessing `COUNTER`.
unsafe {
println!("COUNTER: {COUNTER}");
dbg!(COUNTER);
}
}
```