Skip to content

Commit 89059b2

Browse files
committed
Split Types Chapter
This splits the types chapter into multiple subchapters. I tried to avoid content changes, but I ended up with a few changes: - Added overview links in `types.md`, and a separate discussion of type expressions. - Split array and slice into separate chapters. Although there is some overlap between them, I feel like it was awkward explaining one and then the other. I also felt it conflated the two too much since slices can be used for more than arrays. - Combined `Self` section with the one on the paths page. - Added a basic redirector for external links. Some pages may seem a little bare now, but I think each type page has potential to be expanded and improved in the future.
1 parent f87f140 commit 89059b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1010
-905
lines changed

src/SUMMARY.md

+15
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@
6767

6868
- [Type system](type-system.md)
6969
- [Types](types.md)
70+
- [Boolean type](types/boolean.md)
71+
- [Numeric types](types/numeric.md)
72+
- [Textual types](types/textual.md)
73+
- [Tuple types](types/tuple.md)
74+
- [Array types](types/array.md)
75+
- [Slice types](types/slice.md)
76+
- [Struct types](types/struct.md)
77+
- [Enumerated types](types/enum.md)
78+
- [Union types](types/union.md)
79+
- [Function item types](types/function-item.md)
80+
- [Closure types](types/closure.md)
81+
- [Pointer types](types/pointer.md)
82+
- [Function pointer types](types/function-pointer.md)
83+
- [Trait object types](types/trait-object.md)
84+
- [Impl trait type](types/impl-trait.md)
7085
- [Dynamically Sized Types](dynamically-sized-types.md)
7186
- [Type layout](type-layout.md)
7287
- [Interior mutability](interior-mutability.md)

src/const_eval.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ A _const context_ is one of the following:
5151
* [statics]
5252
* [enum discriminants]
5353

54-
[array type length expressions]: types.html#array-and-slice-types
54+
[array type length expressions]: types/array.html
5555
[enum discriminants]: items/enumerations.html#custom-discriminant-values-for-field-less-enumerations
5656
[constants]: items/constant-items.html
5757
[statics]: items/static-items.html
@@ -68,7 +68,7 @@ A _const context_ is one of the following:
6868
[block expressions]: expressions/block-expr.html
6969
[field]: expressions/field-expr.html
7070
[array indexing]: expressions/array-expr.html#array-and-slice-indexing-expressions
71-
[slice]: types.html#array-and-slice-types
71+
[slice]: types/slice.html
7272
[range expressions]: expressions/range-expr.html
7373
[closure expressions]: expressions/closure-expr.html
7474
[negation]: expressions/operator-expr.html#negation-operators

