|
| 1 | +# `location-detail` |
| 2 | + |
| 3 | +The tracking issue for this feature is: [#70580](https://github.com/rust-lang/rust/issues/70580). |
| 4 | + |
| 5 | +------------------------ |
| 6 | + |
| 7 | +Option `-Z location-detail=val` controls what location details are tracked when |
| 8 | +using `caller_location`. This allows users to control what location details |
| 9 | +are printed as part of panic messages, by allowing them to exclude any combination |
| 10 | +of filenames, line numbers, and column numbers. This option is intended to provide |
| 11 | +users with a way to mitigate the size impact of `#[track_caller]`. |
| 12 | + |
| 13 | +This option supports a comma separated list of location details to be included. Valid options |
| 14 | +within this list are: |
| 15 | + |
| 16 | +- `file` - the filename of the panic will be included in the panic output |
| 17 | +- `line` - the source line of the panic will be included in the panic output |
| 18 | +- `column` - the source column of the panic will be included in the panic output |
| 19 | + |
| 20 | +Any combination of these three options are supported. If this option is not specified, |
| 21 | +all three are included by default. |
| 22 | + |
| 23 | +An example of a panic output when using `-Z location-detail=line`: |
| 24 | +```text |
| 25 | +panicked at 'Process blink had a fault', <redacted>:323:0 |
| 26 | +``` |
| 27 | + |
| 28 | +The code size savings from this option are two-fold. First, the `&'static str` values |
| 29 | +for each path to a file containing a panic are removed from the binary. For projects |
| 30 | +with deep directory structures and many files with panics, this can add up. This category |
| 31 | +of savings can only be realized by excluding filenames from the panic output. Second, |
| 32 | +savings can be realized by allowing multiple panics to be fused into a single panicking |
| 33 | +branch. It is often the case that within a single file, multiple panics with the same |
| 34 | +panic message exist -- e.g. two calls to `Option::unwrap()` in a single line, or |
| 35 | +two calls to `Result::expect()` on adjacent lines. If column and line information |
| 36 | +are included in the `Location` struct passed to the panic handler, these branches cannot |
| 37 | +be fused, as the output is different depending on which panic occurs. However if line |
| 38 | +and column information is identical for all panics, these branches can be fused, which |
| 39 | +can lead to substantial code size savings, especially for small embedded binaries with |
| 40 | +many panics. |
| 41 | + |
| 42 | +The savings from this option are amplified when combined with the use of `-Zbuild-std`, as |
| 43 | +otherwise paths for panics within the standard library are still included in your binary. |
0 commit comments