primitive-type
Rust !: represent a computation that cannot return normally
The never type, written !, has no values. On the stable Rust 1.85 baseline its explicit use is supported in function return position. It describes a function that never returns normally, for example one that always panics. Expected output (not executed): 8 Why: The valid branch runs. The other branch would diverge, so its never-typed expression can coerce to the required result type. Common mistake: Do not call a diverging function expecting an ordinary return value; do not assume arbitrary uses of ! in type positions are stable.
Formal Syntax & Structure
rust syntaxrust
fn name() -> !Working Example
Example Snippetrust
fn fail() -> ! { panic!("Cannot continue") }
fn main() { let valid = true; let value: u32 = if valid { 8 } else { fail() }; println!("{value}");}