Skip to content

Commit ac41af0

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

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

guide/guide.md

+66-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,74 @@ 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 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 (`//* ... */`).
1780

1881
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+
2084

2185
### Attributes
2286

0 commit comments

Comments
 (0)