Skip to content

Commit ac67729

Browse files
committed
Remove stdlib stuff from the Reference
Fixes #11794
1 parent f899513 commit ac67729

File tree

1 file changed

+22
-239
lines changed

1 file changed

+22
-239
lines changed

Diff for: src/doc/reference.md

+22-239
Original file line numberDiff line numberDiff line change
@@ -645,18 +645,7 @@ fn bar() {
645645

646646
A number of minor features of Rust are not central enough to have their own
647647
syntax, and yet are not implementable as functions. Instead, they are given
648-
names, and invoked through a consistent syntax: `name!(...)`. Examples include:
649-
650-
* `format!` : format data into a string
651-
* `env!` : look up an environment variable's value at compile time
652-
* `file!`: return the path to the file being compiled
653-
* `stringify!` : pretty-print the Rust expression given as an argument
654-
* `include!` : include the Rust expression in the given file
655-
* `include_str!` : include the contents of the given file as a string
656-
* `include_bytes!` : include the contents of the given file as a binary blob
657-
* `error!`, `warn!`, `info!`, `debug!` : provide diagnostic information.
658-
659-
All of the above extensions are expressions with values.
648+
names, and invoked through a consistent syntax: `some_extension!(...)`.
660649

661650
Users of `rustc` can define new syntax extensions in two ways:
662651

@@ -744,38 +733,6 @@ Rust syntax is restricted in two ways:
744733
pairs when they occur at the beginning of, or immediately after, a `$(...)*`;
745734
requiring a distinctive token in front can solve the problem.
746735

747-
## Syntax extensions useful in macros
748-
749-
* `stringify!` : turn the identifier argument into a string literal
750-
* `concat!` : concatenates a comma-separated list of literals
751-
752-
## Syntax extensions for macro debugging
753-
754-
* `log_syntax!` : print out the arguments at compile time
755-
* `trace_macros!` : supply `true` or `false` to enable or disable macro expansion logging
756-
757-
## Quasiquoting
758-
759-
The following syntax extensions are used for quasiquoting Rust syntax trees,
760-
usually in [procedural macros](book/plugins.html#syntax-extensions):
761-
762-
* `quote_expr!`
763-
* `quote_item!`
764-
* `quote_pat!`
765-
* `quote_stmt!`
766-
* `quote_tokens!`
767-
* `quote_matcher!`
768-
* `quote_ty!`
769-
* `quote_attr!`
770-
771-
Keep in mind that when `$name : ident` appears in the input to
772-
`quote_tokens!`, the result contains unquoted `name` followed by two tokens.
773-
However, input of the same form passed to `quote_matcher!` becomes a
774-
quasiquoted MBE-matcher of a nonterminal. No unquotation happens. Otherwise
775-
the result of `quote_matcher!` is identical to that of `quote_tokens!`.
776-
777-
Documentation is very limited at the moment.
778-
779736
# Crates and source files
780737

781738
Rust is a *compiled* language. Its semantics obey a *phase distinction*
@@ -1520,22 +1477,6 @@ statics:
15201477
Constants should in general be preferred over statics, unless large amounts of
15211478
data are being stored, or single-address and mutability properties are required.
15221479

1523-
```
1524-
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
1525-
1526-
// Note that ATOMIC_USIZE_INIT is a *const*, but it may be used to initialize a
1527-
// static. This static can be modified, so it is not placed in read-only memory.
1528-
static COUNTER: AtomicUsize = ATOMIC_USIZE_INIT;
1529-
1530-
// This table is a candidate to be placed in read-only memory.
1531-
static TABLE: &'static [usize] = &[1, 2, 3, /* ... */];
1532-
1533-
for slot in TABLE.iter() {
1534-
println!("{}", slot);
1535-
}
1536-
COUNTER.fetch_add(1, Ordering::SeqCst);
1537-
```
1538-
15391480
#### Mutable statics
15401481

15411482
If a static item is declared with the `mut` keyword, then it is allowed to
@@ -2372,18 +2313,6 @@ impl<T: PartialEq> PartialEq for Foo<T> {
23722313
}
23732314
```
23742315

2375-
Supported traits for `derive` are:
2376-
2377-
* Comparison traits: `PartialEq`, `Eq`, `PartialOrd`, `Ord`.
2378-
* Serialization: `Encodable`, `Decodable`. These require `serialize`.
2379-
* `Clone`, to create `T` from `&T` via a copy.
2380-
* `Default`, to create an empty instance of a data type.
2381-
* `FromPrimitive`, to create an instance from a numeric primitive.
2382-
* `Hash`, to iterate over the bytes in a data type.
2383-
* `Rand`, to create a random instance of a data type.
2384-
* `Debug`, to format a value using the `{:?}` formatter.
2385-
* `Copy`, for "Plain Old Data" types which can be copied by simply moving bits.
2386-
23872316
### Compiler Features
23882317

23892318
Certain aspects of Rust may be implemented in the compiler, but they're not
@@ -3882,75 +3811,27 @@ impl Printable for String {
38823811
`self` refers to the value of type `String` that is the receiver for a call to
38833812
the method `make_string`.
38843813

3885-
## Type kinds
3886-
3887-
Types in Rust are categorized into kinds, based on various properties of the
3888-
components of the type. The kinds are:
3889-
3890-
* `Send`
3891-
: Types of this kind can be safely sent between threads.
3892-
This kind includes scalars, boxes, procs, and
3893-
structural types containing only other owned types.
3894-
All `Send` types are `'static`.
3895-
* `Copy`
3896-
: Types of this kind consist of "Plain Old Data"
3897-
which can be copied by simply moving bits.
3898-
All values of this kind can be implicitly copied.
3899-
This kind includes scalars and immutable references,
3900-
as well as structural types containing other `Copy` types.
3901-
* `'static`
3902-
: Types of this kind do not contain any references (except for
3903-
references with the `static` lifetime, which are allowed).
3904-
This can be a useful guarantee for code
3905-
that breaks borrowing assumptions
3906-
using [`unsafe` operations](#unsafe-functions).
3907-
* `Drop`
3908-
: This is not strictly a kind,
3909-
but its presence interacts with kinds:
3910-
the `Drop` trait provides a single method `drop`
3911-
that takes no parameters,
3912-
and is run when values of the type are dropped.
3913-
Such a method is called a "destructor",
3914-
and are always executed in "top-down" order:
3915-
a value is completely destroyed
3916-
before any of the values it owns run their destructors.
3917-
Only `Send` types can implement `Drop`.
3918-
3919-
* _Default_
3920-
: Types with destructors, closure environments,
3921-
and various other _non-first-class_ types,
3922-
are not copyable at all.
3923-
Such types can usually only be accessed through pointers,
3924-
or in some cases, moved between mutable locations.
3925-
3926-
Kinds can be supplied as _bounds_ on type parameters, like traits, in which
3927-
case the parameter is constrained to types satisfying that kind.
3928-
3929-
By default, type parameters do not carry any assumed kind-bounds at all. When
3930-
instantiating a type parameter, the kind bounds on the parameter are checked to
3931-
be the same or narrower than the kind of the type that it is instantiated with.
3932-
3933-
Sending operations are not part of the Rust language, but are implemented in
3934-
the library. Generic functions that send values bound the kind of these values
3935-
to sendable.
3936-
3937-
# Memory and concurrency models
3938-
3939-
Rust has a memory model centered around concurrently-executing _threads_. Thus
3940-
its memory model and its concurrency model are best discussed simultaneously,
3941-
as parts of each only make sense when considered from the perspective of the
3942-
other.
3943-
3944-
When reading about the memory model, keep in mind that it is partitioned in
3945-
order to support threads; and when reading about threads, keep in mind that their
3946-
isolation and communication mechanisms are only possible due to the ownership
3947-
and lifetime semantics of the memory model.
3948-
3949-
## Memory model
3950-
3951-
A Rust program's memory consists of a static set of *items*, a set of
3952-
[threads](#threads) each with its own *stack*, and a *heap*. Immutable portions of
3953-
the heap may be shared between threads, mutable portions may not.
3814+
# The `Copy` trait
3815+
3816+
Rust has a special trait, `Copy`, which when implemented changes the semantics
3817+
of a value. Values whose type implements `Copy` are copied rather than moved
3818+
upon assignment.
3819+
3820+
# The `Sized` trait
3821+
3822+
`Sized` is a special trait which indicates that the size of this type is known
3823+
at compile-time.
3824+
3825+
# The `Drop` trait
3826+
3827+
The `Drop` trait provides a destructor, to be run whenever a value of this type
3828+
is to be destroyed.
3829+
3830+
# Memory model
3831+
3832+
A Rust program's memory consists of a static set of *items* and a *heap*.
3833+
Immutable portions of the heap may be shared between threads, mutable portions
3834+
may not.
39543835

39553836
Allocations in the stack consist of *slots*, and allocations in the heap
39563837
consist of *boxes*.
@@ -3961,36 +3842,18 @@ The _items_ of a program are those functions, modules and types that have their
39613842
value calculated at compile-time and stored uniquely in the memory image of the
39623843
rust process. Items are neither dynamically allocated nor freed.
39633844

3964-
A thread's _stack_ consists of activation frames automatically allocated on entry
3965-
to each function as the thread executes. A stack allocation is reclaimed when
3966-
control leaves the frame containing it.
3967-
39683845
The _heap_ is a general term that describes boxes. The lifetime of an
39693846
allocation in the heap depends on the lifetime of the box values pointing to
39703847
it. Since box values may themselves be passed in and out of frames, or stored
39713848
in the heap, heap allocations may outlive the frame they are allocated within.
39723849

39733850
### Memory ownership
39743851

3975-
A thread owns all memory it can *safely* reach through local variables, as well
3976-
as boxes and references.
3977-
3978-
When a thread sends a value that has the `Send` trait to another thread, it loses
3979-
ownership of the value sent and can no longer refer to it. This is statically
3980-
guaranteed by the combined use of "move semantics", and the compiler-checked
3981-
_meaning_ of the `Send` trait: it is only instantiated for (transitively)
3982-
sendable kinds of data constructor and pointers, never including references.
3983-
39843852
When a stack frame is exited, its local allocations are all released, and its
39853853
references to boxes are dropped.
39863854

3987-
When a thread finishes, its stack is necessarily empty and it therefore has no
3988-
references to any boxes; the remainder of its heap is immediately freed.
3989-
39903855
### Memory slots
39913856

3992-
A thread's stack contains slots.
3993-
39943857
A _slot_ is a component of a stack frame, either a function parameter, a
39953858
[temporary](#lvalues,-rvalues-and-temporaries), or a local variable.
39963859

@@ -4020,86 +3883,6 @@ state. Subsequent statements within a function may or may not initialize the
40203883
local variables. Local variables can be used only after they have been
40213884
initialized; this is enforced by the compiler.
40223885

4023-
### Boxes
4024-
4025-
A _box_ is a reference to a heap allocation holding another value, which is
4026-
constructed by the prefix operator `box`. When the standard library is in use,
4027-
the type of a box is `std::owned::Box<T>`.
4028-
4029-
An example of a box type and value:
4030-
4031-
```
4032-
let x: Box<i32> = Box::new(10);
4033-
```
4034-
4035-
Box values exist in 1:1 correspondence with their heap allocation, copying a
4036-
box value makes a shallow copy of the pointer. Rust will consider a shallow
4037-
copy of a box to move ownership of the value. After a value has been moved,
4038-
the source location cannot be used unless it is reinitialized.
4039-
4040-
```
4041-
let x: Box<i32> = Box::new(10);
4042-
let y = x;
4043-
// attempting to use `x` will result in an error here
4044-
```
4045-
4046-
## Threads
4047-
4048-
Rust's primary concurrency mechanism is called a **thread**.
4049-
4050-
### Communication between threads
4051-
4052-
Rust threads are isolated and generally unable to interfere with one another's
4053-
memory directly, except through [`unsafe` code](#unsafe-functions). All
4054-
contact between threads is mediated by safe forms of ownership transfer, and data
4055-
races on memory are prohibited by the type system.
4056-
4057-
When you wish to send data between threads, the values are restricted to the
4058-
[`Send` type-kind](#type-kinds). Restricting communication interfaces to this
4059-
kind ensures that no references move between threads. Thus access to an entire
4060-
data structure can be mediated through its owning "root" value; no further
4061-
locking or copying is required to avoid data races within the substructure of
4062-
such a value.
4063-
4064-
### Thread
4065-
4066-
The _lifecycle_ of a threads consists of a finite set of states and events that
4067-
cause transitions between the states. The lifecycle states of a thread are:
4068-
4069-
* running
4070-
* blocked
4071-
* panicked
4072-
* dead
4073-
4074-
A thread begins its lifecycle &mdash; once it has been spawned &mdash; in the
4075-
*running* state. In this state it executes the statements of its entry
4076-
function, and any functions called by the entry function.
4077-
4078-
A thread may transition from the *running* state to the *blocked* state any time
4079-
it makes a blocking communication call. When the call can be completed &mdash;
4080-
when a message arrives at a sender, or a buffer opens to receive a message
4081-
&mdash; then the blocked thread will unblock and transition back to *running*.
4082-
4083-
A thread may transition to the *panicked* state at any time, due being killed by
4084-
some external event or internally, from the evaluation of a `panic!()` macro.
4085-
Once *panicking*, a thread unwinds its stack and transitions to the *dead* state.
4086-
Unwinding the stack of a thread is done by the thread itself, on its own control
4087-
stack. If a value with a destructor is freed during unwinding, the code for the
4088-
destructor is run, also on the thread's control stack. Running the destructor
4089-
code causes a temporary transition to a *running* state, and allows the
4090-
destructor code to cause any subsequent state transitions. The original thread
4091-
of unwinding and panicking thereby may suspend temporarily, and may involve
4092-
(recursive) unwinding of the stack of a failed destructor. Nonetheless, the
4093-
outermost unwinding activity will continue until the stack is unwound and the
4094-
thread transitions to the *dead* state. There is no way to "recover" from thread
4095-
panics. Once a thread has temporarily suspended its unwinding in the *panicking*
4096-
state, a panic occurring from within this destructor results in *hard* panic.
4097-
A hard panic currently results in the process aborting.
4098-
4099-
A thread in the *dead* state cannot transition to other states; it exists only to
4100-
have its termination status inspected by other threads, and/or to await
4101-
reclamation when the last reference to it drops.
4102-
41033886
# Runtime services, linkage and debugging
41043887

41053888
The Rust _runtime_ is a relatively compact collection of Rust code that

0 commit comments

Comments
 (0)