]> git.proxmox.com Git - rustc.git/blame - src/librustc_error_codes/error_codes/E0409.md
New upstream version 1.47.0+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0409.md
CommitLineData
60c5eb7d
XL
1An "or" pattern was used where the variable bindings are not consistently bound
2across patterns.
3
4Erroneous code example:
5
6```compile_fail,E0409
7let x = (0, 2);
8match x {
9 (0, ref y) | (y, 0) => { /* use y */} // error: variable `y` is bound with
10 // different mode in pattern #2
11 // than in pattern #1
12 _ => ()
13}
14```
15
16Here, `y` is bound by-value in one case and by-reference in the other.
17
18To fix this error, just use the same mode in both cases.
19Generally using `ref` or `ref mut` where not already used will fix this:
20
21```
22let x = (0, 2);
23match x {
24 (0, ref y) | (ref y, 0) => { /* use y */}
25 _ => ()
26}
27```
28
29Alternatively, split the pattern:
30
31```
32let x = (0, 2);
33match x {
34 (y, 0) => { /* use y */ }
35 (0, ref y) => { /* use y */}
36 _ => ()
37}
38```