Skip to content

warn(unreachable_code) on empty error enums #476

@Kyuuhachi

Description

@Kyuuhachi

Using an empty enum as source produces an unreachable_code warning. Which is certainly true, but should it do that? Sometimes you want to return a Result for forward compatibility or whatever.

use snafu::ResultExt as _;

#[derive(Debug, snafu::Snafu)]
enum Outer {
	Inner { source: Inner },
}

#[derive(Debug, snafu::Snafu)]
enum Inner {}

fn infallible() -> Result<(), Inner> {
	Ok(())
}

fn main() -> Result<(), Outer> {
	infallible().context(InnerSnafu)
}
warning: unreachable expression
 --> src/main.rs:3:17
  |
3 | #[derive(Debug, snafu::Snafu)]
  |                 ^^^^^^^^^^^^
  |                 |
  |                 unreachable expression
  |                 any code following this expression is unreachable
  |
note: this expression has type `Inner`, which is uninhabited
 --> src/main.rs:3:17
  |
3 | #[derive(Debug, snafu::Snafu)]
  |                 ^^^^^^^^^^^^
  = note: `#[warn(unreachable_code)]` on by default
  = note: this warning originates in the derive macro `snafu::Snafu` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: `snafu-unreachable` (bin "snafu-unreachable") generated 1 warning

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions