After reading through https://doc.rust-lang.org/book/ch19-04-advanced-types.html and coming across !
I decided to tinker around with it.
fn bar() -> ! {
loop {}
}
It makes sense to me that this compiles and without warning. The function never returns so the return type can never have a value.
fn bar() -> i64 {
loop {}
1
}
With this, I get an unreachable expression warning. I guess I understand that the return type is allowed because, if the expression were to be reached, it would match the return type.
fn bar() -> () {
loop {}
}
This is the same as the first code block except for the return type, and compiles the same, without warning. Here, I'm confused. The compiler agrees with the return type of !
and ()
. To me, this example is similar to the i64
example in that ()
could be returned if it were reached.
Is the lack of a warning here an inaccuracy by the compiler?