Skip to content

unreachable_code lint falsely warns entire function body is unreachable #149042

@Qwanve

Description

@Qwanve

Code

extern crate futures;
use futures::executor::block_on;
use futures::future::join;

fn test() {
    let a = async {};

    let b = async { loop {} };

    block_on(join(a, b));
}

Current output

warning: unreachable expression
  --> src/lib.rs:5:11
   |
 5 |   fn test() {
   |  ___________^
 6 | |     let a = async {};
 7 | |
 8 | |     let b = async { loop {} };
 9 | |
10 | |     block_on(join(a, b));
   | |     -------------------- any code following this expression is unreachable
11 | | }
   | |_^ unreachable expression
   |
note: this expression has type `((), !)`, which is uninhabited
  --> src/lib.rs:10:5
   |
10 |     block_on(join(a, b));
   |     ^^^^^^^^^^^^^^^^^^^^
   = note: `#[warn(unreachable_code)]` (part of `#[warn(unused)]`) on by default

Desired output

Rationale and extra context

I don't think this lint should trigger at all in this case, since it's the last expression in the function. It doesn't trigger in the same way if there is anything after it, and the block_on and join seem to be load bearing.

Other cases

Rust Version

Nightly:
> rustc --version --verbose
rustc 1.93.0-nightly (518b42830 2025-11-16)
binary: rustc
commit-hash: 518b428304e0008859cb1fd81d1ac20efb2a064a
commit-date: 2025-11-16
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.5

Beta:
> rustc --version --verbose
rustc 1.92.0-beta.3 (f3f12444a 2025-11-09)
binary: rustc
commit-hash: f3f12444a017add0468f683f3a10656d29438a05
commit-date: 2025-11-09
host: x86_64-unknown-linux-gnu
release: 1.92.0-beta.3
LLVM version: 21.1.3

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.I-prioritizeIssue: Indicates that prioritization has been requested for this issue.L-unreachable_codeLint: unreachable_codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions