Skip to content

Commit 81db162

Browse files
author
Diggory Hardy
committed
---
yaml --- r: 54510 b: refs/heads/snap-stage3 c: 1e483c7 h: refs/heads/master v: v3
1 parent f30ce6b commit 81db162

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 25b39b85da9544a4df9ce8201ac9878b1ec34ff5
4+
refs/heads/snap-stage3: 1e483c7b70a7369da3c1cd2c858cf2c3d455968c
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/doc/tutorial.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,26 @@ let mut d = @mut 5; // mutable variable, mutable box
10671067
d = @mut 15;
10681068
~~~~
10691069

1070+
A mutable variable and an immutable variable can refer to the same box, given
1071+
that their types are compatible. Mutability of a box is a property of its type,
1072+
however, so for example a mutable handle to an immutable box cannot be
1073+
assigned a reference to a mutable box.
1074+
1075+
~~~~
1076+
let a = @1; // immutable box
1077+
let b = @mut 2; // mutable box
1078+
1079+
let mut c : @int; // declare a variable with type managed immutable int
1080+
let mut d : @mut int; // and one of type managed mutable int
1081+
1082+
c = a; // box type is the same, okay
1083+
d = b; // box type is the same, okay
1084+
1085+
// but b cannot be assigned to c, or a to d
1086+
c = b; // error
1087+
~~~~
1088+
1089+
10701090
# Move semantics
10711091

10721092
Rust uses a shallow copy for parameter passing, assignment and returning values
@@ -1081,6 +1101,16 @@ let y = x.clone(); // y is a newly allocated box
10811101
let z = x; // no new memory allocated, x can no longer be used
10821102
~~~~
10831103

1104+
Since in owned boxes mutabilility is a property of the owner, not the
1105+
box, mutable boxes may become immutable when they are moved, and vice-versa.
1106+
1107+
~~~~
1108+
let r = ~13;
1109+
let mut s = r; // box becomes mutable
1110+
*s += 1;
1111+
let t = s; // box becomes immutable
1112+
~~~~
1113+
10841114
# Borrowed pointers
10851115

10861116
Rust's borrowed pointers are a general purpose reference type. In contrast with
@@ -1191,7 +1221,7 @@ they are frozen:
11911221
let x = @mut 5;
11921222
let y = x;
11931223
{
1194-
let y = &*y; // the managed box is now frozen
1224+
let z = &*y; // the managed box is now frozen
11951225
// modifying it through x or y will cause a task failure
11961226
}
11971227
// the box is now unfrozen again

branches/snap-stage3/src/librust/rust.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static commands: &'static [Command<'static>] = &[
6464
Command{
6565
cmd: "run",
6666
action: Call(cmd_run),
67-
usage_line: "build an executable, and run it",
67+
usage_line: "build a executable, and run it",
6868
usage_full: UsgStr(
6969
"The run command is an shortcut for the command line \n\
7070
\"rustc <filename> -o <filestem>~ && ./<filestem>~\".\

0 commit comments

Comments
 (0)