You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fntest_one() -> u32{unsafe{2}}fntest_two() -> bool{let x:u32 = unsafe{2};let y:u32 = unsafe{2};
x == y
}fntest_three() -> bool{unsafe{2} == unsafe{2}}
The first two of these functions parse correctly, but the last one does not. The parser complains about seeing == after an unsafe block, and in its recovery, assumes that the unsafe block has type () instead of {integer}.
Exact output:
Compiling playground v0.0.1 (/playground)
error: expected expression, found `==`
--> src/lib.rs:12:18
|
12 | unsafe { 2 } == unsafe { 2 }
| ^^ expected expression
error[[E0308]](https://doc.rust-lang.org/nightly/error-index.html#E0308): mismatched types
|
12 | unsafe { 2 } == unsafe { 2 }
| ^ expected `()`, found integer
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to 2 previous errors
This fails on the current stable compiler and nightly, those being 1.59.0 and 2022-03-27, respectively.
I found this code when using unions:
unionTest{raw:u8,// other stuff that doesn't matter}implPartialEqforTest{fneq(&self,rhs:&Test) -> bool{unsafe{self.raw} == unsafe{ rhs.raw}}}
The text was updated successfully, but these errors were encountered:
Thanks for the report! This currently isn't a bug (AFAIK), as block-style expressions are not accepted in binary operators. I can understand how it is confusing, and the error message is not very helpful.
I'm going to close this as a duplicate of #54482 and #74854 (and others).
Example gist: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=01dfdf28913f8fe69d419dfd7472dc49
In short, take these three functions:
The first two of these functions parse correctly, but the last one does not. The parser complains about seeing
==
after an unsafe block, and in its recovery, assumes that theunsafe
block has type()
instead of{integer}
.Exact output:
This fails on the current stable compiler and nightly, those being 1.59.0 and 2022-03-27, respectively.
I found this code when using unions:
The text was updated successfully, but these errors were encountered: