]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0409.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0409.md
1 An "or" pattern was used where the variable bindings are not consistently bound
2 across patterns.
3
4 Erroneous code example:
5
6 ```compile_fail,E0409
7 let x = (0, 2);
8 match 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
16 Here, `y` is bound by-value in one case and by-reference in the other.
17
18 To fix this error, just use the same mode in both cases.
19 Generally using `ref` or `ref mut` where not already used will fix this:
20
21 ```
22 let x = (0, 2);
23 match x {
24     (0, ref y) | (ref y, 0) => { /* use y */}
25     _ => ()
26 }
27 ```
28
29 Alternatively, split the pattern:
30
31 ```
32 let x = (0, 2);
33 match x {
34     (y, 0) => { /* use y */ }
35     (0, ref y) => { /* use y */}
36     _ => ()
37 }
38 ```