compiler/rustc_error_codes/src/error_codes/E0009.md MARKDOWN 53 lines View on github.com → Search inside
1#### Note: this error code is no longer emitted by the compiler.23In a pattern, all values that don't implement the `Copy` trait have to be bound4the same way. The goal here is to avoid binding simultaneously by-move and5by-ref.67This limitation may be removed in a future version of Rust.89Erroneous code example:1011```12#![feature(move_ref_pattern)]1314struct X { x: (), }1516let x = Some((X { x: () }, X { x: () }));17match x {18    Some((y, ref z)) => {}, // error: cannot bind by-move and by-ref in the19                            //        same pattern20    None => panic!()21}22```2324You have two solutions:2526Solution #1: Bind the pattern's values the same way.2728```29struct X { x: (), }3031let x = Some((X { x: () }, X { x: () }));32match x {33    Some((ref y, ref z)) => {},34    // or Some((y, z)) => {}35    None => panic!()36}37```3839Solution #2: Implement the `Copy` trait for the `X` structure.4041However, please keep in mind that the first solution should be preferred.4243```44#[derive(Clone, Copy)]45struct X { x: (), }4647let x = Some((X { x: () }, X { x: () }));48match x {49    Some((y, ref z)) => {},50    None => panic!()51}52```

Findings

✓ No findings reported for this file.

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.