Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Awaiting a function returning a never type does not warn for unreachable code after the await #128434

Closed
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lints T-compilerRelevant to the compiler team, which will review and decide on the PR/issue. WG-asyncWorking group: Async & await
@ungrichtepfl

Description

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

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lints T-compilerRelevant to the compiler team, which will review and decide on the PR/issue. WG-asyncWorking group: Async & await

Type

No type

Projects

No projects

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /