Skip to content

Commit 03df73e

Browse files
authored
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.
1 parent 384b892 commit 03df73e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/unsafe-rust/mutable-static.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn main() {
3232
3333
// SAFETY: There are no other threads which could be accessing `COUNTER`.
3434
unsafe {
35-
println!("COUNTER: {COUNTER}");
35+
dbg!(COUNTER);
3636
}
3737
}
3838
```

0 commit comments

Comments
 (0)