Skip to content

Commit a9a1393

Browse files
committed
Add -Z location-detail flag
1 parent 97e3b30 commit a9a1393

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

compiler/rustc_session/src/config.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,20 @@ impl LinkerPluginLto {
174174
}
175175
}
176176

177+
/// The different settings that can be enabled via the `-Z location-detail` flag.
178+
#[derive(Clone, PartialEq, Hash, Debug)]
179+
pub struct LocationDetail {
180+
pub file: bool,
181+
pub line: bool,
182+
pub column: bool,
183+
}
184+
185+
impl LocationDetail {
186+
pub fn all() -> Self {
187+
Self { file: true, line: true, column: true }
188+
}
189+
}
190+
177191
#[derive(Clone, PartialEq, Hash, Debug)]
178192
pub enum SwitchWithOptPath {
179193
Enabled(Option<PathBuf>),
@@ -2422,7 +2436,7 @@ crate mod dep_tracking {
24222436
use super::LdImpl;
24232437
use super::{
24242438
CFGuard, CrateType, DebugInfo, ErrorOutputType, InstrumentCoverage, LinkerPluginLto,
2425-
LtoCli, OptLevel, OutputType, OutputTypes, Passes, SourceFileHashAlgorithm,
2439+
LocationDetail, LtoCli, OptLevel, OutputType, OutputTypes, Passes, SourceFileHashAlgorithm,
24262440
SwitchWithOptPath, SymbolManglingVersion, TrimmedDefPaths,
24272441
};
24282442
use crate::lint;
@@ -2513,6 +2527,7 @@ crate mod dep_tracking {
25132527
Option<LdImpl>,
25142528
OutputType,
25152529
RealFileName,
2530+
LocationDetail,
25162531
);
25172532

25182533
impl<T1, T2> DepTrackingHash for (T1, T2)

compiler/rustc_session/src/options.rs

+24
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ mod desc {
368368
"either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted";
369369
pub const parse_linker_plugin_lto: &str =
370370
"either a boolean (`yes`, `no`, `on`, `off`, etc), or the path to the linker plugin";
371+
pub const parse_location_detail: &str =
372+
"comma seperated list of location details to track: `file`, `line`, or `column`";
371373
pub const parse_switch_with_opt_path: &str =
372374
"an optional path to the profiling data output directory";
373375
pub const parse_merge_functions: &str = "one of: `disabled`, `trampolines`, or `aliases`";
@@ -484,6 +486,25 @@ mod parse {
484486
}
485487
}
486488

489+
crate fn parse_location_detail(ld: &mut LocationDetail, v: Option<&str>) -> bool {
490+
if let Some(v) = v {
491+
ld.line = false;
492+
ld.file = false;
493+
ld.column = false;
494+
for s in v.split(',') {
495+
match s {
496+
"file" => ld.file = true,
497+
"line" => ld.line = true,
498+
"column" => ld.column = true,
499+
_ => return false,
500+
}
501+
}
502+
true
503+
} else {
504+
false
505+
}
506+
}
507+
487508
crate fn parse_opt_comma_list(slot: &mut Option<Vec<String>>, v: Option<&str>) -> bool {
488509
match v {
489510
Some(s) => {
@@ -1152,6 +1173,9 @@ options! {
11521173
"a list LLVM plugins to enable (space separated)"),
11531174
llvm_time_trace: bool = (false, parse_bool, [UNTRACKED],
11541175
"generate JSON tracing data file from LLVM data (default: no)"),
1176+
location_detail: LocationDetail = (LocationDetail::all(), parse_location_detail, [TRACKED],
1177+
"comma seperated list of location details to be tracked when using caller_location \
1178+
valid options are `file`, `line`, and `column` (default: all)"),
11551179
ls: bool = (false, parse_bool, [UNTRACKED],
11561180
"list the symbols defined by a library crate (default: no)"),
11571181
macro_backtrace: bool = (false, parse_bool, [UNTRACKED],

0 commit comments

Comments
 (0)