From 5fdb0cbb8ce98bdddc947fc1eeabd2efd509aadc Mon Sep 17 00:00:00 2001 From: Niko Matsakis <niko@alum.mit.edu> Date: Sat, 15 Jun 2013 21:36:55 -0400 Subject: [PATCH] Correct tutorial tests --- doc/tutorial.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/tutorial.md b/doc/tutorial.md index c0b939ddac5..f69f569faee 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -1941,12 +1941,14 @@ fn head_bad<T>(v: &[T]) -> T { ~~~~ However, we can tell the compiler that the `head` function is only for -copyable types: that is, those that have the `Copy` trait. +copyable types: that is, those that have the `Copy` trait. In that +case, we can explicitly create a second copy of the value we are +returning using the `copy` keyword: ~~~~ // This does fn head<T: Copy>(v: &[T]) -> T { - v[0] + copy v[0] } ~~~~ @@ -2137,7 +2139,7 @@ as in this version of `print_all` that copies elements. fn print_all<T: Printable + Copy>(printable_things: ~[T]) { let mut i = 0; while i < printable_things.len() { - let copy_of_thing = printable_things[i]; + let copy_of_thing = copy printable_things[i]; copy_of_thing.print(); i += 1; }