rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.46k stars 12.6k forks source link

I can use never_type on stable #93807

Closed anatawa12 closed 2 years ago

anatawa12 commented 2 years ago

I tried this code:

fn main() {
    println!("Hello, world!");
    test();
}

fn test() -> ! {
    loop {};
}

According to API doc for never and [tracking issue] (B-unstable), I think never_type is not stabilized yet. However, I can use never type with stable rustc. Is it expected behavior? If never_type is already stabilized, can you document on tracking issue or rust stable book?

Meta

rustc --version --verbose:

$ rustc --version --verbose   
rustc 1.58.1 (db9d1b20b 2022-01-20)
binary: rustc
commit-hash: db9d1b20bba1968c1ec1fc49616d4742c1725b4b
commit-date: 2022-01-20
host: aarch64-apple-darwin
release: 1.58.1
LLVM version: 13.0.0
Backtrace

``` $ RUST_BACKTRACE=1 cargo build Compiling minecraft-world-backuper v0.1.0 (/Users/anatawa12/IdeaProjects/minecraft-world-backuper) Finished dev [unoptimized + debuginfo] target(s) in 0.24s ```

fmease commented 2 years ago

The never type is allowed as direct return type since at least 1.0. The Rust Reference.

bjorn3 commented 2 years ago

Using it as return type has been stable since rust 1.0, long before it was conceived as actual type. It was originally intended simply as marker of a diverging (never returning) function. Later an RFC was accepted to promote it to a regular type that can used in other contexts.