@@ -982,7 +982,8 @@ The obvious approach is to define `Cons` as containing an element in the list
982982along with the next ` List ` node. However, this will generate a compiler error.
983983
984984~~~ {.ignore}
985- // error: illegal recursive enum type; wrap the inner value in a box to make it representable
985+ // error: illegal recursive enum type; wrap the inner value in a box to make it
986+ // representable
986987enum List {
987988 Cons(u32, List), // an element (`u32`) and the next node in the list
988989 Nil
@@ -1054,10 +1055,10 @@ immutable, the whole list is immutable. The memory allocation itself is the
10541055box, while the owner holds onto a pointer to it:
10551056
10561057~~~ {.notrust}
1057- List box List box List box List box
1058- +--------------+ +--------------+ +--------------+ +-------------- +
1059- list -> | Cons | 1 | ~ | -> | Cons | 2 | ~ | -> | Cons | 3 | ~ | -> | Nil |
1060- +--------------+ +--------------+ +--------------+ +-------------- +
1058+ List box List box List box List box
1059+ +--------------+ +--------------+ +--------------+ +----------+
1060+ list -> | Cons | 1 | ~ | -> | Cons | 2 | ~ | -> | Cons | 3 | ~ | -> | Nil |
1061+ +--------------+ +--------------+ +--------------+ +----------+
10611062~~~
10621063
10631064> * Note:* the above diagram shows the logical contents of the enum. The actual
@@ -1197,7 +1198,8 @@ fn eq(xs: &List, ys: &List) -> bool {
11971198 // If we have reached the end of both lists, they are equal.
11981199 (&Nil, &Nil) => true,
11991200 // If the current element in both lists is equal, keep going.
1200- (&Cons(x, ~ref next_xs), &Cons(y, ~ref next_ys)) if x == y => eq(next_xs, next_ys),
1201+ (&Cons(x, ~ref next_xs), &Cons(y, ~ref next_ys))
1202+ if x == y => eq(next_xs, next_ys),
12011203 // If the current elements are not equal, the lists are not equal.
12021204 _ => false
12031205 }
@@ -1256,7 +1258,7 @@ Using the generic `List<T>` works much like before, thanks to type inference:
12561258# Cons(value, ~xs)
12571259# }
12581260let mut xs = Nil; // Unknown type! This is a `List<T>`, but `T` can be anything.
1259- xs = prepend(xs, 10); // The compiler infers the type of `xs` as `List<int>` from this .
1261+ xs = prepend(xs, 10); // Here the compiler infers `xs`'s type as `List<int>`.
12601262xs = prepend(xs, 15);
12611263xs = prepend(xs, 20);
12621264~~~
@@ -1303,7 +1305,8 @@ fn eq<T: Eq>(xs: &List<T>, ys: &List<T>) -> bool {
13031305 // If we have reached the end of both lists, they are equal.
13041306 (&Nil, &Nil) => true,
13051307 // If the current element in both lists is equal, keep going.
1306- (&Cons(ref x, ~ref next_xs), &Cons(ref y, ~ref next_ys)) if x == y => eq(next_xs, next_ys),
1308+ (&Cons(ref x, ~ref next_xs), &Cons(ref y, ~ref next_ys))
1309+ if x == y => eq(next_xs, next_ys),
13071310 // If the current elements are not equal, the lists are not equal.
13081311 _ => false
13091312 }
@@ -1331,7 +1334,8 @@ impl<T: Eq> Eq for List<T> {
13311334 // If we have reached the end of both lists, they are equal.
13321335 (&Nil, &Nil) => true,
13331336 // If the current element in both lists is equal, keep going.
1334- (&Cons(ref x, ~ref next_xs), &Cons(ref y, ~ref next_ys)) if x == y => next_xs == next_ys,
1337+ (&Cons(ref x, ~ref next_xs), &Cons(ref y, ~ref next_ys))
1338+ if x == y => next_xs == next_ys,
13351339 // If the current elements are not equal, the lists are not equal.
13361340 _ => false
13371341 }
0 commit comments