Never type - The Rust Reference (original) (raw)

The Rust Reference

[type.never]

Never type

[type.never.syntax]

Syntax
NeverType → !

NeverType !

[type.never.intro]

The never type ! is a type with no values, representing the result of computations that never complete.

[type.never.coercion]

Expressions of type ! can be coerced into any other type.

[type.never.constraint]

The ! type can only appear in function return types presently, indicating it is a diverging function that never returns.

#![allow(unused)]
fn main() {
fn foo() -> ! {
    panic!("This call never returns.");
}
}
#![allow(unused)]
fn main() {
unsafe extern "C" {
    pub safe fn no_return_extern_func() -> !;
}
}