Skip to content

Commit f241f38

Browse files
Rollup merge of rust-lang#107761 - oli-obk:miri_🪵, r=TaKO8Ki
Replace a command line flag with an env var to allow tools to initialize the tracing loggers at their own discretion fixes rust-lang/miri#2778 this was introduced in rust-lang#104645, so this PR reverts the flag-part and uses an env var instead.
2 parents 5b50273 + f95b553 commit f241f38

File tree

6 files changed

+8
-37
lines changed

6 files changed

+8
-37
lines changed

compiler/rustc_driver_impl/src/lib.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,6 @@ fn run_compiler(
229229
registry: diagnostics_registry(),
230230
};
231231

232-
if !tracing::dispatcher::has_been_set() {
233-
init_rustc_env_logger_with_backtrace_option(&config.opts.unstable_opts.log_backtrace);
234-
}
235-
236232
match make_input(config.opts.error_format, &matches.free) {
237233
Err(reported) => return Err(reported),
238234
Ok(Some(input)) => {
@@ -1251,16 +1247,7 @@ pub fn install_ice_hook() {
12511247
/// This allows tools to enable rust logging without having to magically match rustc's
12521248
/// tracing crate version.
12531249
pub fn init_rustc_env_logger() {
1254-
init_rustc_env_logger_with_backtrace_option(&None);
1255-
}
1256-
1257-
/// This allows tools to enable rust logging without having to magically match rustc's
1258-
/// tracing crate version. In contrast to `init_rustc_env_logger` it allows you to
1259-
/// choose a target module you wish to show backtraces along with its logging.
1260-
pub fn init_rustc_env_logger_with_backtrace_option(backtrace_target: &Option<String>) {
1261-
if let Err(error) = rustc_log::init_rustc_env_logger_with_backtrace_option(backtrace_target) {
1262-
early_error(ErrorOutputType::default(), &error.to_string());
1263-
}
1250+
init_env_logger("RUSTC_LOG");
12641251
}
12651252

12661253
/// This allows tools to enable rust logging without having to magically match rustc's
@@ -1324,6 +1311,7 @@ mod signal_handler {
13241311
pub fn main() -> ! {
13251312
let start_time = Instant::now();
13261313
let start_rss = get_resident_set_size();
1314+
init_rustc_env_logger();
13271315
signal_handler::install();
13281316
let mut callbacks = TimePassesCallbacks::default();
13291317
install_ice_hook();

compiler/rustc_interface/src/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,6 @@ fn test_unstable_options_tracking_hash() {
758758
tracked!(link_only, true);
759759
tracked!(llvm_plugins, vec![String::from("plugin_name")]);
760760
tracked!(location_detail, LocationDetail { file: true, line: false, column: false });
761-
tracked!(log_backtrace, Some("filter".to_string()));
762761
tracked!(maximal_hir_to_mir_coverage, true);
763762
tracked!(merge_functions, Some(MergeFunctions::Disabled));
764763
tracked!(mir_emit_retag, true);

compiler/rustc_log/src/lib.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,12 @@ use tracing_subscriber::fmt::{
5454
use tracing_subscriber::layer::SubscriberExt;
5555

5656
pub fn init_rustc_env_logger() -> Result<(), Error> {
57-
init_rustc_env_logger_with_backtrace_option(&None)
58-
}
59-
60-
pub fn init_rustc_env_logger_with_backtrace_option(
61-
backtrace_target: &Option<String>,
62-
) -> Result<(), Error> {
63-
init_env_logger_with_backtrace_option("RUSTC_LOG", backtrace_target)
57+
init_env_logger("RUSTC_LOG")
6458
}
6559

6660
/// In contrast to `init_rustc_env_logger` this allows you to choose an env var
6761
/// other than `RUSTC_LOG`.
6862
pub fn init_env_logger(env: &str) -> Result<(), Error> {
69-
init_env_logger_with_backtrace_option(env, &None)
70-
}
71-
72-
pub fn init_env_logger_with_backtrace_option(
73-
env: &str,
74-
backtrace_target: &Option<String>,
75-
) -> Result<(), Error> {
7663
let filter = match env::var(env) {
7764
Ok(env) => EnvFilter::new(env),
7865
_ => EnvFilter::default().add_directive(Directive::from(LevelFilter::WARN)),
@@ -106,16 +93,16 @@ pub fn init_env_logger_with_backtrace_option(
10693
let layer = layer.with_thread_ids(true).with_thread_names(true);
10794

10895
let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
109-
match backtrace_target {
110-
Some(str) => {
96+
match env::var(format!("{env}_BACKTRACE")) {
97+
Ok(str) => {
11198
let fmt_layer = tracing_subscriber::fmt::layer()
11299
.with_writer(io::stderr)
113100
.without_time()
114101
.event_format(BacktraceFormatter { backtrace_target: str.to_string() });
115102
let subscriber = subscriber.with(fmt_layer);
116103
tracing::subscriber::set_global_default(subscriber).unwrap();
117104
}
118-
None => {
105+
Err(_) => {
119106
tracing::subscriber::set_global_default(subscriber).unwrap();
120107
}
121108
};

compiler/rustc_session/src/options.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1413,8 +1413,6 @@ options! {
14131413
"what location details should be tracked when using caller_location, either \
14141414
`none`, or a comma separated list of location details, for which \
14151415
valid options are `file`, `line`, and `column` (default: `file,line,column`)"),
1416-
log_backtrace: Option<String> = (None, parse_opt_string, [TRACKED],
1417-
"add a backtrace along with logging"),
14181416
ls: bool = (false, parse_bool, [UNTRACKED],
14191417
"list the symbols defined by a library crate (default: no)"),
14201418
macro_backtrace: bool = (false, parse_bool, [UNTRACKED],

tests/rustdoc-ui/z-help.stdout

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
-Z llvm-plugins=val -- a list LLVM plugins to enable (space separated)
7878
-Z llvm-time-trace=val -- generate JSON tracing data file from LLVM data (default: no)
7979
-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`)
80-
-Z log-backtrace=val -- add a backtrace along with logging
8180
-Z ls=val -- list the symbols defined by a library crate (default: no)
8281
-Z macro-backtrace=val -- show macro backtraces (default: no)
8382
-Z maximal-hir-to-mir-coverage=val -- save as much information as possible about the correspondence between MIR and HIR as source scopes (default: no)

tests/ui/attributes/log-backtrace.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// run-pass
22
//
3-
// This test makes sure that log-backtrace option doesn't give a compilation error.
3+
// This test makes sure that log-backtrace option at least parses correctly
44
//
55
// dont-check-compiler-stdout
66
// dont-check-compiler-stderr
77
// rustc-env:RUSTC_LOG=info
8-
// compile-flags: -Zlog-backtrace=rustc_metadata::creader
8+
// rustc-env:RUSTC_LOG_BACKTRACE=rustc_metadata::creader
99
fn main() {}

0 commit comments

Comments
 (0)