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

+1
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

+2-2
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

+3-3
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

+10-10
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

+19-17
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

+2-1
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

+1-1
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

+3-3
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

+1-1
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

+2-2
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

src/how-to-build-and-run.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ Once you've created a config.toml, you are now ready to run
7070
`x.py`. There are a lot of options here, but let's start with what is
7171
probably the best "go to" command for building a local rust:
7272

73-
```
74-
./x.py build -i --stage 1 src/libstd
73+
```bash
74+
> ./x.py build -i --stage 1 src/libstd
7575
```
7676

7777
What this command will do is the following:
@@ -106,7 +106,7 @@ will execute the stage2 compiler (which we did not build, but which
106106
you will likely need to build at some point; for example, if you want
107107
to run the entire test suite).
108108

109-
```
109+
```bash
110110
> rustup toolchain link stage1 build/<host-triple>/stage1
111111
> rustup toolchain link stage2 build/<host-triple>/stage2
112112
```
@@ -115,7 +115,7 @@ Now you can run the rustc you built with. If you run with `-vV`, you
115115
should see a version number ending in `-dev`, indicating a build from
116116
your local environment:
117117

118-
```
118+
```bash
119119
> rustc +stage1 -vV
120120
rustc 1.25.0-dev
121121
binary: rustc

src/incrcomp-debugging.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ As an example, see `src/test/compile-fail/dep-graph-caller-callee.rs`.
1010

1111
The idea is that you can annotate a test like:
1212

13-
```rust
13+
```rust,ignore
1414
#[rustc_if_this_changed]
1515
fn foo() { }
1616
@@ -48,7 +48,7 @@ the graph. You can filter in three ways:
4848
To filter, use the `RUST_DEP_GRAPH_FILTER` environment variable, which should
4949
look like one of the following:
5050

51-
```
51+
```text
5252
source_filter // nodes originating from source_filter
5353
-> target_filter // nodes that can reach target_filter
5454
source_filter -> target_filter // nodes in between source_filter and target_filter
@@ -58,14 +58,14 @@ source_filter -> target_filter // nodes in between source_filter and target_filt
5858
A node is considered to match a filter if all of those strings appear in its
5959
label. So, for example:
6060

61-
```
61+
```text
6262
RUST_DEP_GRAPH_FILTER='-> TypeckTables'
6363
```
6464

6565
would select the predecessors of all `TypeckTables` nodes. Usually though you
6666
want the `TypeckTables` node for some particular fn, so you might write:
6767

68-
```
68+
```text
6969
RUST_DEP_GRAPH_FILTER='-> TypeckTables & bar'
7070
```
7171

@@ -75,7 +75,7 @@ with `bar` in their name.
7575
Perhaps you are finding that when you change `foo` you need to re-type-check
7676
`bar`, but you don't think you should have to. In that case, you might do:
7777

78-
```
78+
```text
7979
RUST_DEP_GRAPH_FILTER='Hir & foo -> TypeckTables & bar'
8080
```
8181

@@ -105,8 +105,10 @@ check of `bar` and you don't think there should be. You dump the
105105
dep-graph as described in the previous section and open `dep-graph.txt`
106106
to see something like:
107107

108-
Hir(foo) -> Collect(bar)
109-
Collect(bar) -> TypeckTables(bar)
108+
```text
109+
Hir(foo) -> Collect(bar)
110+
Collect(bar) -> TypeckTables(bar)
111+
```
110112

111113
That first edge looks suspicious to you. So you set
112114
`RUST_FORBID_DEP_GRAPH_EDGE` to `Hir&foo -> Collect&bar`, re-run, and

src/macro-expansion.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ expansion works.
1515
It's helpful to have an example to refer to. For the remainder of this chapter,
1616
whenever we refer to the "example _definition_", we mean the following:
1717

18-
```rust
18+
```rust,ignore
1919
macro_rules! printer {
2020
(print $mvar:ident) => {
2121
println!("{}", $mvar);
@@ -45,7 +45,7 @@ worrying about _where_. For more information about tokens, see the
4545

4646
Whenever we refer to the "example _invocation_", we mean the following snippet:
4747

48-
```rust
48+
```rust,ignore
4949
printer!(print foo); // Assume `foo` is a variable defined somewhere else...
5050
```
5151

@@ -65,7 +65,7 @@ defined in [`src/libsyntax/ext/tt/macro_parser.rs`][code_mp].
6565

6666
The interface of the macro parser is as follows (this is slightly simplified):
6767

68-
```rust
68+
```rust,ignore
6969
fn parse(
7070
sess: ParserSession,
7171
tts: TokenStream,
@@ -156,7 +156,7 @@ TODO
156156

157157

158158
[code_dir]: https://github.com/rust-lang/rust/tree/master/src/libsyntax/ext/tt
159-
[code_mp]: https://github.com/rust-lang/rust/tree/master/src/libsyntax/ext/tt/macro_parser.rs
160-
[code_mr]: https://github.com/rust-lang/rust/tree/master/src/libsyntax/ext/tt/macro_rules.rs
161-
[code_parse_int]: https://github.com/rust-lang/rust/blob/a97cd17f5d71fb4ec362f4fbd79373a6e7ed7b82/src/libsyntax/ext/tt/macro_parser.rs#L421
159+
[code_mp]: https://doc.rust-lang.org/nightly/nightly-rustc/syntax/ext/tt/macro_parser/
160+
[code_mr]: https://doc.rust-lang.org/nightly/nightly-rustc/syntax/ext/tt/macro_rules/
161+
[code_parse_int]: https://doc.rust-lang.org/nightly/nightly-rustc/syntax/ext/tt/macro_parser/fn.parse.html
162162
[parsing]: ./the-parser.html

0 commit comments

Comments
 (0)