|
1 | 1 | # Language rules |
2 | 2 |
|
3 | | -Clauses within the Reference are labeled with a named *rule*. This provides the ability to link and refer to individual clauses, and to [link to the `rustc` testsuite](test-annotations.md). |
| 3 | +Clauses within the Reference are labeled with a named *rule*. This provides the ability to link and refer to individual clauses, and to [link to the `rustc` test suite](test-annotations.md). |
4 | 4 |
|
5 | 5 | ## Rule labels |
6 | 6 |
|
7 | | -Most clauses should be preceded with a rule label. A rule label should be on a line by itself, and should look like this: |
| 7 | +Most clauses should be preceded by a rule label. A rule label should be on a line by itself, and should look like this: |
8 | 8 |
|
9 | 9 | ```markdown |
10 | 10 | r[foo.bar] |
11 | 11 | ``` |
12 | 12 |
|
13 | | -The rule name should be lowercase, with periods separating from most general to most specific (like `r[array.repeat.zero]`). |
| 13 | +The rule name should be lowercase, with periods separating components from most general to most specific (like `r[array.repeat.zero]`). |
14 | 14 |
|
15 | | -Rules can be linked to by their ID using markdown such as `[foo.bar]`. There are [automatic link references] so that any rule can be referred to from any page in the book. |
| 15 | +Rules can be linked to by their ID using Markdown such as `[foo.bar]`. There are [automatic link references] so that any rule can be referred to from any page in the book. |
16 | 16 |
|
17 | | -In the HTML, the rules are clickable just like headers. |
| 17 | +In the HTML, the rules are clickable, just like headers. |
18 | 18 |
|
19 | 19 | ## Rule guidelines |
20 | 20 |
|
21 | | -When assigning rules to new paragraphs, or when modifying rule names, use the following guidelines: |
| 21 | +When assigning rules to new paragraphs or modifying rule names, use the following guidelines: |
22 | 22 |
|
23 | 23 | 1. A rule applies to one core idea, which should be easily determined when reading the paragraph it is applied to. |
24 | | -2. Other than the "intro" paragraph, purely explanatory, expository, or exemplary content does not need a rule. If the expository paragraph isn't directly related to the previous, separate it with a hard (rendered) line break. |
| 24 | +2. Other than the "intro" paragraph, purely explanatory, expository, or exemplary content does not need a rule. If the expository paragraph isn't directly related to the previous one, separate it with a hard (rendered) line break. |
25 | 25 | - This content will be moved to `[!NOTE]` or more specific admonitions in the future. |
26 | 26 | 3. Rust code examples and tests do not need their own rules. |
27 | 27 | 4. Use the following guidelines for admonitions: |
28 | 28 | - Notes: Do not include a rule. |
29 | 29 | - Warning: Omit the rule if the warning follows from the previous paragraph or if the warning is explanatory and doesn't introduce any new rules. |
30 | | - - Target specific behavior: Always include the rule. |
| 30 | + - Target-specific behavior: Always include the rule. |
31 | 31 | - Edition differences: Always include the rule. |
32 | 32 | 5. The following keywords should be used to identify paragraphs when unambiguous: |
33 | | - - `intro`: The beginning paragraph of each section - should explain the construct being defined overall. |
| 33 | + - `intro`: The beginning paragraph of each section. It should explain the construct being defined overall. |
34 | 34 | - `syntax`: Syntax definitions or explanations when BNF syntax definitions are not used. |
35 | | - - `namespace`: For items only, specifies the namespace(s) the item introduces a name in. May also be used elsewhere when defining a namespace (e.g. `r[attribute.diagnostic.namespace]`). |
36 | | -6. When a rule doesn't fall under the above keywords, or for section rule ids, name the subrule as follows: |
37 | | - - If the rule is naming a specific Rust language construct (e.g. an attribute, standard library type/function, or keyword-introduced concept), use the construct as named in the language, appropriately case-adjusted (but do not replace `_`s with `-`s). |
| 35 | + - `namespace`: For items only, specifies the namespace(s) the item introduces a name in. It may also be used elsewhere when defining a namespace (e.g. `r[attribute.diagnostic.namespace]`). |
| 36 | +6. When a rule doesn't fall under the above keywords, or for section rule IDs, name the subrule as follows: |
| 37 | + - If the rule names a specific Rust language construct (e.g., an attribute, standard library type/function, or keyword-introduced concept), use the construct as named in the language, appropriately case-adjusted (but do not replace `_`s with `-`s). |
38 | 38 | - Other than Rust language concepts with `_`s in the name, use `-` characters to separate words within a "subrule". |
39 | 39 | - Whenever possible, do not repeat previous components of the rule. |
40 | 40 | - Edition differences admonitions should typically be named by the edition where the behavior changed. You should be able to correspond the dates to the chapters in <https://doc.rust-lang.org/edition-guide/>. |
41 | | - - Target specific admonitions should typically be named by the least specific target property to which they apply (e.g. if a rule affects all x86 CPUs, the rule name should include `x86` rather than separately listing `i586`, `i686` and `x86_64`, and if a rule applies to all ELF platforms, it should be named `elf` rather than listing every ELF OS). |
| 41 | + - Target-specific admonitions should typically be named by the least specific target property to which they apply (e.g., if a rule affects all x86 CPUs, the rule name should include `x86` rather than separately listing `i586`, `i686`, and `x86_64`. If a rule applies to all ELF platforms, it should be named `elf` rather than listing every ELF OS). |
42 | 42 | - Use an appropriately descriptive, but short, name if the language does not provide one. |
43 | 43 |
|
44 | 44 | [automatic link references]: ../links.md#rule-links |
0 commit comments