@@ -52,15 +52,6 @@ By default, if rustc encounters an Internal Compiler Error (ICE) it will dump th
52
52
ICE file within the current working directory named ` rustc-ice-<timestamp>-<pid>.txt ` . If this is
53
53
not desirable, you can prevent the ICE file from being created with ` RUSTC_ICE=0 ` .
54
54
55
- ## ` -Z ` flags
56
-
57
- The compiler has a bunch of ` -Z ` flags. These are unstable flags that are only
58
- enabled on nightly. Many of them are useful for debugging. To get a full listing
59
- of ` -Z ` flags, use ` -Z help ` .
60
-
61
- One useful flag is ` -Z verbose-internals ` , which generally enables printing more
62
- info that could be useful for debugging.
63
-
64
55
## Getting a backtrace
65
56
[ getting-a-backtrace ] : #getting-a-backtrace
66
57
@@ -109,7 +100,18 @@ stack backtrace:
109
100
at /home/user/rust/compiler/rustc_driver/src/lib.rs:253
110
101
```
111
102
112
- ## Getting a backtrace for errors
103
+ ## ` -Z ` flags
104
+
105
+ The compiler has a bunch of ` -Z * ` flags. These are unstable flags that are only
106
+ enabled on nightly. Many of them are useful for debugging. To get a full listing
107
+ of ` -Z ` flags, use ` -Z help ` .
108
+
109
+ One useful flag is ` -Z verbose-internals ` , which generally enables printing more
110
+ info that could be useful for debugging.
111
+
112
+ Right below you can find elaborate explainers on a selected few.
113
+
114
+ ### Getting a backtrace for errors
113
115
[ getting-a-backtrace-for-errors ] : #getting-a-backtrace-for-errors
114
116
115
117
If you want to get a backtrace to the point where the compiler emits an
@@ -186,14 +188,14 @@ stack backtrace:
186
188
187
189
Cool, now I have a backtrace for the error!
188
190
189
- ## Debugging delayed bugs
191
+ ### Debugging delayed bugs
190
192
191
193
The ` -Z eagerly-emit-delayed-bugs ` option makes it easy to debug delayed bugs.
192
194
It turns them into normal errors, i.e. makes them visible. This can be used in
193
195
combination with ` -Z treat-err-as-bug ` to stop at a particular delayed bug and
194
196
get a backtrace.
195
197
196
- ## Getting the error creation location
198
+ ### Getting the error creation location
197
199
198
200
` -Z track-diagnostics ` can help figure out where errors are emitted. It uses ` #[track_caller] `
199
201
for this and prints its location alongside the error:
@@ -235,21 +237,6 @@ The compiler uses the [`tracing`] crate for logging.
235
237
236
238
For details see [ the guide section on tracing] ( ./tracing.md )
237
239
238
- ## Formatting Graphviz output (.dot files)
239
- [ formatting-graphviz-output ] : #formatting-graphviz-output
240
-
241
- Some compiler options for debugging specific features yield graphviz graphs -
242
- e.g. the ` #[rustc_mir(borrowck_graphviz_postflow="suffix.dot")] ` attribute
243
- dumps various borrow-checker dataflow graphs.
244
-
245
- These all produce ` .dot ` files. To view these files, install graphviz (e.g.
246
- ` apt-get install graphviz ` ) and then run the following commands:
247
-
248
- ``` bash
249
- $ dot -T pdf maybe_init_suffix.dot > maybe_init_suffix.pdf
250
- $ firefox maybe_init_suffix.pdf # Or your favorite pdf viewer
251
- ```
252
-
253
240
## Narrowing (Bisecting) Regressions
254
241
255
242
The [ cargo-bisect-rustc] [ bisect ] tool can be used as a quick and easy way to
@@ -273,10 +260,61 @@ without doing the build yourself.
273
260
274
261
[ rtim ] : https://github.com/kennytm/rustup-toolchain-install-master
275
262
276
- ## Debugging type layouts
263
+ ## ` #[rustc_*] ` TEST attributes
264
+
265
+ The compiler defines a whole lot of internal (perma-unstable) attributes some of which are useful
266
+ for debugging by dumping extra compiler-internal information. These are prefixed with ` rustc_ ` and
267
+ are gated behind the internal feature ` rustc_attrs ` (enabled via e.g. ` #![feature(rustc_attrs)] ` ).
268
+
269
+ For a complete and up to date list, see [ ` builtin_attrs ` ] . More specifically, the ones marked ` TEST ` .
270
+ Here are some notable ones:
271
+
272
+ | Attribute | Description |
273
+ | ----------------| -------------|
274
+ | ` rustc_def_path ` | Dumps the [ ` def_path_str ` ] of an item. |
275
+ | ` rustc_dump_def_parents ` | Dumps the chain of ` DefId ` parents of certain definitions. |
276
+ | ` rustc_dump_item_bounds ` | Dumps the [ ` item_bounds ` ] of an item. |
277
+ | ` rustc_dump_predicates ` | Dumps the [ ` predicates_of ` ] an item. |
278
+ | ` rustc_dump_vtable ` | |
279
+ | ` rustc_hidden_type_of_opaques ` | Dumps the [ hidden type of all opaque types] [ opaq ] in the crate. |
280
+ | ` rustc_layout ` | [ See this section] ( #debugging-type-layouts ) . |
281
+ | ` rustc_object_lifetime_default ` | Dumps the [ object lifetime defaults] of an item. |
282
+ | ` rustc_outlives ` | Dumps implied bounds of an item. More precisely, the [ ` inferred_outlives_of ` ] an item. |
283
+ | ` rustc_regions ` | Dumps NLL closure region requirements. |
284
+ | ` rustc_symbol_name ` | Dumps the mangled & demangled [ ` symbol_name ` ] of an item. |
285
+ | ` rustc_variances ` | Dumps the [ variances] of an item. |
286
+
287
+ Right below you can find elaborate explainers on a selected few.
288
+
289
+ [ `builtin_attrs` ] : https://github.com/rust-lang/rust/blob/master/compiler/rustc_feature/src/builtin_attrs.rs
290
+ [ `def_path_str` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.def_path_str
291
+ [ `inferred_outlives_of` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.inferred_outlives_of
292
+ [ `item_bounds` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.item_bounds
293
+ [ `predicates_of` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.predicates_of
294
+ [ `symbol_name` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.symbol_name
295
+ [ object lifetime defaults ] : https://doc.rust-lang.org/reference/lifetime-elision.html#default-trait-object-lifetimes
296
+ [ opaq ] : ./opaque-types-impl-trait-inference.md
297
+ [ variances ] : ./variance.md
298
+
299
+ ### Formatting Graphviz output (.dot files)
300
+ [ formatting-graphviz-output ] : #formatting-graphviz-output
301
+
302
+ Some compiler options for debugging specific features yield graphviz graphs -
303
+ e.g. the ` #[rustc_mir(borrowck_graphviz_postflow="suffix.dot")] ` attribute
304
+ dumps various borrow-checker dataflow graphs.
305
+
306
+ These all produce ` .dot ` files. To view these files, install graphviz (e.g.
307
+ ` apt-get install graphviz ` ) and then run the following commands:
308
+
309
+ ``` bash
310
+ $ dot -T pdf maybe_init_suffix.dot > maybe_init_suffix.pdf
311
+ $ firefox maybe_init_suffix.pdf # Or your favorite pdf viewer
312
+ ```
313
+
314
+ ### Debugging type layouts
277
315
278
- The (permanently) unstable ` #[rustc_layout] ` attribute can be used to dump
279
- the [ ` Layout ` ] of the type it is attached to. For example:
316
+ The internal attribute ` #[rustc_layout] ` can be used to dump the [ ` Layout ` ] of
317
+ the type it is attached to. For example:
280
318
281
319
``` rust
282
320
#![feature(rustc_attrs)]
0 commit comments