Closed
Description
I am confused by the following, and I wanted to see if it is a bug or not. The following successfully compiles:
pub fn f() -> ! {
loop {}
();
}
The following without the semicolon does not:
pub fn f() -> ! {
loop {}
() // ERROR: expected ! found unit type
}
I expected to see this happen:
My understanding is that the type of a block expression without a final expression is ()
, so I would expect these to both be the same — probably both should error, since I would expect both have the type ()
as the final expression. If not, can someone explain how the types resolve here?
Note: This was changed in #45880 (I think) where before that both were accepted.
Meta
rustc 1.54.0-nightly (ff2c947 2021-05-25)