@@ -13,10 +13,74 @@ 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 after 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
+ in length (including comment sigils, but excluding indentation) or the maximum
52
+ width of the line (including comment sigils and indentation), whichever is
53
+ smaller:
54
+
55
+ ``` rust
56
+ // This comment goes up to the ................................. 80 char margin.
57
+
58
+ {
59
+ // This comment is .............................................. 80 chars wide.
60
+ }
61
+
62
+ {
63
+ {
64
+ {
65
+ {
66
+ {
67
+ {
68
+ // This comment is limited by the ......................... 100 char margin.
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
74
+ }
75
+ ```
76
+
77
+ #### Doc comments
78
+
79
+ Prefer line comments (` /// ` ) to block comments (` //* ... */ ` ).
17
80
18
81
Prefer outer doc comments (` /// ` or ` //* ` ), only use inner doc comments (` //! `
19
- and ` /*! ` ) to write module-level documentation.
82
+ and ` //*! ` ) to write module-level or crate-level documentation.
83
+
20
84
21
85
### Attributes
22
86
0 commit comments