Skip to content

Consolidate pattern check errors #53840

Closed
@estebank

Description

@estebank

Given:

enum E {
    Foo(String, String, String),
}

fn main() {
    match E::Foo("".into(), "".into(), "".into()) {
        E::Foo(a, b, ref c) => {}
    }
}

the current pattern check emits one diagnostic per mismatched usage:

error[E0009]: cannot bind by-move and by-ref in the same pattern
 --> file.rs:7:16
  |
7 |         E::Foo(a, b, ref c) => {}
  |                ^     ----- both by-ref and by-move used
  |                |
  |                by-move pattern here

error[E0009]: cannot bind by-move and by-ref in the same pattern
 --> file.rs:7:19
  |
7 |         E::Foo(a, b, ref c) => {}
  |                   ^  ----- both by-ref and by-move used
  |                   |
  |                   by-move pattern here

Ideally, the pattern check should collect all problematic patterns when possible to reduce how many diagnostics are emitted:

error[E0009]: cannot bind by-move and by-ref in the same pattern
 --> file.rs:7:16
  |
7 |         E::Foo(a, b, ref c) => {}
  |                ^  ^  ----- both by-ref and by-move used
  |                |  |
  |                |  by-move pattern here
  |                by-move pattern here
  |
help: use by-ref everywhere
  |
7 |         E::Foo(ref a, ref b, ref c) => {}
  |                ^^^    ^^^

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions