about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJunseok Lee <lee.junseok@berkeley.edu>2015-02-17 18:05:15 -0800
committerJunseok Lee <lee.junseok@berkeley.edu>2015-02-18 13:22:59 -0800
commit8e0e87fc326ac44f7b990ebb29e3b0ae7c6a84f8 (patch)
tree94479579453f66b0271e47068f090d40575ee3ad
parentdfc5c0f1e8799f47f9033bdcc8a7cd8a217620a5 (diff)
downloadrust-8e0e87fc326ac44f7b990ebb29e3b0ae7c6a84f8.tar.gz
rust-8e0e87fc326ac44f7b990ebb29e3b0ae7c6a84f8.zip
revised pointer example
-rw-r--r--src/doc/trpl/pointers.md27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/doc/trpl/pointers.md b/src/doc/trpl/pointers.md
index 9c649cd2273..87bd2953fdb 100644
--- a/src/doc/trpl/pointers.md
+++ b/src/doc/trpl/pointers.md
@@ -361,16 +361,16 @@ duration a *lifetime*. Let's try a more complex example:
 
 ```{rust}
 fn main() {
-    let x = &mut 5;
+    let mut x = 5;
 
-    if *x < 10 {
+    if x < 10 {
         let y = &x;
 
         println!("Oh no: {}", y);
         return;
     }
 
-    *x -= 1;
+    x -= 1;
 
     println!("Oh no: {}", x);
 }
@@ -382,17 +382,18 @@ mutated, and therefore, lets us pass. This wouldn't work:
 
 ```{rust,ignore}
 fn main() {
-    let x = &mut 5;
+    let mut x = 5;
 
-    if *x < 10 {
+    if x < 10 {
         let y = &x;
-        *x -= 1;
+
+        x -= 1;
 
         println!("Oh no: {}", y);
         return;
     }
 
-    *x -= 1;
+    x -= 1;
 
     println!("Oh no: {}", x);
 }
@@ -401,12 +402,12 @@ fn main() {
 It gives this error:
 
 ```text
-test.rs:5:8: 5:10 error: cannot assign to `*x` because it is borrowed
-test.rs:5         *x -= 1;
-                  ^~
-test.rs:4:16: 4:18 note: borrow of `*x` occurs here
-test.rs:4         let y = &x;
-                          ^~
+test.rs:7:9: 7:15 error: cannot assign to `x` because it is borrowed
+test.rs:7         x -= 1;
+                  ^~~~~~
+test.rs:5:18: 5:19 note: borrow of `x` occurs here
+test.rs:5         let y = &x;
+                           ^
 ```
 
 As you might guess, this kind of analysis is complex for a human, and therefore