- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsE-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Description
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
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsE-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.