]> git.proxmox.com Git - rustc.git/blame - src/doc/reference/src/glossary.md
New upstream version 1.41.1+dfsg1
[rustc.git] / src / doc / reference / src / glossary.md
CommitLineData
3b2f2976
XL
1# Glossary
2
532ac7d7 3### Abstract syntax tree
3b2f2976
XL
4
5An ‘abstract syntax tree’, or ‘AST’, is an intermediate representation of
6the structure of the program when the compiler is compiling it.
7
ff7c6d11
XL
8### Alignment
9
10The alignment of a value specifies what addresses values are preferred to
11start at. Always a power of two. References to a value must be aligned.
12[More][alignment].
13
3b2f2976
XL
14### Arity
15
ff7c6d11
XL
16Arity refers to the number of arguments a function or operator takes.
17For some examples, `f(2, 3)` and `g(4, 6)` have arity 2, while `h(8, 2, 6)`
18has arity 3. The `!` operator has arity 1.
3b2f2976
XL
19
20### Array
21
22An array, sometimes also called a fixed-size array or an inline array, is a value
23describing a collection of elements, each selected by an index that can be computed
24at run time by the program. It occupies a contiguous region of memory.
25
532ac7d7 26### Associated item
ff7c6d11
XL
27
28An associated item is an item that is associated with another item. Associated
532ac7d7
XL
29items are defined in [implementations] and declared in [traits]. Only
30functions, constants, and type aliases can be associated. Contrast to a [free
31item].
ff7c6d11 32
60c5eb7d
XL
33### Blanket implementation
34
35Any implementation where a type appears [uncovered](#uncovered-type). `impl<T> Foo
36for T`, `impl<T> Bar<T> for T`, `impl<T> Bar<Vec<T>> for T`, and `impl<T> Bar<T>
37for Vec<T>` are considered blanket impls. However, `impl<T> Bar<Vec<T>> for
38Vec<T>` is not a blanket impl, as all instances of `T` which appear in this `impl`
39are covered by `Vec`.
40
3b2f2976
XL
41### Bound
42
43Bounds are constraints on a type or trait. For example, if a bound
44is placed on the argument a function takes, types passed to that function
45must abide by that constraint.
46
47### Combinator
48
49Combinators are higher-order functions that apply only functions and
abe05a73 50earlier defined combinators to provide a result from its arguments.
3b2f2976
XL
51They can be used to manage control flow in a modular fashion.
52
53### Dispatch
54
55Dispatch is the mechanism to determine which specific version of code is actually
56run when it involves polymorphism. Two major forms of dispatch are static dispatch and
57dynamic dispatch. While Rust favors static dispatch, it also supports dynamic dispatch
58through a mechanism called ‘trait objects’.
59
532ac7d7 60### Dynamically sized type
3b2f2976 61
abe05a73 62A dynamically sized type (DST) is a type without a statically known size or alignment.
3b2f2976
XL
63
64### Expression
65
abe05a73 66An expression is a combination of values, constants, variables, operators
3b2f2976
XL
67and functions that evaluate to a single value, with or without side-effects.
68
69For example, `2 + (3 * 4)` is an expression that returns the value 14.
70
532ac7d7
XL
71### Free item
72
73An [item] that is not a member of an [implementation], such as a *free
74function* or a *free const*. Contrast to an [associated item].
75
60c5eb7d
XL
76### Fundamental traits
77
78A fundamental trait is one where adding an impl of it for an existing type is a breaking change.
79The `Fn` traits and `Sized` are fundamental.
80
81### Fundamental type constructors
82
83A fundamental type constructor is a type where implementing a [blanket implementation](#blanket-implementation) over it
84is a breaking change. `&`, `&mut`, `Box`, and `Pin` are fundamental.
85
86Any time a type `T` is considered [local](#local-type), `&T`, `&mut T`, `Box<T>`, and `Pin<T>`
87are also considered local. Fundamental type constructors cannot [cover](#uncovered-type) other types.
88Any time the term "covered type" is used,
89the `T` in `&T`, `&mut T`, `Box<T>`, and `Pin<T>` is not considered covered.
90
e74abb32
XL
91### Inhabited
92
93A type is inhabited if it has constructors and therefore can be instantiated. An inhabited type is
94not "empty" in the sense that there can be values of the type. Opposite of
95[Uninhabited](#uninhabited).
96
532ac7d7
XL
97### Inherent implementation
98
99An [implementation] that applies to a nominal type, not to a trait-type pair.
100[More][inherent implementation].
101
102### Inherent method
103
104A [method] defined in an [inherent implementation], not in a trait
105implementation.
106
abe05a73
XL
107### Initialized
108
109A variable is initialized if it has been assigned a value and hasn't since been
532ac7d7 110moved from. All other memory locations are assumed to be uninitialized. Only
ff7c6d11
XL
111unsafe Rust can create such a memory without initializing it.
112
60c5eb7d
XL
113### Local trait
114
115A `trait` which was defined in the current crate. A trait definition is local
116or not independent of applied type arguments. Given `trait Foo<T, U>`,
117`Foo` is always local, regardless of the types substituted for `T` and `U`.
118
119### Local type
120
121A `struct`, `enum`, or `union` which was defined in the current crate.
122This is not affected by applied type arguments. `struct Foo` is considered local, but
123`Vec<Foo>` is not. `LocalType<ForeignType>` is local. Type aliases do not
124affect locality.
125
532ac7d7 126### Nominal types
ff7c6d11
XL
127
128Types that can be referred to by a path directly. Specifically [enums],
129[structs], [unions], and [trait objects].
130
532ac7d7 131### Object safe traits
ff7c6d11 132
2c00a5a8 133[Traits] that can be used as [trait objects]. Only traits that follow specific
8faf50e0 134[rules][object safety] are object safe.
abe05a73 135
3b2f2976
XL
136### Prelude
137
138Prelude, or The Rust Prelude, is a small collection of items - mostly traits - that are
2c00a5a8 139imported into every module of every crate. The traits in the prelude are pervasive.
3b2f2976 140
9fa01778
XL
141### Scrutinee
142
143A scrutinee is the expression that is matched on in `match` expressions and
144similar pattern matching constructs. For example, in `match x { A => 1, B => 2 }`,
145the expression `x` is the scrutinee.
146
ff7c6d11
XL
147### Size
148
149The size of a value has two definitions.
150
151The first is that it is how much memory must be allocated to store that value.
152
153The second is that it is the offset in bytes between successive elements in an
154array with that item type.
155
156It is a multiple of the alignment, including zero. The size can change
157depending on compiler version (as new optimizations are made) and target
158platform (similar to how `usize` varies per-platform).
159
160[More][alignment].
161
3b2f2976
XL
162### Slice
163
abe05a73 164A slice is dynamically-sized view into a contiguous sequence, written as `[T]`.
3b2f2976 165
abe05a73 166It is often seen in its borrowed forms, either mutable or shared. The shared
3b2f2976
XL
167slice type is `&[T]`, while the mutable slice type is `&mut [T]`, where `T` represents
168the element type.
169
170### Statement
171
172A statement is the smallest standalone element of a programming language
173that commands a computer to perform an action.
174
175### String literal
176
abe05a73
XL
177A string literal is a string stored directly in the final binary, and so will be
178valid for the `'static` duration.
3b2f2976
XL
179
180Its type is `'static` duration borrowed string slice, `&'static str`.
181
182### String slice
183
184A string slice is the most primitive string type in Rust, written as `str`. It is
185often seen in its borrowed forms, either mutable or shared. The shared
186string slice type is `&str`, while the mutable string slice type is `&mut str`.
187
188Strings slices are always valid UTF-8.
189
190### Trait
191
192A trait is a language item that is used for describing the functionalities a type must provide.
ff7c6d11
XL
193It allows a type to make certain promises about its behavior.
194
195Generic functions and generic structs can use traits to constrain, or bound, the types they accept.
196
60c5eb7d
XL
197### Uncovered type
198
199A type which does not appear as an argument to another type. For example,
200`T` is uncovered, but the `T` in `Vec<T>` is covered. This is only relevant for
201type arguments.
202
532ac7d7
XL
203### Undefined behavior
204
205Compile-time or run-time behavior that is not specified. This may result in,
206but is not limited to: process termination or corruption; improper, incorrect,
207or unintended computation; or platform-specific results.
208[More][undefined-behavior].
209
e74abb32
XL
210### Uninhabited
211
212A type is uninhabited if it has no constructors and therefore can never be instantiated. An
213uninhabited type is "empty" in the sense that there are no values of the type. The canonical
214example of an uninhabited type is the [never type] `!`, or an enum with no variants
215`enum Never { }`. Opposite of [Inhabited](#inhabited).
216
416331ca 217[alignment]: type-layout.md#size-and-alignment
532ac7d7 218[associated item]: #associated-item
416331ca 219[enums]: items/enumerations.md
532ac7d7 220[free item]: #free-item
416331ca
XL
221[implementation]: items/implementations.md
222[implementations]: items/implementations.md
223[inherent implementation]: items/implementations.md#inherent-implementations
224[item]: items.md
225[method]: items/associated-items.md#methods
e74abb32 226[never type]: types/never.md
416331ca
XL
227[object safety]: items/traits.md#object-safety
228[structs]: items/structs.md
229[trait objects]: types/trait-object.md
230[traits]: items/traits.md
231[undefined-behavior]: behavior-considered-undefined.md
232[unions]: items/unions.md