Skip to content

Commit 8751dfe

Browse files
committed
merged with upstream/master
2 parents 84c2cd5 + b9bc44d commit 8751dfe

10 files changed

+595
-7
lines changed

Diff for: .travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ deploy:
1616
provider: pages
1717
skip-cleanup: true
1818
github-token: $GITHUB_TOKEN
19-
local-dir: book
19+
local-dir: book/html
2020
on:
2121
branch: master

Diff for: ci/install.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ function cargo_install() {
66
local version=$2
77

88
if command -v $name >/dev/null 2>&1; then
9-
echo "$name is already installed at $(command -v $name)"
9+
local installed_version=`$name --version | sed -E 's/[a-zA-Z_-]+ v?//g'`
10+
if [ "$installed_version" == "$version" ]; then
11+
echo "$name $version is already installed at $(command -v $name)"
12+
else
13+
echo "Forcing install $name $version"
14+
cargo install $name --version $version --force
15+
fi
1016
else
11-
echo "Installing $name"
17+
echo "Installing $name $version"
1218
cargo install $name --version $version
1319
fi
1420
}

Diff for: src/SUMMARY.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
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)
6+
- [The compiler testing framework](./tests/intro.md)
7+
- [Running tests](./tests/running.md)
8+
- [Adding new tests](./tests/adding.md)
59
- [Using `compiletest` + commands to control test execution](./compiletest.md)
6-
- [Using the compiler testing framework](./running-tests.md)
7-
- [How to add new header commands to `compiletest`](./compiletest.md)
810
- [Walkthrough: a typical contribution](./walkthrough.md)
911
- [High-level overview of the compiler source](./high-level-overview.md)
1012
- [Queries: demand-driven compilation](./query.md)

Diff for: src/conventions.md

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
This file offers some tips on the coding conventions for rustc. This
2+
chapter covers [formatting](#formatting), [coding for correctness](#cc),
3+
[using crates from crates.io](#cio), and some tips on
4+
[structuring your PR for easy review](#er).
5+
6+
<a name=formatting>
7+
8+
# Formatting and the tidy script
9+
10+
rustc is slowly moving towards the [Rust standard coding style][fmt];
11+
at the moment, however, it follows a rather more *chaotic* style. We
12+
do have some mandatory formatting conventions, which are automatically
13+
enforced by a script we affectionately call the "tidy" script. The
14+
tidy script runs automatically when you do `./x.py test`.
15+
16+
[fmt]: https://github.com/rust-lang-nursery/fmt-rfcs
17+
18+
<a name=copyright>
19+
20+
### Copyright notice
21+
22+
All files must begin with the following copyright notice:
23+
24+
```
25+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
26+
// file at the top-level directory of this distribution and at
27+
// http://rust-lang.org/COPYRIGHT.
28+
//
29+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
30+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
31+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
32+
// option. This file may not be copied, modified, or distributed
33+
// except according to those terms.
34+
```
35+
36+
The year at the top is not meaningful: copyright protections are in
37+
fact automatic from the moment of authorship. We do not typically edit
38+
the years on existing files. When creating a new file, you can use the
39+
current year if you like, but you don't have to.
40+
41+
## Line length
42+
43+
Lines should be at most 100 characters. It's even better if you can
44+
keep things to 80.
45+
46+
**Ignoring the line length limit.** Sometimes -- in particular for
47+
tests -- it can be necessary to exempt yourself from this limit. In
48+
that case, you can add a comment towards the top of the file (after
49+
the copyright notice) like so:
50+
51+
```
52+
// ignore-tidy-linelength
53+
```
54+
55+
## Tabs vs spaces
56+
57+
Prefer 4-space indent.
58+
59+
<a name=cc>
60+
61+
# Coding for correctness
62+
63+
Beyond formatting, there are a few other tips that are worth
64+
following.
65+
66+
## Prefer exhaustive matches
67+
68+
Using `_` in a match is convenient, but it means that when new
69+
variants are added to the enum, they may not get handled correctly.
70+
Ask yourself: if a new variant were added to this enum, what's the
71+
chance that it would want to use the `_` code, versus having some
72+
other treatment? Unless the answer is "low", then prefer an
73+
exhaustive match. (The same advice applies to `if let` and `while
74+
let`, which are effectively tests for a single variant.)
75+
76+
## Use "TODO" comments for things you don't want to forget
77+
78+
As a useful tool to yourself, you can insert a `// TODO` comment
79+
for something that you want to get back to before you land your PR:
80+
81+
```rust,ignore
82+
fn do_something() {
83+
if something_else {
84+
unimplemented!(): // TODO write this
85+
}
86+
}
87+
```
88+
89+
The tidy script will report an error for a `// TODO` comment, so this
90+
code would not be able to land until the TODO is fixed (or removed).
91+
92+
This can also be useful in a PR as a way to signal from one commit that you are
93+
leaving a bug that a later commit will fix:
94+
95+
```rust,ignore
96+
if foo {
97+
return true; // TODO wrong, but will be fixed in a later commit
98+
}
99+
```
100+
101+
<a name=cio>
102+
103+
# Using crates from crates.io
104+
105+
It is allowed to use crates from crates.io, though external
106+
dependencies should not be added gratuitously. All such crates must
107+
have a suitably permissive license. There is an automatic check which
108+
inspects the Cargo metadata to ensure this.
109+
110+
<a name=er>
111+
112+
# How to structure your PR
113+
114+
How you prepare the commits in your PR can make a big difference for the reviewer.
115+
Here are some tips.
116+
117+
**Isolate "pure refactorings" into their own commit.** For example, if
118+
you rename a method, then put that rename into its own commit, along
119+
with the renames of all the uses.
120+
121+
**More commits is usually better.** If you are doing a large change,
122+
it's almost always better to break it up into smaller steps that can
123+
be independently understood. The one thing to be aware of is that if
124+
you introduce some code following one strategy, then change it
125+
dramatically (versus adding to it) in a later commit, that
126+
'back-and-forth' can be confusing.
127+
128+
**If you run rustfmt and the file was not already formatted, isolate
129+
that into its own commit.** This is really the same as the previous
130+
rule, but it's worth highlighting. It's ok to rustfmt files, but since
131+
we do not currently run rustfmt all the time, that can introduce a lot
132+
of noise into your commit. Please isolate that into its own
133+
commit. This also makes rebases a lot less painful, since rustfmt
134+
tends to cause a lot of merge conflicts, and having those isolated
135+
into their own commit makes htem easier to resolve.
136+
137+
**No merges.** We do not allow merge commits into our history, other
138+
than those by bors. If you get a merge conflict, rebase instead via a
139+
command like `git rebase -i rust-lang/master` (presuming you use the
140+
name `rust-lang` for your remote).
141+
142+
**Individual commits do not have to build (but it's nice).** We do not
143+
require that every intermediate commit successfully builds -- we only
144+
expect to be able to bisect at a PR level. However, if you *can* make
145+
individual commits build, that is always helpful.
146+

Diff for: src/glossary.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Term | Meaning
77
------------------------|--------
88
AST | the abstract syntax tree produced by the syntax crate; reflects user syntax very closely.
99
codegen unit | when we produce LLVM IR, we group the Rust code into a number of codegen units. Each of these units is processed by LLVM independently from one another, enabling parallelism. They are also the unit of incremental re-use.
10+
completeness | completeness is a technical term in type theory. Completeness means that every type-safe program also type-checks. Having both soundness and completeness is very hard, and usually soundness is more important. (see "soundness").
1011
cx | we tend to use "cx" as an abbrevation for context. See also `tcx`, `infcx`, etc.
1112
DAG | a directed acyclic graph is used during compilation to keep track of dependencies between queries. ([see more](incremental-compilation.html))
1213
DefId | an index identifying a definition (see `librustc/hir/def_id.rs`). Uniquely identifies a `DefPath`.
@@ -25,6 +26,7 @@ provider | the function that executes a query ([see more](query.
2526
query | perhaps some sub-computation during compilation ([see more](query.html))
2627
sess | the compiler session, which stores global data used throughout compilation
2728
side tables | because the AST and HIR are immutable once created, we often carry extra information about them in the form of hashtables, indexed by the id of a particular node.
29+
soundness | soundness is a technical term in type theory. Roughly, if a type system is sound, then if a program type-checks, it is type-safe; i.e. I can never (in safe rust) force a value into a variable of the wrong type. (see "completeness").
2830
span | a location in the user's source code, used for error reporting primarily. These are like a file-name/line-number/column tuple on steroids: they carry a start/end point, and also track macro expansions and compiler desugaring. All while being packed into a few bytes (really, it's an index into a table). See the Span datatype for more.
2931
substs | the substitutions for a given generic type or item (e.g. the `i32`, `u32` in `HashMap<i32, u32>`)
3032
tcx | the "typing context", main data structure of the compiler ([see more](ty.html))

Diff for: src/how-to-build-and-run.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,6 @@ Here are a few other useful x.py commands. We'll cover some of them in detail in
132132
- `./x.py clean` – clean up the build directory (`rm -rf build` works too, but then you have to rebuild LLVM)
133133
- `./x.py build --stage 1` – builds everything using the stage 1 compiler, not just up to libstd
134134
- `./x.py build` – builds the stage2 compiler
135-
- Running tests (see the section [running tests](./running-tests.html) for more details):
135+
- Running tests (see the [section on running tests](./tests/running.html) for more details):
136136
- `./x.py test --stage 1 src/libstd` – runs the `#[test]` tests from libstd
137137
- `./x.py test --stage 1 src/test/run-pass` – runs the `run-pass` test suite

Diff for: src/running-tests.md

-1
This file was deleted.

0 commit comments

Comments
 (0)