Skip to content

Commit aead435

Browse files
committed
---
yaml --- r: 71803 b: refs/heads/dist-snap c: 614d6da h: refs/heads/master i: 71801: 021e636 71799: 413b9d0 v: v3
1 parent 43e5b9a commit aead435

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: b50030718cf28f2a5a81857a26b57442734fe854
10-
refs/heads/dist-snap: 08e2cf846aebf5a9f5e53881814976a3beee89a7
10+
refs/heads/dist-snap: 614d6da828969389871e01d1b8a17b3ccc1a5caa
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/doc/tutorial.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,28 @@ 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+
1086+
~~~~ {.xfail-test}
1087+
// but b cannot be assigned to c, or a to d
1088+
c = b; // error
1089+
~~~~
1090+
1091+
10701092
# Move semantics
10711093

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

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

10861118
Rust's borrowed pointers are a general purpose reference type. In contrast with

0 commit comments

Comments
 (0)