From 9a1523455b91637434e89ad7fbc17f0f462960bd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 15 Apr 2015 12:31:56 +0200 Subject: [PATCH] Add long diagnostics for "bind by-ref and by-move" --- src/librustc/diagnostics.rs | 48 ++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 938a74382e20e..2c8e079852741 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -112,6 +112,53 @@ reference when using guards or refactor the entire expression, perhaps by putting the condition inside the body of the arm. "##, +E0009: r##" +In a pattern, all values that don't implement the `Copy` trait have to be bound +the same way. The goal here is to avoid binding simultaneous by-move and by-ref. + +This limitation may be removed in a future version of Rust. + +Wrong example: + +``` +struct X { x: (), } + +let x = Some((X { x: () }, X { x: () })); +match x { + Some((y, ref z)) => {}, + None => panic!() +} +``` + +You have two solutions: +1. Bind the pattern's values the same way: + +``` +struct X { x: (), } + +let x = Some((X { x: () }, X { x: () })); +match x { + Some((ref y, ref z)) => {}, + // or Some((y, z)) => {} + None => panic!() +} +``` + +2. Implement the `Copy` trait for the X structure (however, please +keep in mind that the first solution should be preferred!): + +``` +#[derive(Clone, Copy)] +struct X { x: (), } + +let x = Some((X { x: () }, X { x: () })); +match x { + Some((y, ref z)) => {}, + None => panic!() +} +``` +"##, + E0162: r##" An if-let pattern attempts to match the pattern, and enters the body if the match was succesful. If the match is irrefutable (when it cannot fail to match), @@ -232,7 +279,6 @@ See also https://github.com/rust-lang/rust/issues/14587 } register_diagnostics! { - E0009, E0010, E0011, E0012,