Skip to content

Commit ec61b11

Browse files
author
The rustc-dev-guide Cronjob Bot
committed
Merge from rustc
2 parents c4ebe18 + 525f20e commit ec61b11

7 files changed

Lines changed: 82 additions & 55 deletions

File tree

src/appendix/glossary.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Term | Meaning
3131
<span id="generics">generics</span> | The list of generic parameters defined on an item. There are three kinds of generic parameters: Type, lifetime and const parameters.
3232
<span id="hir">HIR</span> | The _high-level [IR](#ir)_, created by lowering and desugaring the AST. ([see more](../hir.md))
3333
<span id="hir-id">`HirId`</span> | Identifies a particular node in the HIR by combining a def-id with an "intra-definition offset". See [the HIR chapter for more](../hir.md#identifiers-in-the-hir).
34-
<span id="hir-map">HIR map</span> | The HIR map, accessible via `tcx.hir()`, allows you to quickly navigate the HIR and convert between various forms of identifiers.
3534
<span id="ice">ICE</span> | Short for _internal compiler error_, this is when the compiler crashes.
3635
<span id="ich">ICH</span> | Short for _incremental compilation hash_, these are used as fingerprints for things such as HIR and crate metadata, to check if changes have been made. This is useful in incremental compilation to see if part of a crate has changed and should be recompiled.
3736
<span id="infcx">`infcx`</span> | The type inference context (`InferCtxt`). (see `rustc_middle::infer`)

src/building/optimized-build.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,16 @@ like Python or LLVM.
109109

110110
Here is an example of how can `opt-dist` be used locally (outside of CI):
111111

112-
1. Build the tool with the following command:
112+
1. Enable metrics in your `bootstrap.toml` file, because `opt-dist` expects it to be enabled:
113+
```toml
114+
[build]
115+
metrics = true
116+
```
117+
2. Build the tool with the following command:
113118
```bash
114119
./x build tools/opt-dist
115120
```
116-
2. Run the tool with the `local` mode and provide necessary parameters:
121+
3. Run the tool with the `local` mode and provide necessary parameters:
117122
```bash
118123
./build/host/stage0-tools-bin/opt-dist local \
119124
--target-triple <target> \ # select target, e.g. "x86_64-unknown-linux-gnu"

src/compiler-debugging.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ Right below you can find elaborate explainers on a selected few.
301301

302302
Some compiler options for debugging specific features yield graphviz graphs -
303303
e.g. the `#[rustc_mir(borrowck_graphviz_postflow="suffix.dot")]` attribute
304-
dumps various borrow-checker dataflow graphs.
304+
on a function dumps various borrow-checker dataflow graphs in conjunction with
305+
`-Zdump-mir-dataflow`.
305306

306307
These all produce `.dot` files. To view these files, install graphviz (e.g.
307308
`apt-get install graphviz`) and then run the following commands:

src/hir.md

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ The HIR uses a bunch of different identifiers that coexist and serve different p
100100
a wrapper around a [`HirId`]. For more info about HIR bodies, please refer to the
101101
[HIR chapter][hir-bodies].
102102

103-
These identifiers can be converted into one another through the [HIR map][map].
103+
These identifiers can be converted into one another through the `TyCtxt`.
104104

105105
[`DefId`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.DefId.html
106106
[`LocalDefId`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.LocalDefId.html
@@ -110,30 +110,24 @@ These identifiers can be converted into one another through the [HIR map][map].
110110
[`CrateNum`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.CrateNum.html
111111
[`DefIndex`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.DefIndex.html
112112
[`Body`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.Body.html
113-
[hir-map]: ./hir.md#the-hir-map
114113
[hir-bodies]: ./hir.md#hir-bodies
115-
[map]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html
116114

117-
## The HIR Map
115+
## HIR Operations
118116

119117
Most of the time when you are working with the HIR, you will do so via
120-
the **HIR Map**, accessible in the tcx via [`tcx.hir()`] (and defined in
121-
the [`hir::map`] module). The [HIR map] contains a [number of methods] to
122-
convert between IDs of various kinds and to lookup data associated
123-
with a HIR node.
118+
`TyCtxt`. It contains a number of methods, defined in the `hir::map` module and
119+
mostly prefixed with `hir_`, to convert between IDs of various kinds and to
120+
lookup data associated with a HIR node.
124121

125-
[`tcx.hir()`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.hir
126-
[`hir::map`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/index.html
127-
[HIR map]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html
128-
[number of methods]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#methods
122+
[`TyCtxt`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html
129123

130124
For example, if you have a [`LocalDefId`], and you would like to convert it
131-
to a [`HirId`], you can use [`tcx.hir().local_def_id_to_hir_id(def_id)`][local_def_id_to_hir_id].
125+
to a [`HirId`], you can use [`tcx.local_def_id_to_hir_id(def_id)`][local_def_id_to_hir_id].
132126
You need a `LocalDefId`, rather than a `DefId`, since only local items have HIR nodes.
133127

134-
[local_def_id_to_hir_id]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.local_def_id_to_hir_id
128+
[local_def_id_to_hir_id]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.local_def_id_to_hir_id
135129

136-
Similarly, you can use [`tcx.hir().find(n)`][find] to lookup the node for a
130+
Similarly, you can use [`tcx.hir_node(n)`][hir_node] to lookup the node for a
137131
[`HirId`]. This returns a `Option<Node<'hir>>`, where [`Node`] is an enum
138132
defined in the map. By matching on this, you can find out what sort of
139133
node the `HirId` referred to and also get a pointer to the data
@@ -142,26 +136,27 @@ that `n` must be some HIR expression, you can do
142136
[`tcx.hir_expect_expr(n)`][expect_expr], which will extract and return the
143137
[`&hir::Expr`][Expr], panicking if `n` is not in fact an expression.
144138

145-
[find]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.find
139+
[hir_node]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.hir_node
146140
[`Node`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.Node.html
147141
[expect_expr]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.expect_expr
148142
[Expr]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.Expr.html
149143

150-
Finally, you can use the HIR map to find the parents of nodes, via
151-
calls like [`tcx.hir().get_parent(n)`][get_parent].
144+
Finally, you can find the parents of nodes, via
145+
calls like [`tcx.parent_hir_node(n)`][parent_hir_node].
146+
147+
[get_parent_item]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.parent_hir_node
152148

153-
[get_parent]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.get_parent
154149

155150
## HIR Bodies
156151

157152
A [`rustc_hir::Body`] represents some kind of executable code, such as the body
158153
of a function/closure or the definition of a constant. Bodies are
159154
associated with an **owner**, which is typically some kind of item
160155
(e.g. an `fn()` or `const`), but could also be a closure expression
161-
(e.g. `|x, y| x + y`). You can use the HIR map to find the body
162-
associated with a given def-id ([`maybe_body_owned_by`]) or to find
163-
the owner of a body ([`body_owner_def_id`]).
156+
(e.g. `|x, y| x + y`). You can use the `TyCtxt` to find the body
157+
associated with a given def-id ([`hir_maybe_body_owned_by`]) or to find
158+
the owner of a body ([`hir_body_owner_def_id`]).
164159

165160
[`rustc_hir::Body`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.Body.html
166-
[`maybe_body_owned_by`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.maybe_body_owned_by
167-
[`body_owner_def_id`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.body_owner_def_id
161+
[`hir_maybe_body_owned_by`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.hir_maybe_body_owned_by
162+
[`hir_body_owner_def_id`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.hir_body_owner_def_id

src/solve/opaque-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ For opaque types in the defining scope and in the implicit-negative coherence mo
3333
always done in two steps. Outside of the defining scope `normalizes-to` for opaques always
3434
returns `Err(NoSolution)`.
3535

36-
We start by trying to to assign the expected type as a hidden type.
36+
We start by trying to assign the expected type as a hidden type.
3737

3838
In the implicit-negative coherence mode, this currently always results in ambiguity without
3939
interacting with the opaque types storage. We could instead add allow 'defining' all opaque types,

src/tests/directives.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ for more details.
101101
| `normalize-stdout` | Normalize actual stdout with a rule `"<raw>" -> "<normalized>"` before comparing against snapshot | `ui`, `incremental` | `"<RAW>" -> "<NORMALIZED>"`, `<RAW>`/`<NORMALIZED>` is regex capture and replace syntax |
102102
| `dont-check-compiler-stderr` | Don't check actual compiler stderr vs stderr snapshot | `ui` | N/A |
103103
| `dont-check-compiler-stdout` | Don't check actual compiler stdout vs stdout snapshot | `ui` | N/A |
104+
| `dont-require-annotations` | Don't require line annotations for the given diagnostic kind (`//~ KIND`) to be exhaustive | `ui`, `incremental` | `ERROR`, `WARN`, `NOTE`, `HELP`, `SUGGESTION` |
104105
| `run-rustfix` | Apply all suggestions via `rustfix`, snapshot fixed output, and check fixed output builds | `ui` | N/A |
105106
| `rustfix-only-machine-applicable` | `run-rustfix` but only machine-applicable suggestions | `ui` | N/A |
106107
| `exec-env` | Env var to set when executing a test | `ui`, `crashes` | `<KEY>=<VALUE>` |
@@ -191,8 +192,13 @@ settings:
191192
specified atomic widths, e.g. the test with `//@ needs-target-has-atomic: 8,
192193
16, ptr` will only run if it supports the comma-separated list of atomic
193194
widths.
194-
- `needs-dynamic-linking` - ignores if target does not support dynamic linking
195+
- `needs-dynamic-linking` ignores if target does not support dynamic linking
195196
(which is orthogonal to it being unable to create `dylib` and `cdylib` crate types)
197+
- `needs-crate-type` — ignores if target platform does not support one or more
198+
of the comma-delimited list of specified crate types. For example,
199+
`//@ needs-crate-type: cdylib, proc-macro` will cause the test to be ignored
200+
on `wasm32-unknown-unknown` target because the target does not support the
201+
`proc-macro` crate type.
196202

197203
The following directives will check LLVM support:
198204

@@ -229,14 +235,14 @@ ignoring debuggers.
229235

230236
### Affecting how tests are built
231237

232-
| Directive | Explanation | Supported test suites | Possible values |
233-
|---------------------|----------------------------------------------------------------------------------------------|---------------------------|------------------------------------------------------------------------------|
234-
| `compile-flags` | Flags passed to `rustc` when building the test or aux file | All except for `run-make` | Any valid `rustc` flags, e.g. `-Awarnings -Dfoo`. Cannot be `-Cincremental`. |
235-
| `edition` | Alias for `compile-flags: --edition=xxx` | All except for `run-make` | Any valid `--edition` value |
236-
| `rustc-env` | Env var to set when running `rustc` | All except for `run-make` | `<KEY>=<VALUE>` |
237-
| `unset-rustc-env` | Env var to unset when running `rustc` | All except for `run-make` | Any env var name |
238-
| `incremental` | Proper incremental support for tests outside of incremental test suite | `ui`, `crashes` | N/A |
239-
| `no-prefer-dynamic` | Don't use `-C prefer-dynamic`, don't build as a dylib via a `--crate-type=dylib` preset flag | `ui`, `crashes` | N/A |
238+
| Directive | Explanation | Supported test suites | Possible values |
239+
|---------------------|----------------------------------------------------------------------------------------------|---------------------------|--------------------------------------------------------------------------------------------|
240+
| `compile-flags` | Flags passed to `rustc` when building the test or aux file | All except for `run-make` | Any valid `rustc` flags, e.g. `-Awarnings -Dfoo`. Cannot be `-Cincremental` or `--edition` |
241+
| `edition` | The edition used to build the test | All except for `run-make` | Any valid `--edition` value |
242+
| `rustc-env` | Env var to set when running `rustc` | All except for `run-make` | `<KEY>=<VALUE>` |
243+
| `unset-rustc-env` | Env var to unset when running `rustc` | All except for `run-make` | Any env var name |
244+
| `incremental` | Proper incremental support for tests outside of incremental test suite | `ui`, `crashes` | N/A |
245+
| `no-prefer-dynamic` | Don't use `-C prefer-dynamic`, don't build as a dylib via a `--crate-type=dylib` preset flag | `ui`, `crashes` | N/A |
240246

241247
<div class="warning">
242248
Tests (outside of `run-make`) that want to use incremental tests not in the

src/tests/ui.md

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,7 @@ It should be preferred to using `error-pattern`, which is imprecise and non-exha
303303
### `error-pattern`
304304

305305
The `error-pattern` [directive](directives.md) can be used for runtime messages, which don't
306-
have a specific span, or for compile time messages if imprecise matching is required due to
307-
multi-line platform specific diagnostics.
306+
have a specific span, or in exceptional cases for compile time messages.
308307

309308
Let's think about this test:
310309

@@ -318,7 +317,7 @@ fn main() {
318317
```
319318

320319
We want to ensure this shows "index out of bounds" but we cannot use the `ERROR`
321-
annotation since the error doesn't have any span. Then it's time to use the
320+
annotation since the runtime error doesn't have any span. Then it's time to use the
322321
`error-pattern` directive:
323322

324323
```rust,ignore
@@ -331,29 +330,51 @@ fn main() {
331330
}
332331
```
333332

334-
But for strict testing, try to use the `ERROR` annotation as much as possible,
335-
including `//~?` annotations for diagnostics without span.
336-
For compile time diagnostics `error-pattern` should very rarely be necessary.
333+
Use of `error-pattern` is not recommended in general.
337334

338-
Per-line annotations (`//~`) are still checked in tests using `error-pattern`.
339-
To opt out of these checks, use `//@ compile-flags: --error-format=human`.
340-
Do that only in exceptional cases.
335+
For strict testing of compile time output, try to use the line annotations `//~` as much as
336+
possible, including `//~?` annotations for diagnostics without span.
341337

342-
### Error levels
338+
If the compile time output is target dependent or too verbose, use directive
339+
`//@ dont-require-annotations: <diagnostic-kind>` to make the line annotation checking
340+
non-exhaustive, some of the compiler messages can stay uncovered by annotations in this mode.
343341

344-
The error levels that you can have are:
342+
For checking runtime output `//@ check-run-results` may be preferable.
343+
344+
Only use `error-pattern` if none of the above works.
345+
346+
Line annotations `//~` are still checked in tests using `error-pattern`.
347+
In exceptional cases use `//@ compile-flags: --error-format=human` to opt out of these checks.
348+
349+
### Diagnostic kinds (error levels)
350+
351+
The diagnostic kinds that you can have are:
345352

346353
- `ERROR`
347-
- `WARN` or `WARNING`
354+
- `WARN` (or `WARNING`)
348355
- `NOTE`
349-
- `HELP` and `SUGGESTION`
350-
351-
You are allowed to not include a level, but you should include it at least for
352-
the primary message.
356+
- `HELP`
357+
- `SUGGESTION`
353358

354-
The `SUGGESTION` level is used for specifying what the expected replacement text
359+
The `SUGGESTION` kind is used for specifying what the expected replacement text
355360
should be for a diagnostic suggestion.
356361

362+
`ERROR` and `WARN` kinds are required to be exhaustively covered by line annotations
363+
`//~` by default.
364+
365+
Other kinds only need to be line-annotated if at least one annotation of that kind appears
366+
in the test file. For example, one `//~ NOTE` will also require all other `//~ NOTE`s in the file
367+
to be written out explicitly.
368+
369+
Use directive `//@ dont-require-annotations` to opt out of exhaustive annotations.
370+
E.g. use `//@ dont-require-annotations: NOTE` to annotate notes selectively.
371+
Avoid using this directive for `ERROR`s and `WARN`ings, unless there's a serious reason, like
372+
target-dependent compiler output.
373+
374+
Missing diagnostic kinds (`//~ message`) are currently accepted, but are being phased away.
375+
They will match any compiler output kind, but will not force exhaustive annotations for that kind.
376+
Prefer explicit kind and `//@ dont-require-annotations` to achieve the same effect.
377+
357378
UI tests use the `-A unused` flag by default to ignore all unused warnings, as
358379
unused warnings are usually not the focus of a test. However, simple code
359380
samples often have unused warnings. If the test is specifically testing an

0 commit comments

Comments
 (0)