@@ -19,20 +19,13 @@ enum MyEnum {
1919}
2020
2121fn a_to_b (e : & mut MyEnum ) {
22-
23- // we mutably borrow `e` here. This precludes us from changing it directly
24- // as in `*e = ...`, because the borrow checker won't allow it. Therefore
25- // the assignment to `e` must be outside the `if let` clause.
26- * e = if let MyEnum :: A { ref mut name , x : 0 } = * e {
27-
22+ if let MyEnum :: A { name , x : 0 } = e {
2823 // this takes out our `name` and put in an empty String instead
2924 // (note that empty strings don't allocate).
3025 // Then, construct the new enum variant (which will
31- // be assigned to `*e`, because it is the result of the `if let` expression).
32- MyEnum :: B { name : mem :: take (name ) }
33-
34- // In all other cases, we return immediately, thus skipping the assignment
35- } else { return }
26+ // be assigned to `*e`).
27+ * e = MyEnum :: B { name : mem :: take (name ) }
28+ }
3629}
3730```
3831
@@ -50,11 +43,11 @@ enum MultiVariateEnum {
5043
5144fn swizzle (e : & mut MultiVariateEnum ) {
5245 use MultiVariateEnum :: * ;
53- * e = match * e {
46+ * e = match e {
5447 // Ownership rules do not allow taking `name` by value, but we cannot
5548 // take the value out of a mutable reference, unless we replace it:
56- A { ref mut name } => B { name : mem :: take (name ) },
57- B { ref mut name } => A { name : mem :: take (name ) },
49+ A { name } => B { name : mem :: take (name ) },
50+ B { name } => A { name : mem :: take (name ) },
5851 C => D ,
5952 D => C
6053 }
0 commit comments