|
| 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 | + |
0 commit comments