Skip to content

Commit 6cabe2b

Browse files
committed
Fixed two examples of erroneous code so their errors match expectation.
1. In the first case, the previous code was failing during type inference due to mismatched structure. Fix is to use the X structure at both points in the code. 2. In the second case, a naive transcription that subsitutes *nothing* in for the omitted statements signified by "..." will actually compile without an error. Furthermore, any pure code could also be substituted for the ellipsis and the code would compile (as the text already states). So to make the example more illustrative, it would be better to include an impure callback, which makes the potential for aliasing immediately obvious to the reader.
1 parent 88bec09 commit 6cabe2b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

doc/tutorial-borrowed-ptr.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ rejected by the compiler):
302302
fn example3() -> int {
303303
let mut x = ~X {f: 3};
304304
let y = &x.f;
305-
x = ~{f: 4}; // Error reported here.
305+
x = ~X {f: 4}; // Error reported here.
306306
*y
307307
}
308308
~~~
@@ -369,9 +369,11 @@ box's owner. Consider a program like this:
369369
~~~
370370
struct R { g: int }
371371
struct S { mut f: ~R }
372-
fn example5a(x: @S ...) -> int {
372+
fn example5a(x: @S, callback: @fn()) -> int {
373373
let y = &x.f.g; // Error reported here.
374374
...
375+
callback();
376+
...
375377
# return 0;
376378
}
377379
~~~

0 commit comments

Comments
 (0)