src/crates-and-source-files.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn main() {
111111
[module]: items/modules.html
112112
[module path]: paths.html
113113
[attributes]: attributes.html
114-
[unit]: types.html#tuple-types
114+
[unit]: types/tuple.html
115115
[_InnerAttribute_]: attributes.html
116116
[_Item_]: items.html
117117
[_shebang_]: https://en.wikipedia.org/wiki/Shebang_(Unix)

src/destructors.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ variable or field from being dropped automatically.
8282
[Assignment]: expressions/operator-expr.html#assignment-expressions
8383
[`std::ops::Drop::drop`]: ../std/ops/trait.Drop.html
8484
[RFC 1857]: https://github.com/rust-lang/rfcs/blob/master/text/1857-stabilize-drop-order.md
85-
[struct]: types.html#struct-types
86-
[tuple]: types.html#tuple-types
87-
[enum variant]: types.html#enumerated-types
88-
[array]: types.html#array-and-slice-types
89-
[closure]: types.html#closure-types
90-
[Trait objects]: types.html#trait-objects
85+
[struct]: types/struct.html
86+
[tuple]: types/tuple.html
87+
[enum variant]: types/enum.html
88+
[array]: types/array.html
89+
[closure]: types/closure.html
90+
[Trait objects]: types/trait-object.html
9191
[`std::ptr::drop_in_place`]: ../std/ptr/fn.drop_in_place.html
9292
[`std::mem::forget`]: ../std/mem/fn.forget.html
9393
[`std::mem::ManuallyDrop`]: ../std/mem/struct.ManuallyDrop.html

src/dynamically-sized-types.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ Notably: [variables], function parameters, [const] and [static] items must be
2424
`Sized`.
2525

2626
[sized]: special-types-and-traits.html#sized
27-
[Slices]: types.html#array-and-slice-types
28-
[trait objects]: types.html#trait-objects
29-
[Pointer types]: types.html#pointer-types
27+
[Slices]: types/slice.html
28+
[trait objects]: types/trait-object.html
29+
[Pointer types]: types/pointer.html
3030
[variables]: variables.html
3131
[const]: items/constant-items.html
3232
[static]: items/static-items.html

src/expressions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ exist in `core::ops` and `core::cmp` with the same names.
277277
[let statement]: statements.html#let-statements
278278
[Mutable `static` items]: items/static-items.html#mutable-statics
279279
[const contexts]: const_eval.html
280-
[slice]: types.html#array-and-slice-types
280+
[slice]: types/slice.html
281281
[static variables]: items/static-items.html
282282
[Temporary values]: #temporary-lifetimes
283283
[Variables]: variables.html

src/expressions/array-expr.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
> &nbsp;&nbsp; | `[` [_Expression_] ( `,` [_Expression_] )<sup>\*</sup> `,`<sup>?</sup> `]`\
99
> &nbsp;&nbsp; | `[` [_Expression_] `;` [_Expression_] `]`
1010
11-
An _[array](types.html#array-and-slice-types) expression_ can be written by
11+
An _[array](types/array.html) expression_ can be written by
1212
enclosing zero or more comma-separated expressions of uniform type in square
1313
brackets. This produces and array containing each of these values in the
1414
order they are written.
@@ -36,7 +36,7 @@ greater than 1 then this requires that the type of `a` is
3636
> _IndexExpression_ :\
3737
> &nbsp;&nbsp; [_Expression_] `[` [_Expression_] `]`
3838
39-
[Array and slice](types.html#array-and-slice-types)-typed expressions can be
39+
[Array](types/array.html) and [slice](types/slice.html)-typed expressions can be
4040
indexed by writing a square-bracket-enclosed expression of type `usize` (the
4141
index) after them. When the array is mutable, the resulting [memory location]
4242
can be assigned to.

src/expressions/call-expr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
A _call expression_ consists of an expression followed by a parenthesized
1111
expression-list. It invokes a function, providing zero or more input variables.
1212
If the function eventually returns, then the expression completes. For
13-
[non-function types](types.html#function-item-types), the expression f(...) uses
13+
[non-function types](types/function-item.html), the expression f(...) uses
1414
the method on one of the [`std::ops::Fn`], [`std::ops::FnMut`] or
1515
[`std::ops::FnOnce`] traits, which differ in whether they take the type by
1616
reference, mutable reference, or take ownership respectively. An automatic

src/expressions/closure-expr.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ functions, as an abbreviation for defining and capturing a separate function.
2525

2626
Significantly, closure expressions _capture their environment_, which regular
2727
[function definitions] do not. Without the `move` keyword, the closure expression
28-
[infers how it captures each variable from its environment](types.html#capture-modes),
28+
[infers how it captures each variable from its environment](types/closure.html#capture-modes),
2929
preferring to capture by shared reference, effectively borrowing
3030
all outer variables mentioned inside the closure's body. If needed the compiler
3131
will infer that instead mutable references should be taken, or that the values
@@ -35,7 +35,7 @@ prefixing it with the `move` keyword. This is often used to ensure that the
3535
closure's type is `'static`.
3636

3737
The compiler will determine which of the [closure
38-
traits](types.html#call-traits-and-coercions) the closure's type will implement by how it
38+
traits](types/closure.html#call-traits-and-coercions) the closure's type will implement by how it
3939
acts on its captured variables. The closure will also implement
4040
[`Send`](special-types-and-traits.html#send) and/or
4141
[`Sync`](special-types-and-traits.html#sync) if all of its captured types do.
@@ -67,5 +67,5 @@ ten_times(move |j| println!("{}, {}", word, j));
6767

6868
[_Expression_]: expressions.html
6969
[_BlockExpression_]: expressions/block-expr.html
70-
[_TypeNoBounds_]: types.html
70+
[_TypeNoBounds_]: types.html#type-expressions
7171
[_FunctionParameters_]: items/functions.html

src/expressions/loop-expr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ A `loop` expression repeats execution of its body continuously:
3737
`loop { println!("I live."); }`.
3838

3939
A `loop` expression without an associated `break` expression is diverging and
40-
has type [`!`](types.html#never-type). A `loop` expression containing
40+
has type [`!`](types/never.html). A `loop` expression containing
4141
associated [`break` expression(s)](#break-expressions) may terminate, and must
4242
have type compatible with the value of the `break` expression(s).
4343

src/expressions/method-call-expr.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dot, an expression path segment, and a parenthesized expression-list. Method cal
99
resolved to associated [methods] on specific traits, either statically
1010
dispatching to a method if the exact `self`-type of the left-hand-side is known,
1111
or dynamically dispatching if the left-hand-side expression is an indirect
12-
[trait object](types.html#trait-objects).
12+
[trait object](types/trait-object.html).
1313

1414
```rust
1515
let pi: Result<f32, _> = "3.14".parse();
@@ -101,8 +101,8 @@ method and you'll be fine.
101101
[_Expression_]: expressions.html
102102
[_PathExprSegment_]: paths.html#paths-in-expressions
103103
[visible]: visibility-and-privacy.html
104-
[array]: types.html#array-and-slice-types
105-
[trait objects]: types.html#trait-objects
104+
[array]: types/array.html
105+
[trait objects]: types/trait-object.html
106106
[disambiguate call]: expressions/call-expr.html#disambiguating-function-calls
107107
[disambiguating function call syntax]: expressions/call-expr.html#disambiguating-function-calls
108108
[dereference]: expressions/operator-expr.html#the-dereference-operator

src/expressions/operator-expr.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ let a = & & & & mut 10;
8585
> &nbsp;&nbsp; `*` [_Expression_]
8686
8787
The `*` (dereference) operator is also a unary prefix operator. When applied to
88-
a [pointer](types.html#pointer-types) it denotes the pointed-to location. If
88+
a [pointer](types/pointer.html) it denotes the pointed-to location. If
8989
the expression is of type `&mut T` and `*mut T`, and is either a local
9090
variable, a (nested) field of a local variable or is a mutable [place
9191
expression], then the resulting memory location can be assigned to.
@@ -345,7 +345,7 @@ well as the following additional casts. Here `*T` means either `*const T` or
345345
| `*T` where `T: Sized` | Numeric type | Pointer to address cast |
346346
| Integer type | `*V` where `V: Sized` | Address to pointer cast |
347347
| `&[T; n]` | `*const T` | Array to pointer cast |
348-
| [Function pointer](types.html#function-pointer-types) | `*V` where `V: Sized` | Function pointer to pointer cast |
348+
| [Function pointer](types/function-pointer.html) | `*V` where `V: Sized` | Function pointer to pointer cast |
349349
| Function pointer | Integer | Function pointer to address cast |
350350
| Closure \*\* | Function pointer | Closure to function pointer cast |
351351

@@ -446,7 +446,7 @@ assert_eq!(x, 14);
446446
[temporary value]: expressions.html#temporary-lifetimes
447447
[float-int]: https://github.com/rust-lang/rust/issues/10184
448448
[float-float]: https://github.com/rust-lang/rust/issues/15536
449-
[`unit` type]: types.html#tuple-types
449+
[`unit` type]: types/tuple.html
450450

451451
[_BorrowExpression_]: #borrow-operators
452452
[_DereferenceExpression_]: #the-dereference-operator
@@ -460,4 +460,4 @@ assert_eq!(x, 14);
460460
[_CompoundAssignmentExpression_]: #compound-assignment-expressions
461461

462462
[_Expression_]: expressions.html
463-
[_TypeNoBounds_]: types.html
463+
[_TypeNoBounds_]: types.html#type-expressions

src/expressions/tuple-expr.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
> &nbsp;&nbsp; | `(` ( [_Expression_] `,` )<sup>+</sup> [_Expression_]<sup>?</sup> `)`
99
1010
Tuples are written by enclosing zero or more comma-separated expressions in
11-
parentheses. They are used to create [tuple-typed](types.html#tuple-types)
11+
parentheses. They are used to create [tuple-typed](types/tuple.html)
1212
values.
1313

1414
```rust
@@ -31,7 +31,7 @@ comma:
3131
> _TupleIndexingExpression_ :\
3232
> &nbsp;&nbsp; [_Expression_] `.` [TUPLE_INDEX]
3333
34-
[Tuples](types.html#tuple-types) and [struct tuples](items/structs.html) can be
34+
[Tuples](types/tuple.html) and [struct tuples](items/structs.html) can be
3535
indexed using the number corresponding to the position of the field. The index
3636
must be written as a [decimal literal](tokens.html#integer-literals) with no
3737
underscores or suffix. Tuple indexing expressions also differ from field

src/glossary.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Generic functions and generic structs can use traits to constrain, or bound, the
134134
[enums]: items/enumerations.html
135135
[structs]: items/structs.html
136136
[unions]: items/unions.html
137-
[trait objects]: types.html#trait-objects
137+
[trait objects]: types/trait-object.html
138138
[implementations]: items/implementations.html
139139
[traits]: items/traits.html
140140
[object safety]: items/traits.html#object-safety

src/interior-mutability.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ borrow checks to ensure the usual rules around multiple references. The
2020
accessed with atomic operations, allowing the value to be shared and mutated
2121
across threads.
2222

23-
[shared reference]: types.html#shared-references-
23+
[shared reference]: types/pointer.html#shared-references-
2424
[ub]: behavior-considered-undefined.html
2525
[`std::mem::transmute`]: ../std/mem/fn.transmute.html
2626
[`std::cell::UnsafeCell<T>`]: ../std/cell/struct.UnsafeCell.html

src/items/associated-items.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -292,20 +292,20 @@ fn main() {
292292
[_FunctionReturnType_]: items/functions.html
293293
[_Generics_]: items/generics.html
294294
[_Lifetime_]: trait-bounds.html
295-
[_Type_]: types.html
295+
[_Type_]: types.html#type-expressions
296296
[_WhereClause_]: items/generics.html#where-clauses
297297
[trait]: items/traits.html
298298
[traits]: items/traits.html
299299
[type aliases]: items/type-aliases.html
300300
[inherent implementations]: items/implementations.html#inherent-implementations
301301
[identifier]: identifiers.html
302-
[trait object]: types.html#trait-objects
302+
[trait object]: types/trait-object.html
303303
[implementations]: items/implementations.html
304-
[type]: types.html
304+
[type]: types.html#type-expressions
305305
[constants]: items/constant-items.html
306306
[constant item]: items/constant-items.html
307307
[functions]: items/functions.html
308-
[function item]: types.html#function-item-types
308+
[function item]: types/function-item.html
309309
[method call operator]: expressions/method-call-expr.html
310310
[block]: expressions/block-expr.html
311311
[path]: paths.html

src/items/constant-items.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ fn create_and_drop_zero_with_destructor() {
6464
[static lifetime elision]: lifetime-elision.html#static-lifetime-elision
6565
[`Drop`]: special-types-and-traits.html#drop
6666
[IDENTIFIER]: identifiers.html
67-
[_Type_]: types.html
67+
[_Type_]: types.html#type-expressions
6868
[_Expression_]: expressions.html

src/items/enumerations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ enum ZeroVariants {}
137137
[_Expression_]: expressions.html
138138
[_TupleFields_]: items/structs.html
139139
[_StructFields_]: items/structs.html
140-
[enumerated type]: types.html#enumerated-types
140+
[enumerated type]: types/enum.html
141141
[`mem::discriminant`]: ../std/mem/fn.discriminant.html
142142
[numeric cast]: expressions/operator-expr.html#semantics
143143
[`repr` attribute]: attributes.html#ffi-attributes

src/items/external-blocks.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ block.
118118
[_Generics_]: items/generics.html
119119
[_InnerAttribute_]: attributes.html
120120
[_OuterAttribute_]: attributes.html
121-
[_Type_]: types.html
121+
[_Type_]: types.html#type-expressions
122122
[_Visibility_]: visibility-and-privacy.html
123123
[_WhereClause_]: items/generics.html#where-clauses
124124
[attributes]: attributes.html#ffi-attributes

src/items/functions.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ attributes].
220220
[_InnerAttribute_]: attributes.html
221221
[_Pattern_]: patterns.html
222222
[_Statement_]: statements.html
223-
[_Type_]: types.html
223+
[_Type_]: types.html#type-expressions
224224
[_WhereClause_]: items/generics.html#where-clauses
225225
[const contexts]: const_eval.html
226226
[external blocks]: items/external-blocks.html
227227
[path]: paths.html
228228
[block]: expressions/block-expr.html
229229
[variables]: variables.html
230-
[type]: types.html
231-
[*function item type*]: types.html#function-item-types
230+
[type]: types.html#type-expressions
231+
[*function item type*]: types/function-item.html
232232
[Trait]: items/traits.html
233233
[attributes]: attributes.html
234234
[`cfg`]: conditional-compilation.html

src/items/generics.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,16 @@ generic parameter.
106106
[_LifetimeBounds_]: trait-bounds.html
107107
[_Lifetime_]: trait-bounds.html
108108
[_OuterAttribute_]: attributes.html
109-
[_Type_]: types.html
109+
[_Type_]: types.html#type-expressions
110110
[_TypeParamBounds_]: trait-bounds.html
111111

112-
[arrays]: types.html#array-and-slice-types
113-
[function pointers]: types.html#function-pointer-types
114-
[references]: types.html#shared-references-
115-
[raw pointers]: types.html#raw-pointers-const-and-mut
112+
[arrays]: types/array.html
113+
[function pointers]: types/function-pointer.html
114+
[references]: types/pointer.html#shared-references-
115+
[raw pointers]: types/pointer.html#raw-pointers-const-and-mut
116116
[`Clone`]: special-types-and-traits.html#clone
117117
[`Copy`]: special-types-and-traits.html#copy
118118
[`Sized`]: special-types-and-traits.html#sized
119-
[tuples]: types.html#tuple-types
120-
[trait object]: types.html#trait-objects
119+
[tuples]: types/tuple.html
120+
[trait object]: types/trait-object.html
121121
[attributes]: attributes.html

src/items/implementations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ attributes].
184184
[_OuterAttribute_]: attributes.html
185185
[_TypeAlias_]: items/type-aliases.html
186186
[_TypePath_]: paths.html#paths-in-types
187-
[_Type_]: types.html
187+
[_Type_]: types.html#type-expressions
188188
[_Visibility_]: visibility-and-privacy.html
189189
[_WhereClause_]: items/generics.html#where-clauses
190190
[trait]: items/traits.html

src/items/static-items.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ following are true:
7373
[constant expression]: const_eval.html#constant-expressions
7474
[interior mutable]: interior-mutability.html
7575
[IDENTIFIER]: identifiers.html
76-
[_Type_]: types.html
76+
[_Type_]: types.html#type-expressions
7777
[_Expression_]: expressions.html

src/items/structs.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ let px: i32 = p.x;
4949
A _tuple struct_ is a nominal [tuple type], also defined with the keyword
5050
`struct`. For example:
5151

52-
[struct type]: types.html#struct-types
53-
[tuple type]: types.html#tuple-types
52+
[struct type]: types/struct.html
53+
[tuple type]: types/tuple.html
5454

5555
```rust
5656
struct Point(i32, i32);
@@ -85,4 +85,4 @@ particular layout using the [`repr` attribute].
8585
[_Generics_]: items/generics.html
8686
[_WhereClause_]: items/generics.html#where-clauses
8787
[_Visibility_]: visibility-and-privacy.html
88-
[_Type_]: types.html
88+
[_Type_]: types.html#type-expressions

src/items/traits.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ trait T {
209209
[_Pattern_]: patterns.html
210210
[_SelfParam_]: items/associated-items.html#methods
211211
[_TypeParamBounds_]: trait-bounds.html
212-
[_Type_]: types.html
212+
[_Type_]: types.html#type-expressions
213213
[_WhereClause_]: items/generics.html#where-clauses
214214
[bounds]: trait-bounds.html
215-
[trait object]: types.html#trait-objects
215+
[trait object]: types/trait-object.html
216216
[explicit]: expressions/operator-expr.html#type-cast-expressions
217217
[RFC 255]: https://github.com/rust-lang/rfcs/blob/master/text/0255-object-safety.md
218218
[associated items]: items/associated-items.html

src/items/type-aliases.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ let _: F = E::A; // OK
3232
[IDENTIFIER]: identifiers.html
3333
[_Generics_]: items/generics.html
3434
[_WhereClause_]: items/generics.html#where-clauses
35-
[_Type_]: types.html
35+
[_Type_]: types.html#type-expressions

src/keywords.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,4 @@ is possible to declare a variable or method with the name `union`.
126126
[Crates]: crates-and-source-files.html
127127
[union]: items/unions.html
128128
[variants]: items/enumerations.html
129-
[`dyn`]: types.html#trait-objects
129+
[`dyn`]: types/trait-object.html

0 commit comments

Comments
 (0)