Skip to content

Commit 6dea21a

Browse files
committed
location-detail: disable all location details when passed none
Prior to this fix, `-Z location-detail` provided no mechanism for disabling all location details. This commit also adds a test case to verify that this option continues to work as intended, and clarifies the documentation of this option.
1 parent 05e678c commit 6dea21a

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`";
@@ -549,6 +548,9 @@ mod parse {
549548
ld.line = false;
550549
ld.file = false;
551550
ld.column = false;
551+
if v == "none" {
552+
return true;
553+
}
552554
for s in v.split(',') {
553555
match s {
554556
"file" => ld.file = true,
@@ -1360,8 +1362,9 @@ options! {
13601362
llvm_time_trace: bool = (false, parse_bool, [UNTRACKED],
13611363
"generate JSON tracing data file from LLVM data (default: no)"),
13621364
location_detail: LocationDetail = (LocationDetail::all(), parse_location_detail, [TRACKED],
1363-
"comma separated list of location details to be tracked when using caller_location \
1364-
valid options are `file`, `line`, and `column` (default: all)"),
1365+
"what location details should be tracked when using caller_location, either \
1366+
`none`, or a comma separated list of location details, for which \
1367+
valid options are `file`, `line`, and `column` (default: `file,line,column`)"),
13651368
ls: bool = (false, parse_bool, [UNTRACKED],
13661369
"list the symbols defined by a library crate (default: no)"),
13671370
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)