Skip to content

Commit 5fdb0cb

Browse files
committed
Correct tutorial tests
1 parent e014ab9 commit 5fdb0cb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

doc/tutorial.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,12 +1941,14 @@ fn head_bad<T>(v: &[T]) -> T {
19411941
~~~~
19421942

19431943
However, we can tell the compiler that the `head` function is only for
1944-
copyable types: that is, those that have the `Copy` trait.
1944+
copyable types: that is, those that have the `Copy` trait. In that
1945+
case, we can explicitly create a second copy of the value we are
1946+
returning using the `copy` keyword:
19451947

19461948
~~~~
19471949
// This does
19481950
fn head<T: Copy>(v: &[T]) -> T {
1949-
v[0]
1951+
copy v[0]
19501952
}
19511953
~~~~
19521954

@@ -2137,7 +2139,7 @@ as in this version of `print_all` that copies elements.
21372139
fn print_all<T: Printable + Copy>(printable_things: ~[T]) {
21382140
let mut i = 0;
21392141
while i < printable_things.len() {
2140-
let copy_of_thing = printable_things[i];
2142+
let copy_of_thing = copy printable_things[i];
21412143
copy_of_thing.print();
21422144
i += 1;
21432145
}

0 commit comments

Comments
 (0)