Skip to content

Commit b349894

Browse files
authored
Merge pull request #1 from rust-lang-nursery/master
Pulling changes from rust-lang-nursery
2 parents 3c189da + ad77d41 commit b349894

39 files changed

+634
-473
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ install:
99
- bash ci/install.sh
1010
script:
1111
- mdbook build
12+
- mdbook test
1213
notifications:
1314
email:
1415
on_success: never

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ To help prevent accidentally introducing broken links, we use the
3030
invoke this link checker, otherwise it will emit a warning saying it couldn't
3131
be found.
3232

33-
```
34-
$ cargo install mdbook-linkcheck
33+
```bash
34+
> cargo install mdbook-linkcheck
3535
```
3636
You will need `mdbook` version `>= 0.1`. `linkcheck` will be run automatically
3737
when you run `mdbook build`.

src/appendix-background.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ all the remainder. Only at the end of the block is there the
2121
possibility of branching to more than one place (in MIR, we call that
2222
final statement the **terminator**):
2323

24-
```
24+
```mir
2525
bb0: {
2626
statement0;
2727
statement1;
@@ -34,7 +34,7 @@ bb0: {
3434
Many expressions that you are used to in Rust compile down to multiple
3535
basic blocks. For example, consider an if statement:
3636

37-
```rust
37+
```rust,ignore
3838
a = 1;
3939
if some_variable {
4040
b = 1;
@@ -46,7 +46,7 @@ d = 1;
4646

4747
This would compile into four basic blocks:
4848

49-
```
49+
```mir
5050
BB0: {
5151
a = 1;
5252
if some_variable { goto BB1 } else { goto BB2 }

src/appendix-code-index.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ compiler.
66

77
Item | Kind | Short description | Chapter | Declaration
88
----------------|----------|-----------------------------|--------------------|-------------------
9-
`CodeMap` | struct | The CodeMap maps the AST nodes to their source code | [The parser] | [src/libsyntax/codemap.rs](https://github.com/rust-lang/rust/blob/master/src/libsyntax/codemap.rs)
10-
`CompileState` | struct | State that is passed to a callback at each compiler pass | [The Rustc Driver] | [src/librustc_driver/driver.rs](https://github.com/rust-lang/rust/blob/master/src/librustc_driver/driver.rs)
9+
`CodeMap` | struct | The CodeMap maps the AST nodes to their source code | [The parser] | [src/libsyntax/codemap.rs](https://doc.rust-lang.org/nightly/nightly-rustc/syntax/codemap/struct.CodeMap.html)
10+
`CompileState` | struct | State that is passed to a callback at each compiler pass | [The Rustc Driver] | [src/librustc_driver/driver.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/driver/struct.CompileState.html)
1111
`DocContext` | struct | A state container used by rustdoc when crawling through a crate to gather its documentation | [Rustdoc] | [src/librustdoc/core.rs](https://github.com/rust-lang/rust/blob/master/src/librustdoc/core.rs)
12-
`ast::Crate` | struct | Syntax-level representation of a parsed crate | [The parser] | [src/librustc/hir/mod.rs](https://github.com/rust-lang/rust/blob/master/src/libsyntax/ast.rs)
13-
`hir::Crate` | struct | More abstract, compiler-friendly form of a crate's AST | [The Hir] | [src/librustc/hir/mod.rs](https://github.com/rust-lang/rust/blob/master/src/librustc/hir/mod.rs)
14-
`ParseSess` | struct | This struct contains information about a parsing session | [the Parser] | [src/libsyntax/parse/mod.rs](https://github.com/rust-lang/rust/blob/master/src/libsyntax/parse/mod.rs)
15-
`Session` | struct | The data associated with a compilation session | [the Parser], [The Rustc Driver] | [src/librustc/session/mod.html](https://github.com/rust-lang/rust/blob/master/src/librustc/session/mod.rs)
16-
`StringReader` | struct | This is the lexer used during parsing. It consumes characters from the raw source code being compiled and produces a series of tokens for use by the rest of the parser | [The parser] | [src/libsyntax/parse/lexer/mod.rs](https://github.com/rust-lang/rust/blob/master/src/libsyntax/parse/lexer/mod.rs)
17-
`TraitDef` | struct | This struct contains a trait's definition with type information | [The `ty` modules] | [src/librustc/ty/trait_def.rs](https://github.com/rust-lang/rust/blob/master/src/librustc/ty/trait_def.rs)
18-
`Ty<'tcx>` | struct | This is the internal representation of a type used for type checking | [Type checking] | [src/librustc/ty/mod.rs](https://github.com/rust-lang/rust/blob/master/src/librustc/ty/mod.rs)
19-
`TyCtxt<'cx, 'tcx, 'tcx>` | type | The "typing context". This is the central data structure in the compiler. It is the context that you use to perform all manner of queries. | [The `ty` modules] | [src/librustc/ty/context.rs](https://github.com/rust-lang/rust/blob/master/src/librustc/ty/context.rs)
12+
`ast::Crate` | struct | Syntax-level representation of a parsed crate | [The parser] | [src/librustc/hir/mod.rs](https://doc.rust-lang.org/nightly/nightly-rustc/syntax/ast/struct.Crate.html)
13+
`hir::Crate` | struct | More abstract, compiler-friendly form of a crate's AST | [The Hir] | [src/librustc/hir/mod.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/hir/struct.Crate.html)
14+
`ParseSess` | struct | This struct contains information about a parsing session | [the Parser] | [src/libsyntax/parse/mod.rs](https://doc.rust-lang.org/nightly/nightly-rustc/syntax/parse/struct.ParseSess.html)
15+
`Session` | struct | The data associated with a compilation session | [the Parser], [The Rustc Driver] | [src/librustc/session/mod.html](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/session/struct.Session.html)
16+
`StringReader` | struct | This is the lexer used during parsing. It consumes characters from the raw source code being compiled and produces a series of tokens for use by the rest of the parser | [The parser] | [src/libsyntax/parse/lexer/mod.rs](https://doc.rust-lang.org/nightly/nightly-rustc/syntax/parse/lexer/struct.StringReader.html)
17+
`TraitDef` | struct | This struct contains a trait's definition with type information | [The `ty` modules] | [src/librustc/ty/trait_def.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/trait_def/struct.TraitDef.html)
18+
`Ty<'tcx>` | struct | This is the internal representation of a type used for type checking | [Type checking] | [src/librustc/ty/mod.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/type.Ty.html)
19+
`TyCtxt<'cx, 'tcx, 'tcx>` | type | The "typing context". This is the central data structure in the compiler. It is the context that you use to perform all manner of queries. | [The `ty` modules] | [src/librustc/ty/context.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.TyCtxt.html)
2020

2121
[The HIR]: hir.html
2222
[The parser]: the-parser.html

src/appendix-stupid-stats.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
> **Note:** This is a copy of `@nrc`'s amazing [stupid-stats]. You should find
44
> a copy of the code on the GitHub repository although due to the compiler's
55
> constantly evolving nature, there is no guarantee it'll compile on the first
6-
> go.
6+
> go.
77
88
Many tools benefit from being a drop-in replacement for a compiler. By this, I
99
mean that any user of the tool can use `mytool` in all the ways they would
@@ -87,14 +87,16 @@ in [librustc_back](https://github.com/rust-lang/rust/tree/master/src/librustc_ba
8787
(which also contains some things used primarily during translation).
8888

8989
All these phases are coordinated by the driver. To see the exact sequence, look
90-
at the `compile_input` function in [librustc_driver/driver.rs](https://github.com/rust-lang/rust/tree/master/src/librustc_driver/driver.rs).
91-
The driver (which is found in [librust_driver](https://github.com/rust-lang/rust/tree/master/src/librustc_driver))
92-
handles all the highest level coordination of compilation - handling command
93-
line arguments, maintaining compilation state (primarily in the `Session`), and
94-
calling the appropriate code to run each phase of compilation. It also handles
95-
high level coordination of pretty printing and testing. To create a drop-in
96-
compiler replacement or a compiler replacement, we leave most of compilation
97-
alone and customise the driver using its APIs.
90+
at [the `compile_input` function in `librustc_driver`][compile-input].
91+
The driver handles all the highest level coordination of compilation -
92+
1. handling command-line arguments
93+
2. maintaining compilation state (primarily in the `Session`)
94+
3. calling the appropriate code to run each phase of compilation
95+
4. handles high level coordination of pretty printing and testing.
96+
To create a drop-in compiler replacement or a compiler replacement,
97+
we leave most of compilation alone and customise the driver using its APIs.
98+
99+
[compile-input]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/driver/fn.compile_input.html
98100

99101

100102
## The driver customisation APIs
@@ -111,7 +113,7 @@ between phases.
111113
`CompilerCalls` is a trait that you implement in your tool. It contains a fairly
112114
ad-hoc set of methods to hook in to the process of processing command line
113115
arguments and driving the compiler. For details, see the comments in
114-
[librustc_driver/lib.rs](https://github.com/rust-lang/rust/tree/master/src/librustc_driver/lib.rs).
116+
[librustc_driver/lib.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/index.html).
115117
I'll summarise the methods here.
116118

117119
`early_callback` and `late_callback` let you call arbitrary code at different
@@ -175,7 +177,7 @@ foo.rs` (assuming you have a Rust program called `foo.rs`. You can also pass any
175177
command line arguments that you would normally pass to rustc). When you run it
176178
you'll see output similar to
177179

178-
```
180+
```text
179181
In crate: foo,
180182
181183
Found 12 uses of `println!`;
@@ -203,7 +205,7 @@ should dump stupid-stats' stdout to Cargo's stdout).
203205

204206
Let's start with the `main` function for our tool, it is pretty simple:
205207

206-
```
208+
```rust,ignore
207209
fn main() {
208210
let args: Vec<_> = std::env::args().collect();
209211
rustc_driver::run_compiler(&args, &mut StupidCalls::new());
@@ -221,7 +223,7 @@ this tool different from rustc.
221223

222224
`StupidCalls` is a mostly empty struct:
223225

224-
```
226+
```rust,ignore
225227
struct StupidCalls {
226228
default_calls: RustcDefaultCalls,
227229
}
@@ -236,7 +238,7 @@ to keep Cargo happy.
236238

237239
Most of the rest of the impl of `CompilerCalls` is trivial:
238240

239-
```
241+
```rust,ignore
240242
impl<'a> CompilerCalls<'a> for StupidCalls {
241243
fn early_callback(&mut self,
242244
_: &getopts::Matches,
@@ -298,7 +300,7 @@ tool does it's actual work by walking the AST. We do that by creating an AST
298300
visitor and making it walk the AST from the top (the crate root). Once we've
299301
walked the crate, we print the stats we've collected:
300302

301-
```
303+
```rust,ignore
302304
fn build_controller(&mut self, _: &Session) -> driver::CompileController<'a> {
303305
// We mostly want to do what rustc does, which is what basic() will return.
304306
let mut control = driver::CompileController::basic();
@@ -338,7 +340,7 @@ That is all it takes to create your own drop-in compiler replacement or custom
338340
compiler! For the sake of completeness I'll go over the rest of the stupid-stats
339341
tool.
340342

341-
```
343+
```rust
342344
struct StupidVisitor {
343345
println_count: usize,
344346
arg_counts: Vec<usize>,
@@ -353,7 +355,7 @@ methods, these walk the AST taking no action. We override `visit_item` and
353355
functions, modules, traits, structs, and so forth, we're only interested in
354356
functions) and macros:
355357

356-
```
358+
```rust,ignore
357359
impl<'v> visit::Visitor<'v> for StupidVisitor {
358360
fn visit_item(&mut self, i: &'v ast::Item) {
359361
match i.node {

src/compiletest.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ which takes a single argument (which, in this case is a value of 1).
6161
(rather than the current Rust default of 101 at the time of this writing). The
6262
header command and the argument list (if present) are typically separated by a
6363
colon:
64-
```
64+
65+
```rust,ignore
6566
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
6667
// file at the top-level directory of this distribution and at
6768
// http://rust-lang.org/COPYRIGHT.

src/const-eval.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ integer or fat pointer, it will directly yield the value (via `Value::ByVal` or
3535
memory allocation (via `Value::ByRef`). This means that the `const_eval`
3636
function cannot be used to create miri-pointers to the evaluated constant or
3737
static. If you need that, you need to directly work with the functions in
38-
[src/librustc_mir/interpret/const_eval.rs](https://github.com/rust-lang/rust/blob/master/src/librustc_mir/interpret/const_eval.rs).
38+
[src/librustc_mir/interpret/const_eval.rs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/interpret/const_eval/).

src/conventions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ tidy script runs automatically when you do `./x.py test`.
2121

2222
All files must begin with the following copyright notice:
2323

24-
```
24+
```rust
2525
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2626
// file at the top-level directory of this distribution and at
2727
// http://rust-lang.org/COPYRIGHT.
@@ -48,7 +48,7 @@ tests -- it can be necessary to exempt yourself from this limit. In
4848
that case, you can add a comment towards the top of the file (after
4949
the copyright notice) like so:
5050

51-
```
51+
```rust
5252
// ignore-tidy-linelength
5353
```
5454

@@ -61,7 +61,7 @@ Prefer 4-space indent.
6161
# Coding for correctness
6262

6363
Beyond formatting, there are a few other tips that are worth
64-
following.
64+
following.
6565

6666
## Prefer exhaustive matches
6767

src/high-level-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ compilation improves, that may change.)
1919

2020
The dependency structure of these crates is roughly a diamond:
2121

22-
```
22+
```text
2323
rustc_driver
2424
/ | \
2525
/ | \

src/hir.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ This chapter covers the main concepts of the HIR.
1212
You can view the HIR representation of your code by passing the
1313
`-Zunpretty=hir-tree` flag to rustc:
1414

15-
```
16-
cargo rustc -- -Zunpretty=hir-tree
15+
```bash
16+
> cargo rustc -- -Zunpretty=hir-tree
1717
```
1818

1919
### Out-of-band storage and the `Crate` type

0 commit comments

Comments
 (0)