Skip to content

Inconsistent "pattern doesn't bind x" messages in or patterns #39698

Description

@osa1

Compiling this using rustc nightly (tried with 29dece1 2017-02-08)

enum T {
    T1(i32),
    T2(i32),
}

fn main() {
    match T::T1(123) {
        T::T1(a) | T::T2(b) => { println!("{:?}", a); }
    }
}

prints

error[E0408]: variable `a` from pattern #1 is not bound in pattern #2
 --> pat.rs:8:20
  |
8 |         T::T1(a) | T::T2(b) => { println!("{:?}", a); }
  |                    ^^^^^^^^ pattern doesn't bind `a`

error[E0408]: variable `b` from pattern #2 is not bound in pattern #1
 --> pat.rs:8:26
  |
8 |         T::T1(a) | T::T2(b) => { println!("{:?}", a); }
  |                          ^ pattern doesn't bind `b`

This is confusing, ideally I think second error message would be


error[E0408]: variable `b` from pattern #2 is not bound in pattern #1
 --> pat.rs:8:26
  |
8 |         T::T1(a) | T::T2(b) => { println!("{:?}", a); }
  |         ^^^^^^^^ pattern doesn't bind `b`

At least not pointing at b while saying the pattern doesn't bind b would be better.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions