Skip to content

False-positive with the unreachable code lint #88393

Open
@bjorn3

Description

@bjorn3

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=67b068c7dded060fd71f7e5a5ca91278

#![allow(deprecated, invalid_value)]

enum Void {}

fn main() {
    if false {
        unsafe { std::mem::uninitialized::<Void>(); }
    }
    
    println!();
}

The current output is:

warning: unreachable expression
  --> src/main.rs:10:5
   |
7  |         unsafe { std::mem::uninitialized::<Void>(); }
   |                  --------------------------------- any code following this expression is unreachable
...
10 |     println!();
   |     ^^^^^^^^^^^ unreachable expression
   |
   = note: `#[warn(unreachable_code)]` on by default
note: this expression has type `Void`, which is uninhabited
  --> src/main.rs:7:18
   |
7  |         unsafe { std::mem::uninitialized::<Void>(); }
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this warning originates in the macro `$crate::format_args` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: `playground` (bin "playground") generated 1 warning

I expected no lint to trigger as the println!() is actually reachable. This problem doesn't occur for panic!().

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-unreachable_codeLint: unreachable_codeT-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