Skip to content

Commit 3c02e2b

Browse files
committed
Merge pull request #4669 from pnkfelix/tutorial-revisions
Small fixes to code samples in Tutorials
2 parents 464ec27 + 20af4d7 commit 3c02e2b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

doc/tutorial-borrowed-ptr.md

Lines changed: 5 additions & 3 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
~~~
@@ -366,12 +366,14 @@ Things get trickier when the unique box is not uniquely owned by the
366366
stack frame, or when there is no way for the compiler to determine the
367367
box's owner. Consider a program like this:
368368

369-
~~~
369+
~~~ {.xfail-test}
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
~~~

doc/tutorial.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,7 +2015,7 @@ the method name with the trait name.
20152015
The compiler will use type inference to decide which implementation to call.
20162016

20172017
~~~~
2018-
# trait Shape { static fn new(area: float) -> self; }
2018+
trait Shape { static fn new(area: float) -> self; }
20192019
# use float::consts::pi;
20202020
# use float::sqrt;
20212021
struct Circle { radius: float }
@@ -2211,11 +2211,15 @@ Likewise, supertrait methods may also be called on trait objects.
22112211
~~~ {.xfail-test}
22122212
# trait Shape { fn area(&self) -> float; }
22132213
# trait Circle : Shape { fn radius(&self) -> float; }
2214-
# impl int: Shape { fn area(&self) -> float { 0.0 } }
2215-
# impl int: Circle { fn radius(&self) -> float { 0.0 } }
2216-
# let mycircle = 0;
2214+
# use float::consts::pi;
2215+
# use float::sqrt;
2216+
# struct Point { x: float, y: float }
2217+
# struct CircleStruct { center: Point, radius: float }
2218+
# impl CircleStruct: Circle { fn radius(&self) -> float { sqrt(self.area() / pi) } }
2219+
# impl CircleStruct: Shape { fn area(&self) -> float { pi * square(self.radius) } }
22172220
2218-
let mycircle: Circle = @mycircle as @Circle;
2221+
let concrete = @CircleStruct{center:Point{x:3f,y:4f},radius:5f};
2222+
let mycircle: Circle = concrete as @Circle;
22192223
let nonsense = mycircle.radius() * mycircle.area();
22202224
~~~
22212225

0 commit comments

Comments
 (0)