Skip to content

Commit 702b6e5

Browse files
committed
Introduces a "Syntax Index" chapter to TRPL.
The intent with this chapter is to have a central place where users can go to find out what a random bit of syntax means, be it a keyword, symbol, or some unusual bit of composite syntax (like `for <...>`). This should be useful both for new users (who may not know what to call this weird `'blah` thing), and for experienced users (who may just wish to link someone to the appropriate section on `Trait + Trait` bounds). Where possible, entries have been linked to an appropriate section of the book which explains the syntax. This was not possible in all cases. If an entry is missing links, that's because I was unable to *find* anything appropriate to link to. This commit should include all stable keywords, operators and symbols, as well as a selection of potentially confusing or unusual syntax.
1 parent 0f53643 commit 702b6e5

File tree

2 files changed

+227
-0
lines changed

2 files changed

+227
-0
lines changed

src/doc/trpl/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,5 @@
6969
* [Slice Patterns](slice-patterns.md)
7070
* [Associated Constants](associated-constants.md)
7171
* [Glossary](glossary.md)
72+
* [Syntax Index](syntax-index.md)
7273
* [Bibliography](bibliography.md)

src/doc/trpl/syntax-index.md

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
% Syntax Index
2+
3+
## Keywords
4+
5+
* `as`: primitive casting. See [Casting Between Types (`as`)].
6+
* `break`: break out of loop. See [Loops (Ending Iteration Early)].
7+
* `const`: constant items. See [`const` and `static`].
8+
* `continue`: continue to next loop iteration. See [Loops (Ending Iteration Early)].
9+
* `crate`: external crate linkage. See [Crates and Modules (Importing External Crates)].
10+
* `else`: fallback for `if` and `if let` constructs. See [`if`], [`if let`].
11+
* `enum`: defining enumeration. See [Enums].
12+
* `extern`: external crate, function, and variable linkage. See [Crates and Modules (Importing External Crates)], [Foreign Function Interface].
13+
* `false`: boolean false literal. See [Primitive Types (Booleans)].
14+
* `fn`: function definition and function pointer types. See [Functions].
15+
* `for`: iterator loop, part of trait `impl` syntax, and higher-ranked lifetime syntax. See [Loops (`for`)], [Method Syntax].
16+
* `if`: conditional branching. See [`if`], [`if let`].
17+
* `impl`: inherent and trait implementation blocks. See [Method Syntax].
18+
* `in`: part of `for` loop syntax. See [Loops (`for`)].
19+
* `let`: variable binding. See [Variable Bindings].
20+
* `loop`: unconditional, infinite loop. See [Loops (`loop`)].
21+
* `match`: pattern matching. See [Match].
22+
* `mod`: module declaration. See [Crates and Modules (Defining Modules)].
23+
* `move`: part of closure syntax. See [Closures (`move` closures)].
24+
* `mut`: denotes mutability in pointer types, pattern bindings, and `struct` fields. See [Mutability].
25+
* `pub`: denotes public visibility in `struct` fields, `impl` blocks, and modules. See [Crates and Modules (Exporting a Public Interface)].
26+
* `ref`: by-reference binding. See [Patterns (`ref` and `ref mut`)].
27+
* `return`: return from function. See [Functions (Early Returns)].
28+
* `Self`: implementer type alias. See [Traits].
29+
* `self`: method subject. See [Method Syntax (Method Calls)].
30+
* `static`: global variable. See [`const` and `static` (`static`)].
31+
* `struct`: structure definition. See [Structs].
32+
* `trait`: trait definition. See [Traits].
33+
* `true`: boolean true literal. See [Primitive Types (Booleans)].
34+
* `type`: type alias, and associated type definition. See [`type` Aliases], [Associated Types].
35+
* `unsafe`: denotes unsafe code, functions, traits, and implementations. See [Unsafe].
36+
* `use`: import symbols into scope. See [Crates and Modules (Importing Modules with `use`)].
37+
* `where`: type constraint clauses. See [Traits (`where` clause)].
38+
* `while`: conditional loop. See [Loops (`while`)].
39+
40+
## Operators and Symbols
41+
42+
* `!` (`expr!(…)`, `expr!{…}`, `expr![…]`): denotes macro expansion. See [Macros].
43+
* `!` (`!expr`): bitwise or logical complement. Overloadable (`Not`).
44+
* `%` (`expr % expr`): arithmetic remainder. Overloadable (`Rem`).
45+
* `%=` (`var %= expr`): arithmetic remainder & assignment.
46+
* `&` (`expr & expr`): bitwise and. Overloadable (`BitAnd`).
47+
* `&` (`&expr`): borrow. See [References and Borrowing].
48+
* `&` (`&type`, `&mut type`, `&'a type`, `&'a mut type`): borrowed pointer type. See [References and Borrowing].
49+
* `&=` (`var &= expr`): bitwise and & assignment.
50+
* `&&` (`expr && expr`): logical and.
51+
* `*` (`expr * expr`): arithmetic multiplication. Overloadable (`Mul`).
52+
* `*` (`*expr`): dereference.
53+
* `*` (`*const type`, `*mut type`): raw pointer. See [Raw Pointers].
54+
* `*=` (`var *= expr`): arithmetic multiplication & assignment.
55+
* `+` (`expr + expr`): arithmetic addition. Overloadable (`Add`).
56+
* `+` (`trait + trait`, `'a + trait`): compound type constraint. See [Traits (Multiple Trait Bounds)].
57+
* `+=` (`var += expr`): arithmetic addition & assignment.
58+
* `,`: argument and element separator. See [Attributes], [Functions], [Structs], [Generics], [Match], [Closures], [Crates and Modules (Importing Modules with `use`)].
59+
* `-` (`expr - expr`): arithmetic subtraction. Overloadable (`Sub`).
60+
* `-` (`- expr`): arithmetic negation. Overloadable (`Neg`).
61+
* `-=` (`var -= expr`): arithmetic subtraction & assignment.
62+
* `->` (`fn(…) -> type`, `|…| -> type`): function and closure return type. See [Functions], [Closures].
63+
* `.` (`expr.ident`): member access. See [Structs], [Method Syntax].
64+
* `..` (`..`, `expr..`, `..expr`, `expr..expr`): right-exclusive range literal.
65+
* `..` (`..expr`): struct literal update syntax. See [Structs (Update syntax)].
66+
* `..` (`..ident`): "and the rest" pattern binding. See [Patterns (Ignoring bindings)].
67+
* `...` (`expr ... expr`): inclusive range pattern. See [Patterns (Ranges)].
68+
* `/` (`expr / expr`): arithmetic division. Overloadable (`Div`).
69+
* `/=` (`var /= expr`): arithmetic division & assignment.
70+
* `:` (`pat: type`, `ident: type`): constraints. See [Variable Bindings], [Functions], [Structs], [Traits].
71+
* `:` (`ident: expr`): struct field initialiser. See [Structs].
72+
* `:` (`'a: loop {…}`): loop label. See [Loops (Loops Labels)].
73+
* `;`: statement and item terminator.
74+
* `;` (`[…; len]`): part of fixed-size array syntax. See [Primitive Types (Arrays)].
75+
* `<<` (`expr << expr`): left-shift. Overloadable (`Shl`).
76+
* `<<=` (`var <<= expr`): left-shift & assignment.
77+
* `<` (`expr < expr`): less-than comparison. Overloadable (`Cmp`, `PartialCmp`).
78+
* `<=` (`var <= expr`): less-than or equal-to comparison. Overloadable (`Cmp`, `PartialCmp`).
79+
* `=` (`var = expr`, `ident = type`): assignment/equivalence. See [Variable Bindings], [`type` Aliases], generic parameter defaults.
80+
* `==` (`var == expr`): comparison. Overloadable (`Eq`, `PartialEq`).
81+
* `=>` (`pat => expr`): part of match arm syntax. See [Match].
82+
* `>` (`expr > expr`): greater-than comparison. Overloadable (`Cmp`, `PartialCmp`).
83+
* `>=` (`var >= expr`): greater-than or equal-to comparison. Overloadable (`Cmp`, `PartialCmp`).
84+
* `>>` (`expr >> expr`): right-shift. Overloadable (`Shr`).
85+
* `>>=` (`var >>= expr`): right-shift & assignment.
86+
* `@` (`expr @ expr`): pattern binding. See [Patterns (Bindings)].
87+
* `^` (`expr ^ expr`): bitwise exclusive or. Overloadable (`BitXor`).
88+
* `^=` (`var ^= expr`): bitwise exclusive or & assignment.
89+
* `|` (`expr | expr`): bitwise or. Overloadable (`BitOr`).
90+
* `|` (`pat | pat`): pattern alternatives. See [Patterns (Multiple patterns)].
91+
* `|=` (`var |= expr`): bitwise or & assignment.
92+
* `||` (`expr || expr`): logical or.
93+
* `_`: "ignored" pattern binding. See [Patterns (Ignoring bindings)].
94+
95+
## Other Syntax
96+
97+
<!-- Various bits of standalone stuff. -->
98+
99+
* `'ident`: named lifetime or loop label. See [Lifetimes], [Loops (Loops Labels)].
100+
* `…u8`, `…i32`, `…f64`, `…usize`, …: numeric literal of specific type.
101+
* `"…"`: string literal. See [Strings].
102+
* `r"…"`, `r#"…"#`, `r##"…"##`, …: raw string literal.
103+
* `b"…"`: byte string literal.
104+
* `rb"…"`, `rb#"…"#`, `rb##"…"##`, …: raw byte string literal.
105+
* `'…'`: character literal. See [Primitive Types (`char`)].
106+
* `b'…'`: ASCII byte literal.
107+
108+
<!-- Path-related syntax -->
109+
110+
* `ident::ident`: path. See [Crates and Modules (Defining Modules)].
111+
* `::path`: path relative to the crate root (*i.e.* an explicitly absolute path). See [Crates and Modules (Re-exporting with `pub use`)].
112+
* `self::path`: path relative to the current module (*i.e.* an explicitly relative path). See [Crates and Modules (Re-exporting with `pub use`)].
113+
* `super::path`: path relative to the parent of the current module. See [Crates and Modules (Re-exporting with `pub use`)].
114+
* `type::ident`: associated constants, functions, and types. See [Associated Types].
115+
* `<type>::…`: associated item for a type which cannot be directly named (*e.g.* `<&T>::…`, `<[T]>::…`, *etc.*). See [Associated Types].
116+
117+
<!-- Generics -->
118+
119+
* `path<…>`: specifies parameters to generic type *in a type*. See [Generics].
120+
* `path::<…>`: specifies parameters to generic type or function *in an expression*.
121+
* `ident<…>`: generic parameters. See [Generics].
122+
* `for<…> type`: higher-ranked lifetime bounds.
123+
* `type<ident=type>` (*e.g.* `Iterator<Item=T>`): a generic type where one or more associated types have specific assignments. See [Associated Types].
124+
125+
<!-- Constraints -->
126+
127+
* `T: U`: generic parameter `T` constrained to types that implement `U`. See [Traits].
128+
* `T: 'a`: generic type `T` must outlive lifetime `'a`.
129+
* `'b: 'a`: generic lifetime `'b` must outlive lifetime `'a`.
130+
* `T: ?Sized`: allow generic type parameter to be a dynamically-sized type. See [Unsized Types (`?Sized`)].
131+
* `'a + trait`, `trait + trait`: compound type constraint. See [Traits (Multiple Trait Bounds)].
132+
133+
<!-- Macros and attributes -->
134+
135+
* `#[meta]`: outer attribute. See [Attributes].
136+
* `#![meta]`: inner attribute. See [Attributes].
137+
* `$ident`: macro substitution. See [Macros].
138+
* `$ident:kind`: macro capture. See [Macros].
139+
* `$(…)…`: macro repetition. See [Macros].
140+
141+
<!-- Comments -->
142+
143+
* `//`: line comment. See [Comments].
144+
* `//!`: inner line doc comment. See [Comments].
145+
* `///`: outer line doc comment. See [Comments].
146+
* `/*…*/`: block comment. See [Comments].
147+
* `/*!…*/`: inner block doc comment. See [Comments].
148+
* `/**…*/`: outer block doc comment. See [Comments].
149+
150+
<!-- Various things involving parens and tuples -->
151+
152+
* `()`: empty tuple (*a.k.a.* unit), both literal and type.
153+
* `(expr)`: parenthesised expression.
154+
* `(expr,)`: single-element tuple expression. See [Primitive Types (Tuples)].
155+
* `(type,)`: single-element tuple type. See [Primitive Types (Tuples)].
156+
* `(expr, …)`: tuple expression. See [Primitive Types (Tuples)].
157+
* `(type, …)`: tuple type. See [Primitive Types (Tuples)].
158+
* `expr(expr, …)`: function call expression. Also used to initialise tuple `struct`s and tuple `enum` variants. See [Functions].
159+
* `ident!(…)`, `ident!{…}`, `ident![…]`: macro invocation. See [Macros].
160+
* `expr.0`, `expr.1`, …: tuple indexing. See [Primitive Types (Tuple Indexing)].
161+
162+
<!-- Bracey things -->
163+
164+
* `{…}`: block expression.
165+
* `Type {…}`: `struct` literal. See [Structs].
166+
167+
<!-- Brackety things -->
168+
169+
* `[…]`: array literal. See [Primitive Types (Arrays)].
170+
* `[expr; len]`: array literal containing `len` copies of `expr`. See [Primitive Types (Arrays)].
171+
* `[type; len]`: array type containing `len` instances of `type`. See [Primitive Types (Arrays)].
172+
173+
[`const` and `static` (`static`)]: const-and-static.html#static
174+
[`const` and `static`]: const-and-static.html
175+
[`if let`]: if-let.html
176+
[`if`]: if.html
177+
[`type` Aliases]: type-aliases.html
178+
[Associated Types]: associated-types.html
179+
[Attributes]: attributes.html
180+
[Casting Between Types (`as`)]: casting-between-types.html#as
181+
[Closures (`move` closures)]: closures.html#move-closures
182+
[Closures]: closures.html
183+
[Comments]: comments.html
184+
[Crates and Modules (Defining Modules)]: crates-and-modules.html#defining-modules
185+
[Crates and Modules (Exporting a Public Interface)]: crates-and-modules.html#exporting-a-public-interface
186+
[Crates and Modules (Importing External Crates)]: crates-and-modules.html#importing-external-crates
187+
[Crates and Modules (Importing Modules with `use`)]: crates-and-modules.html#importing-modules-with-use
188+
[Crates and Modules (Re-exporting with `pub use`)]: crates-and-modules.html#re-exporting-with-pub-use
189+
[Enums]: enums.html
190+
[Foreign Function Interface]: ffi.html
191+
[Functions (Early Returns)]: functions.html#early-returns
192+
[Functions]: functions.html
193+
[Generics]: generics.html
194+
[Lifetimes]: lifetimes.html
195+
[Loops (`for`)]: loops.html#for
196+
[Loops (`loop`)]: loops.html#loop
197+
[Loops (`while`)]: loops.html#while
198+
[Loops (Ending Iteration Early)]: loops.html#ending-iteration-early
199+
[Loops (Loops Labels)]: loops.html#loop-labels
200+
[Macros]: macros.html
201+
[Match]: match.html
202+
[Method Syntax (Method Calls)]: method-syntax.html#method-calls
203+
[Method Syntax]: method-syntax.html
204+
[Mutability]: mutability.html
205+
[Operators and Overloading]: operators-and-overloading.html
206+
[Patterns (`ref` and `ref mut`)]: patterns.html#ref-and-ref-mut
207+
[Patterns (Bindings)]: patterns.html#bindings
208+
[Patterns (Ignoring bindings)]: patterns.html#ignoring-bindings
209+
[Patterns (Multiple patterns)]: patterns.html#multiple-patterns
210+
[Patterns (Ranges)]: patterns.html#ranges
211+
[Primitive Types (`char`)]: primitive-types.html#char
212+
[Primitive Types (Arrays)]: primitive-types.html#arrays
213+
[Primitive Types (Booleans)]: primitive-types.html#booleans
214+
[Primitive Types (Tuple Indexing)]: primitive-types.html#tuple-indexing
215+
[Primitive Types (Tuples)]: primitive-types.html#tuples
216+
[Raw Pointers]: raw-pointers.html
217+
[References and Borrowing]: references-and-borrowing.html
218+
[Strings]: strings.html
219+
[Structs (Update syntax)]: structs.html#update-syntax
220+
[Structs]: structs.html
221+
[Traits (`where` clause)]: traits.html#where-clause
222+
[Traits (Multiple Trait Bounds)]: traits.html#multiple-trait-bounds
223+
[Traits]: traits.html
224+
[Unsafe]: unsafe.html
225+
[Unsized Types (`?Sized`)]: unsized-types.html#?sized
226+
[Variable Bindings]: variable-bindings.html

0 commit comments

Comments
 (0)