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.
This commit is contained in:
Felix S. Klock II 2013-01-29 10:20:28 +01:00
parent 88bec09e63
commit 6cabe2b902

View File

@ -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;
}
~~~