From 6cabe2b90226e2262c8c1937b604d9f2c6f14059 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 29 Jan 2013 10:20:28 +0100 Subject: [PATCH] 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. --- doc/tutorial-borrowed-ptr.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/tutorial-borrowed-ptr.md b/doc/tutorial-borrowed-ptr.md index 4866f7b8f5e..59d58cadbec 100644 --- a/doc/tutorial-borrowed-ptr.md +++ b/doc/tutorial-borrowed-ptr.md @@ -302,7 +302,7 @@ rejected by the compiler): fn example3() -> int { let mut x = ~X {f: 3}; let y = &x.f; - x = ~{f: 4}; // Error reported here. + x = ~X {f: 4}; // Error reported here. *y } ~~~ @@ -369,9 +369,11 @@ box's owner. Consider a program like this: ~~~ struct R { g: int } struct S { mut f: ~R } -fn example5a(x: @S ...) -> int { +fn example5a(x: @S, callback: @fn()) -> int { let y = &x.f.g; // Error reported here. ... + callback(); + ... # return 0; } ~~~