Skip to content

Misleading unreachable code warning from return in try blocks #54165

Closed
@scottmcm

Description

@scottmcm
#![feature(try_blocks)]

fn first_some() -> Option<()> {
    let _: Option<_> = try { return Some(foo()?) };
    let _: Option<_> = try { return Some(bar()?) };
    None
}

https://play.rust-lang.org/?gist=363157c898e0d067260e711db131b256&version=nightly&edition=2018

warning: unreachable expression
 --> src/main.rs:4:30
  |
4 |     let _: Option<_> = try { return Some(foo()?) };
  |                              ^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unreachable_code)] on by default

warning: unreachable expression
 --> src/main.rs:5:30
  |
5 |     let _: Option<_> = try { return Some(bar()?) };
  |                              ^^^^^^^^^^^^^^^^^^^

The desugar should probably just suppress this warning for the code it generates.

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.F-try_blocks`#![feature(try_blocks)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions