about summary refs log tree commit diff
path: root/src/doc/tutorial.md
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-07-17 22:16:23 +0000
committerbors <bors@rust-lang.org>2014-07-17 22:16:23 +0000
commite288fc6a996562c5e4aca46e22c1da46eb3d086b (patch)
tree2f26793e5416aa2cef3b93760807543c0c6398d2 /src/doc/tutorial.md
parent36d6acc4eea7e305058511c3fda19d459095b7f8 (diff)
parentde70d76373e05fcf0f421cedb185b08de10a714c (diff)
downloadrust-e288fc6a996562c5e4aca46e22c1da46eb3d086b.tar.gz
rust-e288fc6a996562c5e4aca46e22c1da46eb3d086b.zip
auto merge of #15515 : pcwalton/rust/cross-borrowing, r=alexcrichton
except where trait objects are involved.

Part of issue #15349, though I'm leaving it open for trait objects.
Cross borrowing for trait objects remains because it is needed until we
have DST.

This will break code like:

    fn foo(x: &int) { ... }

    let a = box 3i;
    foo(a);

Change this code to:

    fn foo(x: &int) { ... }

    let a = box 3i;
    foo(&*a);

[breaking-change]

r? @alexcrichton
Diffstat (limited to 'src/doc/tutorial.md')
-rw-r--r--src/doc/tutorial.md10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/doc/tutorial.md b/src/doc/tutorial.md
index e0f0bbd6c9f..4c90e564b58 100644
--- a/src/doc/tutorial.md
+++ b/src/doc/tutorial.md
@@ -1470,7 +1470,7 @@ Now we can call `compute_distance()` in various ways:
 # let on_the_stack :     Point  =     Point { x: 3.0, y: 4.0 };
 # let on_the_heap  : Box<Point> = box Point { x: 7.0, y: 9.0 };
 # fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 }
-compute_distance(&on_the_stack, on_the_heap);
+compute_distance(&on_the_stack, &*on_the_heap);
 ~~~
 
 Here the `&` operator is used to take the address of the variable
@@ -1480,11 +1480,9 @@ reference. We also call this _borrowing_ the local variable
 `on_the_stack`, because we are creating an alias: that is, another
 route to the same data.
 
-In the case of `owned_box`, however, no
-explicit action is necessary. The compiler will automatically convert
-a box `box point` to a reference like
-`&point`. This is another form of borrowing; in this case, the
-contents of the owned box are being lent out.
+Likewise, in the case of `owned_box`,
+the `&` operator is used in conjunction with the `*` operator
+to take a reference to the contents of the box.
 
 Whenever a value is borrowed, there are some limitations on what you
 can do with the original. For example, if the contents of a variable