Skip to content

Commit 30abb07

Browse files
committed
Comments
closes #17 cc #89
1 parent 6c702c4 commit 30abb07

File tree

1 file changed

+65
-2
lines changed

1 file changed

+65
-2
lines changed

guide/guide.md

+65-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,73 @@ Use spaces, not tabs.
1313
### [Statements](statements.md)
1414
### [Expressions](expressions.md)
1515

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 (`//* ... */`).
1779

1880
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+
2083

2184
### Attributes
2285

0 commit comments

Comments
 (0)