Skip to content

Commit c1395ea

Browse files
committed
auto merge of #11999 : joaoxsouls/rust/master, r=cmr
2 parents 2877928 + b69c81c commit c1395ea

File tree

1 file changed

+12
-57
lines changed

1 file changed

+12
-57
lines changed

src/doc/rust.md

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,9 +2426,9 @@ before the expression they apply to.
24262426
: Logical negation. On the boolean type, this flips between `true` and
24272427
`false`. On integer types, this inverts the individual bits in the
24282428
two's complement representation of the value.
2429-
`@` and `~`
2429+
`~`
24302430
: [Boxing](#pointer-types) operators. Allocate a box to hold the value they are applied to,
2431-
and store the value in it. `@` creates a managed box, whereas `~` creates an owned box.
2431+
and store the value in it. `~` creates an owned box.
24322432
`&`
24332433
: Borrow operator. Returns a reference, pointing to its operand.
24342434
The operand of a borrow is statically proven to outlive the resulting pointer.
@@ -3203,16 +3203,6 @@ All pointers in Rust are explicit first-class values.
32033203
They can be copied, stored into data structures, and returned from functions.
32043204
There are four varieties of pointer in Rust:
32053205

3206-
Managed pointers (`@`)
3207-
: These point to managed heap allocations (or "boxes") in the task-local, managed heap.
3208-
Managed pointers are written `@content`,
3209-
for example `@int` means a managed pointer to a managed box containing an integer.
3210-
Copying a managed pointer is a "shallow" operation:
3211-
it involves only copying the pointer itself
3212-
(as well as any reference-count or GC-barriers required by the managed heap).
3213-
Dropping a managed pointer does not necessarily release the box it points to;
3214-
the lifecycles of managed boxes are subject to an unspecified garbage collection algorithm.
3215-
32163206
Owning pointers (`~`)
32173207
: These point to owned heap allocations (or "boxes") in the shared, inter-task heap.
32183208
Each owned box has a single owning pointer; pointer and pointee retain a 1:1 relationship at all times.
@@ -3521,63 +3511,28 @@ state. Subsequent statements within a function may or may not initialize the
35213511
local variables. Local variables can be used only after they have been
35223512
initialized; this is enforced by the compiler.
35233513

3524-
### Memory boxes
3525-
3526-
A _box_ is a reference to a heap allocation holding another value. There
3527-
are two kinds of boxes: *managed boxes* and *owned boxes*.
3528-
3529-
A _managed box_ type or value is constructed by the prefix *at* sigil `@`.
3530-
3531-
An _owned box_ type or value is constructed by the prefix *tilde* sigil `~`.
3514+
### Owned boxes
35323515

3533-
Multiple managed box values can point to the same heap allocation; copying a
3534-
managed box value makes a shallow copy of the pointer (optionally incrementing
3535-
a reference count, if the managed box is implemented through
3536-
reference-counting).
3516+
An _owned box_ is a reference to a heap allocation holding another value, which is constructed
3517+
by the prefix *tilde* sigil `~`
35373518

3538-
Owned box values exist in 1:1 correspondence with their heap allocation.
3539-
3540-
An example of constructing one managed box type and value, and one owned box
3541-
type and value:
3519+
An example of an owned box type and value:
35423520

35433521
~~~~
3544-
let x: @int = @10;
35453522
let x: ~int = ~10;
35463523
~~~~
35473524

3548-
Some operations (such as field selection) implicitly dereference boxes. An
3549-
example of an _implicit dereference_ operation performed on box values:
3525+
Owned box values exist in 1:1 correspondence with their heap allocation
3526+
copying an owned box value makes a shallow copy of the pointer
3527+
Rust will consider a shallow copy of an owned box to move ownership of the value. After a value has been moved, the source location cannot be used unless it is reinitialized.
35503528

35513529
~~~~
3552-
struct Foo { y: int }
3553-
let x = @Foo{y: 10};
3554-
assert!(x.y == 10);
3555-
~~~~
3556-
3557-
Other operations act on box values as single-word-sized address values. For
3558-
these operations, to access the value held in the box requires an explicit
3559-
dereference of the box value. Explicitly dereferencing a box is indicated with
3560-
the unary *star* operator `*`. Examples of such _explicit dereference_
3561-
operations are:
3562-
3563-
* copying box values (`x = y`)
3564-
* passing box values to functions (`f(x,y)`)
3565-
3566-
An example of an explicit-dereference operation performed on box values:
3567-
3530+
let x: ~int = ~10;
3531+
let y = x;
3532+
// attempting to use `x` will result in an error here
35683533
~~~~
3569-
fn takes_boxed(b: @int) {
3570-
}
35713534

3572-
fn takes_unboxed(b: int) {
3573-
}
35743535

3575-
fn main() {
3576-
let x: @int = @10;
3577-
takes_boxed(x);
3578-
takes_unboxed(*x);
3579-
}
3580-
~~~~
35813536

35823537
## Tasks
35833538

0 commit comments

Comments
 (0)