-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Implement -Z location-detail flag #89920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a9a1393
Add -Z location-detail flag
hudson-ayers e1d94b8
Configure saved panic locations based on location-detail flag
hudson-ayers 8090f67
document the unstable location-detail flag
hudson-ayers b802629
add tests for -Zlocation-detail
hudson-ayers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/doc/unstable-book/src/compiler-flags/location-detail.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# `location-detail` | ||
|
||
The tracking issue for this feature is: [#70580](https://github.com/rust-lang/rust/issues/70580). | ||
|
||
------------------------ | ||
|
||
Option `-Z location-detail=val` controls what location details are tracked when | ||
using `caller_location`. This allows users to control what location details | ||
are printed as part of panic messages, by allowing them to exclude any combination | ||
of filenames, line numbers, and column numbers. This option is intended to provide | ||
users with a way to mitigate the size impact of `#[track_caller]`. | ||
|
||
This option supports a comma separated list of location details to be included. Valid options | ||
within this list are: | ||
|
||
- `file` - the filename of the panic will be included in the panic output | ||
- `line` - the source line of the panic will be included in the panic output | ||
- `column` - the source column of the panic will be included in the panic output | ||
|
||
Any combination of these three options are supported. If this option is not specified, | ||
all three are included by default. | ||
|
||
An example of a panic output when using `-Z location-detail=line`: | ||
```text | ||
panicked at 'Process blink had a fault', <redacted>:323:0 | ||
``` | ||
|
||
The code size savings from this option are two-fold. First, the `&'static str` values | ||
for each path to a file containing a panic are removed from the binary. For projects | ||
with deep directory structures and many files with panics, this can add up. This category | ||
of savings can only be realized by excluding filenames from the panic output. Second, | ||
savings can be realized by allowing multiple panics to be fused into a single panicking | ||
branch. It is often the case that within a single file, multiple panics with the same | ||
panic message exist -- e.g. two calls to `Option::unwrap()` in a single line, or | ||
two calls to `Result::expect()` on adjacent lines. If column and line information | ||
are included in the `Location` struct passed to the panic handler, these branches cannot | ||
be fused, as the output is different depending on which panic occurs. However if line | ||
and column information is identical for all panics, these branches can be fused, which | ||
can lead to substantial code size savings, especially for small embedded binaries with | ||
many panics. | ||
|
||
The savings from this option are amplified when combined with the use of `-Zbuild-std`, as | ||
otherwise paths for panics within the standard library are still included in your binary. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// run-fail | ||
// check-run-results | ||
// compile-flags: -Zlocation-detail=line,file | ||
|
||
fn main() { | ||
panic!("column-redacted"); | ||
} |
2 changes: 2 additions & 0 deletions
2
src/test/ui/panics/location-detail-panic-no-column.run.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
thread 'main' panicked at 'column-redacted', $DIR/location-detail-panic-no-column.rs:6:0 | ||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// run-fail | ||
// check-run-results | ||
// compile-flags: -Zlocation-detail=line,column | ||
|
||
fn main() { | ||
panic!("file-redacted"); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
thread 'main' panicked at 'file-redacted', <redacted>:6:5 | ||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// run-fail | ||
// check-run-results | ||
// compile-flags: -Zlocation-detail=file,column | ||
|
||
fn main() { | ||
panic!("line-redacted"); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
thread 'main' panicked at 'line-redacted', $DIR/location-detail-panic-no-line.rs:0:5 | ||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// run-fail | ||
// check-run-results | ||
// compile-flags: -Zlocation-detail=line,column | ||
|
||
fn main() { | ||
let opt: Option<u32> = None; | ||
opt.unwrap(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', <redacted>:7:9 | ||
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.