Awaiting a function returning a never type does not warn for unreachable code after the await · Issue #128434 · rust-lang/rust (original) (raw)

Code

pub async fn endless_async() -> ! { loop { tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; } }

pub async fn should_warn() { endless_async().await; println!("This code is unreachable"); // no warning about unreachable code }

pub fn endless() -> ! { loop { std::thread::sleep(std::time::Duration::from_secs(1)); } }

pub fn warns() { endless(); println!("This code is unreachable"); // warning: unreachable statement }

Current output

warning: unreachable statement --> src/lib.rs:20:5 | 19 | endless(); | --------- any code following this expression is unreachable 20 | println!("This code is unreachable"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | = note: #[warn(unreachable_code)] on by default = note: this warning originates in the macro println (in Nightly builds, run with -Z macro-backtrace for more info)

Desired output

warning: unreachable statement --> src/lib.rs:9:5 | 8 | endless_async().await; | --------------------- any code following this expression is unreachable 9 | println!("This code is unreachable"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | = note: #[warn(unreachable_code)] on by default = note: this warning originates in the macro println (in Nightly builds, run with -Z macro-backtrace for more info) warning: unreachable statement --> src/lib.rs:20:5 | 19 | endless(); | --------- any code following this expression is unreachable 20 | println!("This code is unreachable"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | = note: #[warn(unreachable_code)] on by default = note: this warning originates in the macro println (in Nightly builds, run with -Z macro-backtrace for more info)

Rationale and extra context

No response

Other cases

No response

Rust Version

rustc 1.80.0 (051478957 2024-07-21) binary: rustc commit-hash: 051478957371ee0084a7c0913941d2a8c4757bb9 commit-date: 2024-07-21 host: x86_64-unknown-linux-gnu release: 1.80.0 LLVM version: 18.1.7

Anything else?

Same behaviour with the current nightly version:

rustc 1.82.0-nightly (f8060d282 2024-07-30)
binary: rustc
commit-hash: f8060d282d42770fadd73905e3eefb85660d3278
commit-date: 2024-07-30
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7