rust

What does the bang '!' do before an open brace '{' in Rust?


I'm reading code as part of learning Rust - I've just done Chapter 9 in The Book. I don't understand what the bang '!' is doing here:

#[inline(always)]
pub fn wait_forever() -> ! {
    loop {
        asm::wfe()
    }
}

or in several other functions in a chain that call this one.

I looked the The Rust Programming Language Operators and Symbols but I couldn't recognise it one of the entries.


Solution

  • In a function declaration the return type is specified after the -> It should be clear form the name of the function the intention is to never return. What type should such a function have?

    It's the "never" type, see https://doc.rust-lang.org/reference/types/never.html