]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0009.md
Rollup merge of #93556 - dtolnay:trailingcomma, r=cjgillot
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0009.md
1 #### Note: this error code is no longer emitted by the compiler.
2
3 In a pattern, all values that don't implement the `Copy` trait have to be bound
4 the same way. The goal here is to avoid binding simultaneously by-move and
5 by-ref.
6
7 This limitation may be removed in a future version of Rust.
8
9 Erroneous code example:
10
11 ```
12 #![feature(move_ref_pattern)]
13
14 struct X { x: (), }
15
16 let x = Some((X { x: () }, X { x: () }));
17 match x {
18     Some((y, ref z)) => {}, // error: cannot bind by-move and by-ref in the
19                             //        same pattern
20     None => panic!()
21 }
22 ```
23
24 You have two solutions:
25
26 Solution #1: Bind the pattern's values the same way.
27
28 ```
29 struct X { x: (), }
30
31 let x = Some((X { x: () }, X { x: () }));
32 match x {
33     Some((ref y, ref z)) => {},
34     // or Some((y, z)) => {}
35     None => panic!()
36 }
37 ```
38
39 Solution #2: Implement the `Copy` trait for the `X` structure.
40
41 However, please keep in mind that the first solution should be preferred.
42
43 ```
44 #[derive(Clone, Copy)]
45 struct X { x: (), }
46
47 let x = Some((X { x: () }, X { x: () }));
48 match x {
49     Some((y, ref z)) => {},
50     None => panic!()
51 }
52 ```