Skip to content

Small fixes to code samples in Tutorials #4669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions doc/tutorial-borrowed-ptr.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
~~~
Expand Down Expand Up @@ -366,12 +366,14 @@ Things get trickier when the unique box is not uniquely owned by the
stack frame, or when there is no way for the compiler to determine the
box's owner. Consider a program like this:

~~~
~~~ {.xfail-test}
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;
}
~~~
Expand Down
14 changes: 9 additions & 5 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,7 @@ the method name with the trait name.
The compiler will use type inference to decide which implementation to call.

~~~~
# trait Shape { static fn new(area: float) -> self; }
trait Shape { static fn new(area: float) -> self; }
# use float::consts::pi;
# use float::sqrt;
struct Circle { radius: float }
Expand Down Expand Up @@ -2211,11 +2211,15 @@ Likewise, supertrait methods may also be called on trait objects.
~~~ {.xfail-test}
# trait Shape { fn area(&self) -> float; }
# trait Circle : Shape { fn radius(&self) -> float; }
# impl int: Shape { fn area(&self) -> float { 0.0 } }
# impl int: Circle { fn radius(&self) -> float { 0.0 } }
# let mycircle = 0;
# use float::consts::pi;
# use float::sqrt;
# struct Point { x: float, y: float }
# struct CircleStruct { center: Point, radius: float }
# impl CircleStruct: Circle { fn radius(&self) -> float { sqrt(self.area() / pi) } }
# impl CircleStruct: Shape { fn area(&self) -> float { pi * square(self.radius) } }

let mycircle: Circle = @mycircle as @Circle;
let concrete = @CircleStruct{center:Point{x:3f,y:4f},radius:5f};
let mycircle: Circle = concrete as @Circle;
let nonsense = mycircle.radius() * mycircle.area();
~~~

Expand Down