SilentByte / nameof

Provides a Rust macro to determine the string name of a binding, type, or function.
https://crates.io/crates/nameof
MIT License
37 stars 3 forks source link

Fails to compile with unsafe symbols #11

Open notpeelz opened 1 year ago

notpeelz commented 1 year ago

Given this code:

static mut TEST: u8 = 0;

fn main() {
    println!("{}", ::nameof::name_of!(TEST));
}

the compiler fails with this error:

error[E0133]: use of mutable static is unsafe and requires unsafe function or block
 --> src/main.rs:4:20
  |
4 |     println!("{}", ::nameof::name_of!(TEST));
  |                    ^^^^^^^^^^^^^^^^^^^^^^^^ use of mutable static
  |
  = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
  = note: this error originates in the macro `::nameof::name_of` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0133`.
error: could not compile `bug-repro-rust-nameof-unsafe` due to previous error