Skip to content

Commit 9cc06eb

Browse files
authored
Rollup merge of #99620 - hudson-ayers:fix-location-detail, r=davidtwco
`-Z location-detail`: provide option to disable all location details As reported [here](#89920 (comment)), when I first implemented the `-Z location-detail` flag there was a bug, where passing an empty list was not correctly supported, and instead rejected by the compiler. This PR fixes that such that passing an empty list results in no location details being tracked, as originally specified in rust-lang/rfcs#2091 . This PR also adds a test case to verify that this option continues to work as intended.
2 parents e820ecd + 6dea21a commit 9cc06eb

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

compiler/rustc_session/src/options.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,7 @@ mod desc {
393393
"either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted";
394394
pub const parse_linker_plugin_lto: &str =
395395
"either a boolean (`yes`, `no`, `on`, `off`, etc), or the path to the linker plugin";
396-
pub const parse_location_detail: &str =
397-
"comma separated list of location details to track: `file`, `line`, or `column`";
396+
pub const parse_location_detail: &str = "either `none`, or a comma separated list of location details to track: `file`, `line`, or `column`";
398397
pub const parse_switch_with_opt_path: &str =
399398
"an optional path to the profiling data output directory";
400399
pub const parse_merge_functions: &str = "one of: `disabled`, `trampolines`, or `aliases`";
@@ -551,6 +550,9 @@ mod parse {
551550
ld.line = false;
552551
ld.file = false;
553552
ld.column = false;
553+
if v == "none" {
554+
return true;
555+
}
554556
for s in v.split(',') {
555557
match s {
556558
"file" => ld.file = true,
@@ -1374,8 +1376,9 @@ options! {
13741376
llvm_time_trace: bool = (false, parse_bool, [UNTRACKED],
13751377
"generate JSON tracing data file from LLVM data (default: no)"),
13761378
location_detail: LocationDetail = (LocationDetail::all(), parse_location_detail, [TRACKED],
1377-
"comma separated list of location details to be tracked when using caller_location \
1378-
valid options are `file`, `line`, and `column` (default: all)"),
1379+
"what location details should be tracked when using caller_location, either \
1380+
`none`, or a comma separated list of location details, for which \
1381+
valid options are `file`, `line`, and `column` (default: `file,line,column`)"),
13791382
ls: bool = (false, parse_bool, [UNTRACKED],
13801383
"list the symbols defined by a library crate (default: no)"),
13811384
macro_backtrace: bool = (false, parse_bool, [UNTRACKED],

src/doc/unstable-book/src/compiler-flags/location-detail.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ within this list are:
1717
- `line` - the source line of the panic will be included in the panic output
1818
- `column` - the source column of the panic will be included in the panic output
1919

20-
Any combination of these three options are supported. If this option is not specified,
21-
all three are included by default.
20+
Any combination of these three options are supported. Alternatively, you can pass
21+
`none` to this option, which results in no location details being tracked.
22+
If this option is not specified, all three are included by default.
2223

2324
An example of a panic output when using `-Z location-detail=line`:
2425
```text

src/test/rustdoc-ui/z-help.stdout

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
-Z link-only=val -- link the `.rlink` file generated by `-Z no-link` (default: no)
7070
-Z llvm-plugins=val -- a list LLVM plugins to enable (space separated)
7171
-Z llvm-time-trace=val -- generate JSON tracing data file from LLVM data (default: no)
72-
-Z location-detail=val -- comma separated list of location details to be tracked when using caller_location valid options are `file`, `line`, and `column` (default: all)
72+
-Z location-detail=val -- what location details should be tracked when using caller_location, either `none`, or a comma separated list of location details, for which valid options are `file`, `line`, and `column` (default: `file,line,column`)
7373
-Z ls=val -- list the symbols defined by a library crate (default: no)
7474
-Z macro-backtrace=val -- show macro backtraces (default: no)
7575
-Z merge-functions=val -- control the operation of the MergeFunctions LLVM pass, taking the same values as the target option of the same name
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// run-fail
2+
// check-run-results
3+
// compile-flags: -Zlocation-detail=none
4+
// exec-env:RUST_BACKTRACE=0
5+
6+
fn main() {
7+
panic!("no location info");
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
thread 'main' panicked at 'no location info', <redacted>:0:0
2+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

0 commit comments

Comments
 (0)