我在一些我认为应该可以工作的东西中遇到了一些编译错误,
fn function() -> bool {
unsafe { 1 } == 1
}
这会给我带来这个错误
error: expected expression, found `==`
--> src/main.rs:9:18
|
9 | unsafe { 1 } == 1
| ^^ expected expression
error[E0308]: mismatched types
--> src/main.rs:9:14
|
9 | unsafe { 1 } == 1
| ^ expected `()`, found integer
For more information about this error, try `rustc --explain E0308`.
error: could not compile `testcon` due to 2 previous errors
我知道这有点没用,但那1
真的是一个不安全的函数.
但话说回来,这一切都运行得很好.
fn function() -> bool {
let var = unsafe { 1 };
var == 1
}
我知道也许两者都会被优化为完全相同,但我很好奇为什么