Skip to content

unreachable pattern not warned when used in sufficiently complex macro / procmacro hack #78234

Closed
rust-lang/futures-rs
#2243
@drahnr

Description

@drahnr

I tried this code:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=49f774bfbf796f141b31e716fba52820

with expansion:

https://gist.github.com/bkchr/92b754ec82efcc115637ab5533e79ff4

use futures::{future, select}; // 0.3.6

pub enum Foo {
    Bar,
    Baz,
}

/* this function does produce warnings
fn match_foo(foo: Foo) -> i32 {
    match foo {
       x => 1,
        _ => unreachable!("why you do this rust?"),
    }
}
*/

pub async fn foo(foo: Foo) {
    let mut a = future::ready(4);
    
    use Foo::Bar;
    let res = select! {
        // but this doesn't        
        a_res = a => match foo {
            Bar => 1,
            _ => 4,
            _ => unreachable!("why you do this rust?"),
        },
    };

    assert_eq!(res, 4, "oh");
}


fn main() {
    futures::executor::block_on(async move {
        foo(Foo::Baz).await
    });
}

I expected to see this happen:

Be warned about the unreachable pattern / enum variant.

Instead, this happened:

No warning was displayed despite an unreachable pattern being present.

Compiling playground v0.0.1 (/playground)
    Finished dev [unoptimized + debuginfo] target(s) in 0.79s
     Running `target/debug/playground`
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `4`: oh', src/main.rs:29:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Meta

rustc --version --verbose:

rustc 1.47.0 (18bf6b4f0 2020-10-07)
binary: rustc
commit-hash: 18bf6b4f01a6feaf7259ba7cdae58031af1b7b39
commit-date: 2020-10-07
host: x86_64-unknown-linux-gnu
release: 1.47.0
LLVM version: 11.0

Credit for example @ordian , initial finding by @coriolinus

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-patternsRelating to patterns and pattern matchingC-bugCategory: This is a bug.P-lowLow priorityT-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