Closed
Description
Given the following code:
fn foo() {
unsafe {
static BAR: u32 = std::mem::transmute(0_i32);
}
}
The current output is:
Compiling playground v0.0.1 (/playground)
warning: unnecessary `unsafe` block
[--> src/lib.rs:2:5
](https://play.rust-lang.org/#) |
2 | unsafe {
| ^^^^^^ unnecessary `unsafe` block
|
= note: `#[warn(unused_unsafe)]` on by default
error[[E0133]](https://doc.rust-lang.org/stable/error-index.html#E0133): call to unsafe function is unsafe and requires unsafe function or block
[--> src/lib.rs:3:27
](https://play.rust-lang.org/#) |
3 | static BAR: u32 = std::mem::transmute(0_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
For more information about this error, try `rustc --explain E0133`.
warning: `playground` (lib) generated 1 warning
error: could not compile `playground` due to previous error; 1 warning emitted
Ideally the output should look like:
It could suggest moving the unsafe block:
static BAR: u32 = unsafe { std::mem::transmute(0_i32) };
^^^^^^
Or perhaps this should be valid? It is inside an unsafe block after all.