Skip to content

Commit 3503a64

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents 9c1b9c8 + 21cacd1 commit 3503a64

File tree

7 files changed

+71
-49
lines changed

7 files changed

+71
-49
lines changed

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/tests/directives.md

Lines changed: 1 addition & 0 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>` |

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

src/ty.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ Here is a summary:
6161
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
6262
| Describe the *syntax* of a type: what the user wrote (with some desugaring). | Describe the *semantics* of a type: the meaning of what the user wrote. |
6363
| Each `rustc_hir::Ty` has its own spans corresponding to the appropriate place in the program. | Doesn’t correspond to a single place in the user’s program. |
64-
| `rustc_hir::Ty` has generics and lifetimes; however, some of those lifetimes are special markers like [`LifetimeName::Implicit`][implicit]. | `ty::Ty` has the full type, including generics and lifetimes, even if the user left them out |
64+
| `rustc_hir::Ty` has generics and lifetimes; however, some of those lifetimes are special markers like [`LifetimeKind::Implicit`][implicit]. | `ty::Ty` has the full type, including generics and lifetimes, even if the user left them out |
6565
| `fn foo(x: u32) → u32 { }` - Two `rustc_hir::Ty` representing each usage of `u32`, each has its own `Span`s, and `rustc_hir::Ty` doesn’t tell us that both are the same type | `fn foo(x: u32) → u32 { }` - One `ty::Ty` for all instances of `u32` throughout the program, and `ty::Ty` tells us that both usages of `u32` mean the same type. |
66-
| `fn foo(x: &u32) -> &u32)` - Two `rustc_hir::Ty` again. Lifetimes for the references show up in the `rustc_hir::Ty`s using a special marker, [`LifetimeName::Implicit`][implicit]. | `fn foo(x: &u32) -> &u32)`- A single `ty::Ty`. The `ty::Ty` has the hidden lifetime param. |
66+
| `fn foo(x: &u32) -> &u32)` - Two `rustc_hir::Ty` again. Lifetimes for the references show up in the `rustc_hir::Ty`s using a special marker, [`LifetimeKind::Implicit`][implicit]. | `fn foo(x: &u32) -> &u32)`- A single `ty::Ty`. The `ty::Ty` has the hidden lifetime param. |
6767

68-
[implicit]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.LifetimeName.html#variant.Implicit
68+
[implicit]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.LifetimeKind.html#variant.Implicit
6969

7070
**Order**
7171

@@ -323,4 +323,4 @@ When looking at the debug output of `Ty` or simply talking about different types
323323
- Generic parameters: `{name}/#{index}` e.g. `T/#0`, where `index` corresponds to its position in the list of generic parameters
324324
- Inference variables: `?{id}` e.g. `?x`/`?0`, where `id` identifies the inference variable
325325
- Variables from binders: `^{binder}_{index}` e.g. `^0_x`/`^0_2`, where `binder` and `index` identify which variable from which binder is being referred to
326-
- Placeholders: `!{id}` or `!{id}_{universe}` e.g. `!x`/`!0`/`!x_2`/`!0_2`, representing some unique type in the specified universe. The universe is often elided when it is `0`
326+
- Placeholders: `!{id}` or `!{id}_{universe}` e.g. `!x`/`!0`/`!x_2`/`!0_2`, representing some unique type in the specified universe. The universe is often elided when it is `0`

0 commit comments

Comments
 (0)