Skip to content

Commit 8f9f5ef

Browse files
committed
add some notes on coding conventions and link to copyright notice
1 parent 9d12cff commit 8f9f5ef

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- [About this guide](./about-this-guide.md)
44
- [How to build the compiler and run what you built](./how-to-build-and-run.md)
5+
- [Coding conventions](./conventions.md)
56
- [The compiler testing framework](./tests/intro.md)
67
- [Running tests](./tests/running.md)
78
- [Adding new tests](./tests/adding.md)

src/conventions.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
rustc is slowly moving towards the [Rust standard coding style][fmt];
2+
at the moment, however, it follows a rather more *chaotic*
3+
style. There are a few things that are always true.
4+
5+
[fmt]: https://github.com/rust-lang-nursery/fmt-rfcs
6+
7+
# The tidy script
8+
9+
Running `./x.py test` begins with a "tidy" step. This tidy step checks
10+
that your source files meet some basic conventions.
11+
12+
<a name=copyright>
13+
14+
## Copyright notice
15+
16+
All files must begin with the following copyright notice:
17+
18+
```
19+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
20+
// file at the top-level directory of this distribution and at
21+
// http://rust-lang.org/COPYRIGHT.
22+
//
23+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
24+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
25+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
26+
// option. This file may not be copied, modified, or distributed
27+
// except according to those terms.
28+
```
29+
30+
The year at the top is not meaningful: copyright protections are in
31+
fact automatic from the moment of authorship. We do not typically edit
32+
the years on existing files. When creating a new file, you can use the
33+
current year if you like, but you don't have to.
34+
35+
## Line length
36+
37+
Lines should be at most 100 characters. It's even better if you can
38+
keep things to 80.
39+
40+
**Ignoring the line length limit.** Sometimes -- in particular for
41+
tests -- it can be necessary to exempt yourself from this limit. In
42+
that case, you can add a comment towards the top of the file (after
43+
the copyright notice) like so:
44+
45+
```
46+
// ignore-tidy-linelength
47+
```
48+
49+
## Tabs vs spaces
50+
51+
Prefer 4-space indent.
52+
53+
# Warnings and lints
54+
55+
In general, Rust crates
56+
57+
# Policy on using crates from crates.io
58+
59+
It is allowed to use crates from crates.io, though external
60+
dependencies should not be added gratuitously. All such crates must
61+
have a suitably permissive license. There is an automatic check which
62+
inspects the Cargo metadata to ensure this.
63+

src/tests/adding.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ To add a new test, the first thing you generally do is to create a
99
file, typically a Rust source file. Test files have a particular
1010
structure:
1111

12-
- They always begin with the copyright notice;
12+
- They always begin with the [copyright notice](../conventions.html#copyright);
1313
- then they should have some kind of
1414
[comment explaining what the test is about](#explanatory_comment);
1515
- next, they can have one or more [header commands](#header_commands), which are special

0 commit comments

Comments
 (0)