Skip to content

Commit 6b5d74c

Browse files
authored
Merge pull request rust-lang#1 from mark-i-m/cap-line-length
2 parents d467979 + d498ee7 commit 6b5d74c

File tree

5 files changed

+126
-70
lines changed

5 files changed

+126
-70
lines changed

src/appendix-glossary.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Appendix C: Glossary
22

3-
The compiler uses a number of...idiosyncratic abbreviations and things. This glossary attempts to list them and give you a few pointers for understanding them better.
3+
The compiler uses a number of...idiosyncratic abbreviations and things. This
4+
glossary attempts to list them and give you a few pointers for understanding
5+
them better.
46

57
Term | Meaning
68
------------------------|--------

src/appendix-stupid-stats.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ and a bunch of other crates with the 'librustc_' prefix.
7373

7474
Next is translation, this translates the AST (and all those side tables) into
7575
LLVM IR (intermediate representation). We do this by calling into the LLVM
76-
libraries, rather than actually writing IR directly to a file. The code for this is in
77-
[librustc_trans](https://github.com/rust-lang/rust/tree/master/src/librustc_trans).
76+
libraries, rather than actually writing IR directly to a file. The code for
77+
this is in [librustc_trans](https://github.com/rust-lang/rust/tree/master/src/librustc_trans).
7878

7979
The next phase is running the LLVM backend. This runs LLVM's optimisation passes
8080
on the generated IR and then generates machine code. The result is object files.
@@ -117,8 +117,8 @@ I'll summarise the methods here.
117117
`early_callback` and `late_callback` let you call arbitrary code at different
118118
points - early is after command line arguments have been parsed, but before
119119
anything is done with them; late is pretty much the last thing before
120-
compilation starts, i.e., after all processing of command line arguments, etc. is
121-
done. Currently, you get to choose whether compilation stops or continues at
120+
compilation starts, i.e., after all processing of command line arguments, etc.
121+
is done. Currently, you get to choose whether compilation stops or continues at
122122
each point, but you don't get to change anything the driver has done. You can
123123
record some info for later, or perform other actions of your own.
124124

@@ -402,4 +402,4 @@ analysis, rather than doing its own analysis). Other parts of the compiler
402402
internally (I already changed save-analysis to use `CompilerController`). I've
403403
been experimenting with a prototype rustfmt which also uses these APIs.
404404

405-
[stupid-stats]: https://github.com/nrc/stupid-stats
405+
[stupid-stats]: https://github.com/nrc/stupid-stats

src/compiletest.md

+114-61
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,66 @@
11
# `compiletest`
2+
23
## Introduction
4+
35
`compiletest` is the main test harness of the Rust test suite. It allows
46
test authors to organize large numbers of tests (the Rust compiler has many
57
thousands), efficient test execution (parallel execution is supported), and
68
allows the test author to configure behavior and expected results of both
79
individual and groups of tests.
810

9-
`compiletest` tests may check test code for success, for failure or in some cases, even failure to compile. Tests are
10-
typically organized as a Rust source file with annotations in comments before and/or within the test code, which serve to
11-
direct `compiletest` on if or how to run the test, what behavior to expect, and more. If you are unfamiliar with the compiler
12-
testing framework, see [`this chapter`](./tests/intro.html) for additional background.
13-
14-
The tests themselves are typically (but not always) organized into "suites"--for example, `run-pass`, a folder
15-
representing tests that should succeed, `run-fail`, a folder holding tests that should compile successfully, but return
16-
a failure (non-zero status), `compile-fail`, a folder holding tests that should fail to compile, and many more. The various
17-
suites are defined in [src/tools/compiletest/src/common.rs](https://github.com/rust-lang/rust/tree/master/src/tools/compiletest/src/common.rs) in the `pub struct Config` declaration. And a very good
18-
introduction to the different suites of compiler tests along with details about them can be found in [`Adding new tests`](./tests/adding.html).
11+
`compiletest` tests may check test code for success, for failure or in some
12+
cases, even failure to compile. Tests are typically organized as a Rust source
13+
file with annotations in comments before and/or within the test code, which
14+
serve to direct `compiletest` on if or how to run the test, what behavior to
15+
expect, and more. If you are unfamiliar with the compiler testing framework,
16+
see [`this chapter`](./tests/intro.html) for additional background.
17+
18+
The tests themselves are typically (but not always) organized into
19+
"suites"--for example, `run-pass`, a folder representing tests that should
20+
succeed, `run-fail`, a folder holding tests that should compile successfully,
21+
but return a failure (non-zero status), `compile-fail`, a folder holding tests
22+
that should fail to compile, and many more. The various suites are defined in
23+
[src/tools/compiletest/src/common.rs][common] in the `pub struct Config`
24+
declaration. And a very good introduction to the different suites of compiler
25+
tests along with details about them can be found in [`Adding new
26+
tests`](./tests/adding.html).
1927

2028
## Adding a new test file
21-
Briefly, simply create your new test in the appropriate location under [src/test](https://github.com/rust-lang/rust/tree/master/src/test). No registration of test files is necessary as
22-
`compiletest` will scan the [src/test](https://github.com/rust-lang/rust/tree/master/src/test) subfolder recursively, and will execute any Rust source files it finds as tests.
23-
See [`Adding new tests`](./tests/adding.html) for a complete guide on how to adding new tests.
29+
30+
Briefly, simply create your new test in the appropriate location under
31+
[src/test][test]. No registration of test files is necessary as `compiletest`
32+
will scan the [src/test][test] subfolder recursively, and will execute any Rust
33+
source files it finds as tests. See [`Adding new tests`](./tests/adding.html)
34+
for a complete guide on how to adding new tests.
2435

2536
## Header Commands
26-
Source file annotations which appear in comments near the top of the source file *before* any test code are known as header
27-
commands. These commands can instruct `compiletest` to ignore this test, set expectations on whether it is expected to
28-
succeed at compiling, or what the test's return code is expected to be. Header commands (and their inline counterparts,
29-
Error Info commands) are described more fully [here](./tests/adding.html#header-commands-configuring-rustc).
37+
38+
Source file annotations which appear in comments near the top of the source
39+
file *before* any test code are known as header commands. These commands can
40+
instruct `compiletest` to ignore this test, set expectations on whether it is
41+
expected to succeed at compiling, or what the test's return code is expected to
42+
be. Header commands (and their inline counterparts, Error Info commands) are
43+
described more fully
44+
[here](./tests/adding.html#header-commands-configuring-rustc).
3045

3146
### Adding a new header command
32-
Header commands are defined in the `TestProps` struct in [src/tools/compiletest/src/header.rs](https://github.com/rust-lang/rust/tree/master/src/tools/compiletest/src/header.rs). At a high level, there are dozens of test properties defined here, all set to default values in the `TestProp` struct's `impl` block. Any test can override this
33-
default value by specifying the property in question as header command as a comment (`//`) in the test source file, before any source code.
47+
48+
Header commands are defined in the `TestProps` struct in
49+
[src/tools/compiletest/src/header.rs][header]. At a high level, there are
50+
dozens of test properties defined here, all set to default values in the
51+
`TestProp` struct's `impl` block. Any test can override this default value by
52+
specifying the property in question as header command as a comment (`//`) in
53+
the test source file, before any source code.
3454

3555
#### Using a header command
36-
Here is an example, specifying the `must-compile-successfully` header command, which takes no arguments, followed by the
37-
`failure-status` header command, which takes a single argument (which, in this case is a value of 1). `failure-status` is
38-
instructing `compiletest` to expect a failure status of 1 (rather than the current Rust default of 101 at the time of this
39-
writing). The header command and the argument list (if present) are typically separated by a colon:
56+
57+
Here is an example, specifying the `must-compile-successfully` header command,
58+
which takes no arguments, followed by the `failure-status` header command,
59+
which takes a single argument (which, in this case is a value of 1).
60+
`failure-status` is instructing `compiletest` to expect a failure status of 1
61+
(rather than the current Rust default of 101 at the time of this writing). The
62+
header command and the argument list (if present) are typically separated by a
63+
colon:
4064
```
4165
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
4266
// file at the top-level directory of this distribution and at
@@ -61,36 +85,51 @@ fn main() -> Result<(), Box<Error>> {
6185
```
6286

6387
#### Adding a new header command property
64-
One would add a new header command if there is a need to define some test property or behavior on an individual, test-by-test
65-
basis. A header command property serves as the header command's backing store (holds the command's current value) at
66-
runtime.
88+
89+
One would add a new header command if there is a need to define some test
90+
property or behavior on an individual, test-by-test basis. A header command
91+
property serves as the header command's backing store (holds the command's
92+
current value) at runtime.
6793

6894
To add a new header command property:
69-
1. Look for the `pub struct TestProps` declaration in [src/tools/compiletest/src/header.rs](https://github.com/rust-lang/rust/tree/master/src/tools/compiletest/src/header.rs) and add
70-
the new public property to the end of the declaration.
71-
2. Look for the `impl TestProps` implementation block immediately following the struct declaration and initialize the new
72-
property to its default value.
95+
1. Look for the `pub struct TestProps` declaration in
96+
[src/tools/compiletest/src/header.rs][header] and add the new public
97+
property to the end of the declaration.
98+
2. Look for the `impl TestProps` implementation block immediately following
99+
the struct declaration and initialize the new property to its default
100+
value.
73101

74102
#### Adding a new header command parser
75-
When `compiletest` encounters a test file, it parses the file a line at a time by calling every parser defined in the
76-
`Config` struct's implementation block, also in [src/tools/compiletest/src/header.rs](https://github.com/rust-lang/rust/tree/master/src/tools/compiletest/src/header.rs) (note the `Config` struct's declaration
77-
block is found in [src/tools/compiletest/src/common.rs](https://github.com/rust-lang/rust/tree/master/src/tools/compiletest/src/common.rs). `TestProps`'s `load_from()` method will try passing the current
78-
line of text to each parser, which, in turn typically checks to see if the line begins with a particular commented (`//`)
79-
header command such as `// must-compile-successfully` or `// failure-status`. Whitespace after the comment marker is
80-
optional.
81-
82-
Parsers will override a given header command property's default value merely by being specified in the test file as a header
83-
command or by having a parameter value specified in the test file, depending on the header command.
84-
85-
Parsers defined in `impl Config` are typically named `parse_<header_command>` (note kebab-case `<header-command>` transformed
86-
to snake-case `<header_command>`). `impl Config` also defines several 'low-level' parsers which make it simple to parse
87-
common patterns like simple presence or not (`parse_name_directive()`), header-command:parameter(s)
88-
(`parse_name_value_directive()`), optional parsing only if a particular `cfg` attribute is defined (`has_cfg_prefix()`) and
89-
many more. The low-level parsers are found near the end of the `impl Config` block; be sure to look through them and their
90-
associated parsers immediately above to see how they are used to avoid writing additional parsing code unneccessarily.
91-
92-
As a concrete example, here is the implementation for the `parse_failure_status()` parser, in
93-
[src/tools/compiletest/src/header.rs](https://github.com/rust-lang/rust/tree/master/src/tools/compiletest/src/header.rs):
103+
104+
When `compiletest` encounters a test file, it parses the file a line at a time
105+
by calling every parser defined in the `Config` struct's implementation block,
106+
also in [src/tools/compiletest/src/header.rs][header] (note the `Config`
107+
struct's declaration block is found in
108+
[src/tools/compiletest/src/common.rs][common]. `TestProps`'s `load_from()`
109+
method will try passing the current line of text to each parser, which, in turn
110+
typically checks to see if the line begins with a particular commented (`//`)
111+
header command such as `// must-compile-successfully` or `// failure-status`.
112+
Whitespace after the comment marker is optional.
113+
114+
Parsers will override a given header command property's default value merely by
115+
being specified in the test file as a header command or by having a parameter
116+
value specified in the test file, depending on the header command.
117+
118+
Parsers defined in `impl Config` are typically named `parse_<header_command>`
119+
(note kebab-case `<header-command>` transformed to snake-case
120+
`<header_command>`). `impl Config` also defines several 'low-level' parsers
121+
which make it simple to parse common patterns like simple presence or not
122+
(`parse_name_directive()`), header-command:parameter(s)
123+
(`parse_name_value_directive()`), optional parsing only if a particular `cfg`
124+
attribute is defined (`has_cfg_prefix()`) and many more. The low-level parsers
125+
are found near the end of the `impl Config` block; be sure to look through them
126+
and their associated parsers immediately above to see how they are used to
127+
avoid writing additional parsing code unneccessarily.
128+
129+
As a concrete example, here is the implementation for the
130+
`parse_failure_status()` parser, in
131+
[src/tools/compiletest/src/header.rs][header]:
132+
94133
```diff
95134
@@ -232,6 +232,7 @@ pub struct TestProps {
96135
// customized normalization rules
@@ -132,14 +171,21 @@ As a concrete example, here is the implementation for the `parse_failure_status(
132171
```
133172

134173
## Implementing the behavior change
135-
When a test invokes a particular header command, it is expected that some behavior will change as a result. What behavior,
136-
obviously, will depend on the purpose of the header command. In the case of `failure-status`, the behavior that changes
137-
is that `compiletest` expects the failure code defined by the header command invoked in the test, rather than the default
138-
value.
139-
140-
Although specific to `failure-status` (as every header command will have a different implementation in order to invoke
141-
behavior change) perhaps it is helpful to see the behavior change implementation of one case, simply as an example. To implement `failure-status`, the `check_correct_failure_status()` function found in the `TestCx` implementation block,
142-
located in [src/tools/compiletest/src/runtest.rs](https://github.com/rust-lang/rust/tree/master/src/tools/compiletest/src/runtest.rs), was modified as per below:
174+
175+
When a test invokes a particular header command, it is expected that some
176+
behavior will change as a result. What behavior, obviously, will depend on the
177+
purpose of the header command. In the case of `failure-status`, the behavior
178+
that changes is that `compiletest` expects the failure code defined by the
179+
header command invoked in the test, rather than the default value.
180+
181+
Although specific to `failure-status` (as every header command will have a
182+
different implementation in order to invoke behavior change) perhaps it is
183+
helpful to see the behavior change implementation of one case, simply as an
184+
example. To implement `failure-status`, the `check_correct_failure_status()`
185+
function found in the `TestCx` implementation block, located in
186+
[src/tools/compiletest/src/runtest.rs](https://github.com/rust-lang/rust/tree/master/src/tools/compiletest/src/runtest.rs),
187+
was modified as per below:
188+
143189
```diff
144190
@@ -295,11 +295,14 @@ impl<'test> TestCx<'test> {
145191
}
@@ -176,7 +222,14 @@ located in [src/tools/compiletest/src/runtest.rs](https://github.com/rust-lang/r
176222
}
177223
}
178224
```
179-
Note the use of `self.props.failure_status` to access the header command property. In tests which do not specify the failure
180-
status header command, `self.props.failure_status` will evaluate to the default value of 101 at the time of this writing.
181-
But for a test which specifies a header command of, for example, `// failure-status: 1`, `self.props.failure_status` will
182-
evaluate to 1, as `parse_failure_status()` will have overridden the `TestProps` default value, for that test specifically.
225+
Note the use of `self.props.failure_status` to access the header command
226+
property. In tests which do not specify the failure status header command,
227+
`self.props.failure_status` will evaluate to the default value of 101 at the
228+
time of this writing. But for a test which specifies a header command of, for
229+
example, `// failure-status: 1`, `self.props.failure_status` will evaluate to
230+
1, as `parse_failure_status()` will have overridden the `TestProps` default
231+
value, for that test specifically.
232+
233+
[test]: https://github.com/rust-lang/rust/tree/master/src/test
234+
[header]: https://github.com/rust-lang/rust/tree/master/src/tools/compiletest/src/header.rs
235+
[common]: https://github.com/rust-lang/rust/tree/master/src/tools/compiletest/src/common.rs

src/const-eval.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Prominent examples are
1111
* Array length
1212
* needs to be known to reserve stack or heap space
1313
* Enum variant discriminants
14-
* needs to be known to prevent two variants from having the same discriminant
14+
* needs to be known to prevent two variants from having the same
15+
discriminant
1516
* Patterns
1617
* need to be known to check for overlapping patterns
1718

src/conventions.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ inspects the Cargo metadata to ensure this.
111111

112112
# How to structure your PR
113113

114-
How you prepare the commits in your PR can make a big difference for the reviewer.
115-
Here are some tips.
114+
How you prepare the commits in your PR can make a big difference for the
115+
reviewer. Here are some tips.
116116

117117
**Isolate "pure refactorings" into their own commit.** For example, if
118118
you rename a method, then put that rename into its own commit, along

0 commit comments

Comments
 (0)