Skip to content

1.92.0 warns about unreachable code, but that code can't be removed without type errors #152559

@ericseppanen

Description

@ericseppanen

I tried this code:

use std::process::ExitCode;

enum Never {}

fn never_returns() -> Never {
    todo!()
}

pub fn run() -> ExitCode {
    never_returns();
    ExitCode::FAILURE
}

And rustc raises an "unreachable expression" warning. This seems reasonable. So I remove that line:

use std::process::ExitCode;

enum Never {}

fn never_returns() -> Never {
    todo!()
}

pub fn run() -> ExitCode {
    never_returns();
}

I expected to see this happen:

  • either rustc can tell that that path is unreachable, and it should not have type errors,
  • or rustc can't tell it's unreachable, and the "unreachable expression" warning should not appear.

Instead, this happened: rustc seems to simultaneously indicate that path is unreachable, AND some expression is needed there to satisfy the type-checker.

Is there really no way to write the run function without invoking #[allow(unreachable_code)]? That seems odd. (Sorry, I shouldn't have asked. Didn't mean to nerd-snipe.)

Meta

rustc --version --verbose:

rustc 1.93.1 (01f6ddf75 2026-02-11)
binary: rustc
commit-hash: 01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf
commit-date: 2026-02-11
host: x86_64-unknown-linux-gnu
release: 1.93.1
LLVM version: 21.1.8

(Happens on any stable version >= 1.92.0; and also on nightly 2026-02-11)

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.C-bugCategory: This is a bug.L-false-positiveLint: False positive (should not have fired).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-stablePerformance or correctness regression from one stable version to another.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions