Skip to content

unreachable_code lint falsely warns entire function body is unreachable #149042

Closed

Description

@phos-fir

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

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Nov 17, 2025
  2. ryanavella commented on Nov 17, 2025

    @ryanavella

    The lint also fires for match block_on(join(a, b)) {} despite the exhaustive match on the uninhabited type.

  3. clubby789 commented on Nov 17, 2025

    @clubby789
    Contributor

    searched nightlies: from nightly-2025-08-01 to nightly-2025-10-16
    regressed nightly: nightly-2025-10-13
    searched commit range: be0ade2...2300c2a
    regressed commit: ff6dc92

    bisected with cargo-bisect-rustc v0.6.11

    Host triple: x86_64-unknown-linux-gnu
    Reproduce with:

    cargo bisect-rustc --start=2025-08-01 --end=2025-10-16 
    Minimized:
    //@ edition: 2024
    enum Never {}
    
    fn make_never() -> Never {
        loop {}
    }
    
    fn check() -> () {
        make_never();
    }
    
    fn main() {
        check();
    }
  4. clubby789 commented on Nov 17, 2025

    @clubby789
    Contributor

    #142390 cc @cjgillot - I guess the warning is correct but the 'unreachable expression' span is wrong. Seems like it's using the span of the implicit _0 = const () return value assignment, which is that of the whole function

  5. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Nov 18, 2025
  6. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    on Nov 18, 2025
  7. added a commit that references this issue on Nov 22, 2025
    af17d59
  8. added 3 commits that reference this issue on Nov 24, 2025
    4c7c89d
    3cc08ff
    0448705
  9. added
    P-highHigh priority
    and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Dec 4, 2025
  10. added 2 commits that reference this issue on Dec 10, 2025
    175e932
    652e54c
  11. added a commit that references this issue on Dec 29, 2025
    676f2da
  12. added a commit that references this issue on Jan 1, 2026
    c638484
  13. added a commit that references this issue on Mar 19, 2026
    89a7582
  14. added a commit that references this issue on Mar 27, 2026
    40347c3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.L-unreachable_codeLint: unreachable_codeP-highHigh priorityT-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