From 6dea21a4a255fc246243fabc54436352b5f12c80 Mon Sep 17 00:00:00 2001 From: Hudson Ayers Date: Fri, 22 Jul 2022 12:21:32 -0700 Subject: [PATCH] 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. --- compiler/rustc_session/src/options.rs | 11 +++++++---- .../src/compiler-flags/location-detail.md | 5 +++-- src/test/rustdoc-ui/z-help.stdout | 2 +- .../panics/location-detail-panic-no-location-info.rs | 8 ++++++++ .../location-detail-panic-no-location-info.run.stderr | 2 ++ 5 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 src/test/ui/panics/location-detail-panic-no-location-info.rs create mode 100644 src/test/ui/panics/location-detail-panic-no-location-info.run.stderr diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 501997679f4bf..6d96cf9410bef 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -393,8 +393,7 @@ mod desc { "either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted"; pub const parse_linker_plugin_lto: &str = "either a boolean (`yes`, `no`, `on`, `off`, etc), or the path to the linker plugin"; - pub const parse_location_detail: &str = - "comma separated list of location details to track: `file`, `line`, or `column`"; + pub const parse_location_detail: &str = "either `none`, or a comma separated list of location details to track: `file`, `line`, or `column`"; pub const parse_switch_with_opt_path: &str = "an optional path to the profiling data output directory"; pub const parse_merge_functions: &str = "one of: `disabled`, `trampolines`, or `aliases`"; @@ -549,6 +548,9 @@ mod parse { ld.line = false; ld.file = false; ld.column = false; + if v == "none" { + return true; + } for s in v.split(',') { match s { "file" => ld.file = true, @@ -1360,8 +1362,9 @@ options! { llvm_time_trace: bool = (false, parse_bool, [UNTRACKED], "generate JSON tracing data file from LLVM data (default: no)"), location_detail: LocationDetail = (LocationDetail::all(), parse_location_detail, [TRACKED], - "comma separated list of location details to be tracked when using caller_location \ - valid options are `file`, `line`, and `column` (default: all)"), + "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`)"), ls: bool = (false, parse_bool, [UNTRACKED], "list the symbols defined by a library crate (default: no)"), macro_backtrace: bool = (false, parse_bool, [UNTRACKED], diff --git a/src/doc/unstable-book/src/compiler-flags/location-detail.md b/src/doc/unstable-book/src/compiler-flags/location-detail.md index 08d937cc28200..db07061996964 100644 --- a/src/doc/unstable-book/src/compiler-flags/location-detail.md +++ b/src/doc/unstable-book/src/compiler-flags/location-detail.md @@ -17,8 +17,9 @@ within this list are: - `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. +Any combination of these three options are supported. Alternatively, you can pass +`none` to this option, which results in no location details being tracked. +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 diff --git a/src/test/rustdoc-ui/z-help.stdout b/src/test/rustdoc-ui/z-help.stdout index 86e42440bd0bc..9a492f1a810dc 100644 --- a/src/test/rustdoc-ui/z-help.stdout +++ b/src/test/rustdoc-ui/z-help.stdout @@ -69,7 +69,7 @@ -Z link-only=val -- link the `.rlink` file generated by `-Z no-link` (default: no) -Z llvm-plugins=val -- a list LLVM plugins to enable (space separated) -Z llvm-time-trace=val -- generate JSON tracing data file from LLVM data (default: no) - -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) + -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`) -Z ls=val -- list the symbols defined by a library crate (default: no) -Z macro-backtrace=val -- show macro backtraces (default: no) -Z merge-functions=val -- control the operation of the MergeFunctions LLVM pass, taking the same values as the target option of the same name diff --git a/src/test/ui/panics/location-detail-panic-no-location-info.rs b/src/test/ui/panics/location-detail-panic-no-location-info.rs new file mode 100644 index 0000000000000..7b609145bad72 --- /dev/null +++ b/src/test/ui/panics/location-detail-panic-no-location-info.rs @@ -0,0 +1,8 @@ +// run-fail +// check-run-results +// compile-flags: -Zlocation-detail=none +// exec-env:RUST_BACKTRACE=0 + +fn main() { + panic!("no location info"); +} diff --git a/src/test/ui/panics/location-detail-panic-no-location-info.run.stderr b/src/test/ui/panics/location-detail-panic-no-location-info.run.stderr new file mode 100644 index 0000000000000..d1c3108643c6c --- /dev/null +++ b/src/test/ui/panics/location-detail-panic-no-location-info.run.stderr @@ -0,0 +1,2 @@ +thread 'main' panicked at 'no location info', :0:0 +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace