Skip to content

Fix code of tutorials now that mutable fields are deprecated #5154

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

Closed
wants to merge 1 commit into from
Closed
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
28 changes: 14 additions & 14 deletions doc/tutorial-borrowed-ptr.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,11 @@ mutations:
~~~ {.xfail-test}
fn example3() -> int {
struct R { g: int }
struct S { mut f: ~R }
struct S { f: ~R }

let mut x = ~S {mut f: ~R {g: 3}};
let mut x = ~S {f: ~R {g: 3}};
let y = &x.f.g;
x = ~S {mut f: ~R {g: 4}}; // Error reported here.
x = ~S {f: ~R {g: 4}}; // Error reported here.
x.f = ~R {g: 5}; // Error reported here.
*y
}
Expand All @@ -368,8 +368,8 @@ box's owner. Consider a program like this:

~~~ {.xfail-test}
struct R { g: int }
struct S { mut f: ~R }
fn example5a(x: @S, callback: @fn()) -> int {
struct S { f: ~R }
fn example5a(x: @mut S, callback: @fn()) -> int {
let y = &x.f.g; // Error reported here.
...
callback();
Expand All @@ -383,11 +383,11 @@ Here the heap looks something like:
~~~ {.notrust}
Stack Managed Heap Exchange Heap

x +------+ +-------------+ +------+
| @... | ----> | mut f: ~... | --+-> | g: 3 |
y +------+ +-------------+ | +------+
| &int | -------------------------+
+------+
x +---------+ +---------+ +------+
| @mut... | ----> | f: ~... | --+-> | g: 3 |
y +---------+ +---------+ | +------+
| &int | ---------------------+
+---------+
~~~

In this case, the owning reference to the value being borrowed is
Expand Down Expand Up @@ -423,8 +423,8 @@ onto your stack:

~~~
struct R { g: int }
struct S { mut f: ~R }
fn example5c(x: @S) -> int {
struct S { f: ~R }
fn example5c(x: @mut S) -> int {
let mut v = ~R {g: 0};
v <-> x.f; // Swap v and x.f
{ // Block constrains the scope of `y`:
Expand Down Expand Up @@ -768,7 +768,7 @@ replaced the `...` with some specific code:

~~~
struct R { g: int }
struct S { mut f: ~R }
struct S { f: ~R }
fn example5a(x: @S ...) -> int {
let y = &x.f.g; // Unsafe
*y + 1
Expand All @@ -789,7 +789,7 @@ We can now update `example5a()` to use `add_one()`:

~~~
# struct R { g: int }
# struct S { mut f: ~R }
# struct S { f: ~R }
# pure fn add_one(x: &int) -> int { *x + 1 }
fn example5a(x: @S ...) -> int {
let y = &x.f.g;
Expand Down
8 changes: 4 additions & 4 deletions doc/tutorial-ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ extern mod std;
use libc::c_ulonglong;

struct timeval {
mut tv_sec: c_ulonglong,
mut tv_usec: c_ulonglong
tv_sec: c_ulonglong,
tv_usec: c_ulonglong
}

#[nolink]
Expand All @@ -231,8 +231,8 @@ extern mod lib_c {
fn unix_time_in_microseconds() -> u64 {
unsafe {
let x = timeval {
mut tv_sec: 0 as c_ulonglong,
mut tv_usec: 0 as c_ulonglong
tv_sec: 0 as c_ulonglong,
tv_usec: 0 as c_ulonglong
};
lib_c::gettimeofday(ptr::addr_of(&x), ptr::null());
return (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64);
Expand Down
22 changes: 11 additions & 11 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ of its fields nevertheless mutable, using the `mut` keyword.
~~~~
struct Stack {
content: ~[int],
mut head: uint
head: uint
}
~~~~

Expand Down Expand Up @@ -938,19 +938,19 @@ type that contains managed boxes or other managed types.
~~~
// A linked list node
struct Node {
mut next: MaybeNode,
mut prev: MaybeNode,
payload: int
next: MaybeNode,
prev: MaybeNode,
payload: int
}

enum MaybeNode {
SomeNode(@Node),
NoNode
SomeNode(@mut Node),
NoNode
}

let node1 = @Node { next: NoNode, prev: NoNode, payload: 1 };
let node2 = @Node { next: NoNode, prev: NoNode, payload: 2 };
let node3 = @Node { next: NoNode, prev: NoNode, payload: 3 };
let node1 = @mut Node { next: NoNode, prev: NoNode, payload: 1 };
let node2 = @mut Node { next: NoNode, prev: NoNode, payload: 2 };
let node3 = @mut Node { next: NoNode, prev: NoNode, payload: 3 };

// Link the three list nodes together
node1.next = SomeNode(node2);
Expand Down Expand Up @@ -2300,8 +2300,8 @@ mod farm {
# impl Human { fn rest(&self) { } }
# pub fn make_me_a_farm() -> farm::Farm { farm::Farm { chickens: ~[], cows: ~[], farmer: Human(0) } }
pub struct Farm {
priv mut chickens: ~[Chicken],
priv mut cows: ~[Cow],
priv chickens: ~[Chicken],
priv cows: ~[Cow],
farmer: Human
}

Expand Down