Skip to content

false positive "unreachable expression" #64103

Closed
@matthiaskrgr

Description

@matthiaskrgr
pub fn main() {
     std::process::Command::new("test").output().unwrap_or(panic!("oh no"));
}

rustc warns that the entire line is an unreachable expression

warning: unreachable expression
 --> src/main.rs:3:6
  |
3 |      std::process::Command::new("test").output().unwrap_or(panic!("oh no"));
  |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unreachable_code)] on by default

however the code is clearly executed as can be see on the playground

   Compiling playground v0.0.1 (/playground)
warning: unreachable expression
 --> src/main.rs:2:6
  |
2 |      std::process::Command::new("test").output().unwrap_or(panic!("oh no"));
  |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unreachable_code)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.60s
     Running `target/debug/playground`
thread 'main' panicked at 'oh no', src/main.rs:2:60
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

If the line was truly unreachable, there would be no panic...

This bug appears on stable, beta and nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions