Open
Description
I tried this code:
fn predicate() -> bool {
unsafe { std::str::from_utf8_unchecked(&[65]) } == "A"
}
fn main() {}
I expected to see this happen: compilation succeeds.
Instead, this happened: two errors are emitted.
error: expected expression, found `==`
--> src/main.rs:2:49
|
2 | unsafe { std::str::from_utf8_unchecked(&[65]) } == "A"
| ^^ expected expression
error[E0308]: mismatched types
--> src/main.rs:2:10
|
2 | unsafe { std::str::from_utf8_unchecked(&[65]) } == "A"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: consider using a semicolon here: `;`
| |
| expected `()`, found `&str`
Meta
rustc --version --verbose
:
rustc 1.63.0-nightly (ca122c7eb 2022-06-13)
binary: rustc
commit-hash: ca122c7ebb3ab50149c9d3d24ddb59c252b32272
commit-date: 2022-06-13
host: x86_64-pc-windows-msvc
release: 1.63.0-nightly
LLVM version: 14.0.5
Even though I know that I can simply wrap the entire unsafe
block with parentheses, but this still doesn't seem right when an if
block can be combined with boolean expressions in a similar fashion:
if true && if true { true } else { false } { }
I know that the if
case seem to be very spaghetti, but I feel like unsafe
blocks should exhibit this same behaviour during compilation.