Skip to content

Commit b67b098

Browse files
committed
---
yaml --- r: 24465 b: refs/heads/master c: df98cb8 h: refs/heads/master i: 24463: 5cfa48a v: v3
1 parent bb16155 commit b67b098

File tree

2 files changed

+48
-22
lines changed

2 files changed

+48
-22
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: e513bc98754c1dfa33e8d71b7352a0409905e5f3
2+
refs/heads/master: df98cb8e884e7546b83ee229975759deb948e05a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/doc/rust.md

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,27 +2510,53 @@ tuple of arguments.
25102510
Enumerated types cannot be denoted *structurally* as types, but must be
25112511
denoted by named reference to an [*enumeration* item](#enumerations).
25122512

2513-
### Box types
2514-
2515-
Box types are represented as pointers. There are three flavours of
2516-
pointers:
2517-
2518-
Shared boxes (`@`)
2519-
: These are reference-counted boxes. Their type is written
2520-
`@content`, for example `@int` means a shared box containing an
2521-
integer. Copying a value of such a type means copying the pointer
2522-
and increasing the reference count.
2523-
2524-
Unique boxes (`~`)
2525-
: Unique boxes have only a single owner, and are freed when their
2526-
owner releases them. They are written `~content`. Copying a
2527-
unique box involves copying the contents into a new box.
2528-
2529-
Unsafe pointers (`*`)
2530-
: Unsafe pointers are pointers without safety guarantees or
2531-
language-enforced semantics. Their type is written `*content`.
2532-
They can be copied and dropped freely. Dereferencing an unsafe
2533-
pointer is part of the unsafe sub-dialect of Rust.
2513+
### Pointer types
2514+
2515+
All pointers in Rust are explicit first-class values.
2516+
They can be copied, stored into data structures, and returned from functions.
2517+
There are four varieties of pointer in Rust:
2518+
2519+
Managed pointers (`@`)
2520+
: These point to managed heap allocations (or "boxes") in the task-local, managed heap.
2521+
Managed pointers are written `@content`,
2522+
for example `@int` means a managed pointer to a managed box containing an integer.
2523+
Copying a managed pointer is a "shallow" operation:
2524+
it involves only copying the pointer itself
2525+
(as well as any reference-count or GC-barriers required by the managed heap).
2526+
Dropping a managed pointer does not necessarily release the box it points to;
2527+
the lifecycles of managed boxes are subject to an unspecified garbage collection algorithm.
2528+
2529+
Owning pointers (`~`)
2530+
: These point to owned heap allocations (or "boxes") in the shared, inter-task heap.
2531+
Each owned box has a single owning pointer; pointer and pointee retain a 1:1 relationship at all times.
2532+
Owning pointers are written `~content`,
2533+
for example `~int` means an owning pointer to an owned box containing an integer.
2534+
Copying an owned box is a "deep" operation:
2535+
it involves allocating a new owned box and copying the contents of the old box into the new box.
2536+
Releasing an owning pointer immediately releases its corresponding owned box.
2537+
2538+
Borrowed pointers (`&`)
2539+
: These point to memory _owned by some other value_.
2540+
Borrowed pointers arise by (automatic) conversion from owning pointers, managed pointers,
2541+
or by applying the borrowing operator `&` to some other value,
2542+
including [lvalues, rvalues or temporaries](#lvalues-rvalues-and-temporaries).
2543+
Borrowed pointers are written `&content`, or in some cases `&f/content` for some lifetime-variable `f`,
2544+
for example `&int` means a borrowed pointer to an integer.
2545+
Copying a borrowed pointer is a "shallow" operation:
2546+
it involves only copying the pointer itself.
2547+
Releasing a borrowed pointer typically has no effect on the value it points to,
2548+
with the exception of temporary values,
2549+
which are released when the last borrowed pointer to them is released.
2550+
2551+
Raw pointers (`*`)
2552+
: Raw pointers are pointers without safety or liveness guarantees.
2553+
Raw pointers are written `*content`,
2554+
for example `*int` means a raw pointer to an integer.
2555+
Copying or dropping a raw pointer is has no effect on the lifecycle of any other value.
2556+
Dereferencing a raw pointer or converting it to any other pointer type is an [`unsafe` operation](#unsafe-functions).
2557+
Raw pointers are generally discouraged in Rust code;
2558+
they exist to support interoperability with foreign code,
2559+
and writing performance-critical or low-level functions.
25342560

25352561
### Function types
25362562

0 commit comments

Comments
 (0)