You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/authoring.md
+25-1Lines changed: 25 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,8 @@ This document serves as a guide for editors and reviewers. Some conventions and
15
15
* Code blocks should have an explicit language tag.
16
16
* Do not wrap long lines. This helps with reviewing diffs of the source.
17
17
* Use [smart punctuation] instead of Unicode characters. For example, use `---` for em-dash instead of the Unicode character. Characters like em-dash can be difficult to see in a fixed-width editor, and some editors may not have easy methods to enter such characters.
18
-
* Links should be relative with the `.md` extension. Links to other rust-lang books that are published with the reference or the standard library API should also be relative so that the linkchecker can validate them.
18
+
* Links should be relative with the `.md` extension. Links to other rust-lang books that are published with the reference should also be relative so that the linkchecker can validate them.
19
+
* Links to the standard library should use rustdoc-style links described in [Standard library links](#standard-library-links).
19
20
* The use of reference links is preferred, with shortcuts if appropriate. Place the sorted link reference definitions at the bottom of the file, or at the bottom of a section if there are an unusually large number of links that are specific to the section.
20
21
21
22
```markdown
@@ -75,6 +76,29 @@ Rules can be linked to by their ID using markdown such as `[foo.bar]`. There are
75
76
76
77
In the HTML, the rules are clickable just like headers.
77
78
79
+
When assigning rules to new paragraphs, or when modifying rule names, use the following guidelines:
80
+
81
+
1. A rule applies to one core idea, which should be easily determined when reading the paragraph it is applied to.
82
+
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.
83
+
* This content will be moved to `[!NOTE]` or more specific admonitions in the future.
84
+
3. Rust code examples and tests do not need their own rules.
85
+
4. Use the following guidelines for admonitions:
86
+
* Notes: Do not include a rule.
87
+
* 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.
88
+
* Target specific behavior: Always include the rule.
89
+
* Edition differences: Always include the rule.
90
+
5. The following keywords should be used to identify paragraphs when unambiguous:
91
+
*`intro`: The beginning paragraph of each section - should explain the construct being defined overall.
92
+
*`syntax`: Syntax definitions or explanations when BNF syntax definitions are not used.
93
+
*`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]`).
94
+
6. When a rule doesn't fall under the above keywords, or for section rule ids, name the subrule as follows:
95
+
* 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).
96
+
* Other than Rust language concepts with `_`s in the name, use `-` characters to separate words within a "subrule".
97
+
* Whenever possible, do not repeat previous components of the rule.
98
+
* Edition differences admonitions should typically be named by the edition referenced directly by the rule. If multiple editions are named, use the one for which the behavior is defined by the admonition, and not by a previous paragraph.
99
+
* 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).
100
+
* Use an appropriately descriptive, but short, name if the language does not provide one.
101
+
78
102
### Standard library links
79
103
80
104
You should link to the standard library without specifying a URL in a fashion similar to [rustdoc intra-doc links][intra]. Some examples:
Copy file name to clipboardExpand all lines: src/behavior-considered-undefined.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,8 @@ undefined behavior, it is *unsound*.
40
40
All this also applies when values of these
41
41
types are passed in a (nested) field of a compound type, but not behind
42
42
pointer indirections.
43
-
* Mutating immutable bytes. All bytes inside a [`const`] item or within an implicitly [const-promoted] expression are immutable.
43
+
* Mutating immutable bytes.
44
+
All bytes reachable through a [const-promoted] expression are immutable, as well as bytes reachable through borrows in `static` and `const` initializers that have been [lifetime-extended] to `'static`.
44
45
The bytes owned by an immutable binding or immutable `static` are immutable, unless those bytes are part of an [`UnsafeCell<U>`].
45
46
46
47
Moreover, the bytes [pointed to] by a shared reference, including transitively through other references (both shared and mutable) and `Box`es, are immutable; transitivity includes those references stored in fields of compound types.
@@ -78,7 +79,7 @@ The span of bytes a pointer or reference "points to" is determined by the pointe
78
79
A place is said to be "based on a misaligned pointer" if the last `*` projection
79
80
during place computation was performed on a pointer that was not aligned for its
80
81
type. (If there is no `*` projection in the place expression, then this is
81
-
accessing the field of a local and rustc will guarantee proper alignment. If
82
+
accessing the field of a local or `static`and rustc will guarantee proper alignment. If
82
83
there are multiple `*` projection, then each of them incurs a load of the
83
84
pointer-to-be-dereferenced itself from memory, and each of these loads is
84
85
subject to the alignment constraint. Note that some `*` projections can be
@@ -179,3 +180,4 @@ reading uninitialized memory is permitted are inside `union`s and in "padding"
Copy file name to clipboardExpand all lines: src/input-format.md
+18-1Lines changed: 18 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,41 @@
1
1
# Input format
2
2
3
+
r[input]
4
+
5
+
r[input.intro]
3
6
This chapter describes how a source file is interpreted as a sequence of tokens.
4
7
5
8
See [Crates and source files] for a description of how programs are organised into files.
6
9
7
10
## Source encoding
8
11
12
+
r[input.encoding]
13
+
14
+
r[input.encoding.utf8]
9
15
Each source file is interpreted as a sequence of Unicode characters encoded in UTF-8.
16
+
17
+
r[input.encoding.invalid]
10
18
It is an error if the file is not valid UTF-8.
11
19
12
20
## Byte order mark removal
13
21
22
+
r[input.byte-order-mark]
23
+
14
24
If the first character in the sequence is `U+FEFF` ([BYTE ORDER MARK]), it is removed.
15
25
16
26
## CRLF normalization
17
27
28
+
r[input.crlf]
29
+
18
30
Each pair of characters `U+000D` (CR) immediately followed by `U+000A` (LF) is replaced by a single `U+000A` (LF).
19
31
20
32
Other occurrences of the character `U+000D` (CR) are left in place (they are treated as [whitespace]).
21
33
22
34
## Shebang removal
23
35
36
+
r[input.shebang]
37
+
38
+
r[input.shebang.intro]
24
39
If the remaining sequence begins with the characters `#!`, the characters up to and including the first `U+000A` (LF) are removed from the sequence.
25
40
26
41
For example, the first line of the following file would be ignored:
@@ -34,15 +49,17 @@ fn main() {
34
49
}
35
50
```
36
51
52
+
r[input.shebang.inner-attribute]
37
53
As an exception, if the `#!` characters are followed (ignoring intervening [comments] or [whitespace]) by a `[` token, nothing is removed.
38
54
This prevents an [inner attribute] at the start of a source file being removed.
39
55
40
56
> **Note**: The standard library [`include!`] macro applies byte order mark removal, CRLF normalization, and shebang removal to the file it reads. The [`include_str!`] and [`include_bytes!`] macros do not.
41
57
42
58
## Tokenization
43
59
44
-
The resulting sequence of characters is then converted into tokens as described in the remainder of this chapter.
60
+
r[input.tokenization]
45
61
62
+
The resulting sequence of characters is then converted into tokens as described in the remainder of this chapter.
46
63
47
64
[inner attribute]: attributes.md
48
65
[BYTE ORDER MARK]: https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8
0 commit comments