@@ -13,10 +13,73 @@ Use spaces, not tabs.
13
13
### [ Statements] ( statements.md )
14
14
### [ Expressions] ( expressions.md )
15
15
16
- ### Doc comments
16
+
17
+ ### Comments
18
+
19
+ The following guidelines are recommendations only, a mechanical formatter should
20
+ not change comments except to move them within a file. To be clear this means
21
+ changing the whitespace before a line comment or the whitespace before or after
22
+ a block comment.
23
+
24
+ Prefer line comments (` // ` ) to block comments (` /* ... */ ` ).
25
+
26
+ When using line comments there should be a single space the opening sigil.
27
+
28
+ When using single-line block comments there should be a single space after the
29
+ opening sigil and before the closing sigil. Multi-line block comments should
30
+ have a newline after the opening sigil and before the closing sigil.
31
+
32
+ Prefer to put a comment on its own line. Where a comment follows code, there
33
+ should be a single space before it. Where a block comment is inline, there
34
+ should be surrounding whitespace as if it were an identifier or keyword. There
35
+ should be no trailing whitespace after a comment. Examples:
36
+
37
+ ``` rust
38
+ // A comment on an item.
39
+ struct Foo { ... }
40
+
41
+ fn foo () {} // A comment after an item.
42
+
43
+ pub fn foo (/* a comment before an argument */ x : T ) {... }
44
+ ```
45
+
46
+ Comments should usually be complete sentences. Start with a capital letter, end
47
+ with a period (` . ` ). An inline block comment may be treated as a note without
48
+ punctuation.
49
+
50
+ Source lines which are entirely a comment should be limited to 80 characters
51
+ (including comment sigils) in length or the maximum width of the line, whichever
52
+ is smaller:
53
+
54
+ ``` rust
55
+ // This comment is goes up to the .............................. 80 char margin.
56
+
57
+ {
58
+ // This comment is .............................................. 80 chars wide.
59
+ }
60
+
61
+ {
62
+ {
63
+ {
64
+ {
65
+ {
66
+ {
67
+ // This comment is limited by the ......................... 100 char margin.
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
74
+ ```
75
+
76
+ #### Doc comments
77
+
78
+ Prefer line comments (` /// ` ) to block comments (` //* ... */ ` ).
17
79
18
80
Prefer outer doc comments (` /// ` or ` //* ` ), only use inner doc comments (` //! `
19
- and ` /*! ` ) to write module-level documentation.
81
+ and ` //*! ` ) to write module-level or crate-level documentation.
82
+
20
83
21
84
### Attributes
22
85
0 commit comments