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:
parent
384b892092
commit
03df73e747
@ -32,7 +32,7 @@ fn main() {
|
||||
|
||||
// SAFETY: There are no other threads which could be accessing `COUNTER`.
|
||||
unsafe {
|
||||
println!("COUNTER: {COUNTER}");
|
||||
dbg!(COUNTER);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user