Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yeah, it's called Bottom (⊥)

    fun foo(): ⊥ {
        return foo();
    }

In Rust it's called !, and you can write

    fn will_panic() -> ! {
        panic!("uh oh");
    }
This is actually useful for some embedded systems, where the main function isn't allowed to return, and gets declared with the Nothing / Bottom / ! type.

The compiler is also smart enough to say that an infinite loop has type !, so you can have

    fn main() -> ! {
        let setup = ...;
        loop {
            blink_led();
            sleep(100);
        }
    }
and it'll complain if you put a break statement in the loop.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: