Skip to content

Commit aa9bb67

Browse files
authored
Merge pull request #273 from mark-i-m/conventions
Update Conventions chapters, add chapter on dependencies
2 parents 0456aaa + bb3392e commit aa9bb67

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- [Profiling the compiler](./profiling.md)
2121
- [with the linux perf tool](./profiling/with_perf.md)
2222
- [Coding conventions](./conventions.md)
23+
- [crates.io Dependencies](./crates-io.md)
2324

2425
---
2526

src/conventions.md

+22-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ rustc is slowly moving towards the [Rust standard coding style][fmt];
1111
at the moment, however, it follows a rather more *chaotic* style. We
1212
do have some mandatory formatting conventions, which are automatically
1313
enforced by a script we affectionately call the "tidy" script. The
14-
tidy script runs automatically when you do `./x.py test` and can be run
14+
tidy script runs automatically when you do `./x.py test` and can be run
1515
in isolation with `./x.py test src/tools/tidy`.
1616

1717
[fmt]: https://github.com/rust-lang-nursery/fmt-rfcs
@@ -20,11 +20,12 @@ in isolation with `./x.py test src/tools/tidy`.
2020

2121
### Copyright notice
2222

23-
Some existing files begin with a copyright and license notice. Please omit this
24-
notice for new files licensed under the standard terms (dual MIT/Apache-2.0).
25-
For existing files, the year at the top is not meaningful: copyright
26-
protections are in fact automatic from the moment of authorship. We do not
27-
typically edit the years on existing files.
23+
In the past, files begin with a copyright and license notice. Please **omit**
24+
this notice for new files licensed under the standard terms (dual
25+
MIT/Apache-2.0).
26+
27+
All of the copyright notices should be gone by now, but if you come across one
28+
in the rust-lang/rust repo, feel free to open a PR to remove it.
2829

2930
## Line length
3031

@@ -132,3 +133,18 @@ require that every intermediate commit successfully builds – we only
132133
expect to be able to bisect at a PR level. However, if you *can* make
133134
individual commits build, that is always helpful.
134135

136+
# Naming conventions
137+
138+
Apart from normal Rust style/naming conventions, there are also some specific
139+
to the compiler.
140+
141+
- `cx` tends to be short for "context" and is often used as a suffix. For
142+
example, `tcx` is a common name for the [Typing Context][tcx].
143+
144+
- [`'tcx` and `'gcx`][tcx] are used as the lifetime names for the Typing
145+
Context.
146+
147+
- Because `crate` is a keyword, if you need a variable to represent something
148+
crate-related, often the spelling is changed to `krate`.
149+
150+
[tcx]: ./ty.md

src/crates-io.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# crates.io Dependencies
2+
3+
The rust compiler supports building with some dependencies from `crates.io`.
4+
For example, `log` and `env_logger` come from `crates.io`.
5+
6+
In general, you should avoid adding dependencies to the compiler for several
7+
reasons:
8+
9+
- The dependency may not be high quality or well-maintained, whereas we want
10+
the compiler to be high-quality.
11+
- The dependency may not be using a compatible license.
12+
- The dependency may have transitive dependencies that have one of the above
13+
problems.
14+
15+
TODO: what is the vetting process?
16+
17+
## Whitelist
18+
19+
The `tidy` tool has a [whitelist] of crates that are allowed. To add a
20+
dependency that is not already in the compiler, you will need to add it to this
21+
whitelist.
22+
23+
[whitelist]: https://github.com/rust-lang/rust/blob/659994627234ce7d95a1a52ad8756ce661059adf/src/tools/tidy/src/deps.rs#L56

0 commit comments

Comments
 (0)