From e7f04857efc4ebc369e588d194e5288ef57752e7 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 7 Oct 2021 09:17:57 -0700 Subject: [PATCH 1/8] rustc_driver: Enable the `WARN` log level by default This commit changes the `tracing_subscriber` initialization in `rustc_driver` so that the `WARN` verbosity level is enabled by default when the `RUSTC_LOG` env variable is empty. If the `RUSTC_LOG` env variable is set, the filter string in the environment variable is honored, instead. Fixes #76824 Closes #89623 cc @eddyb, @oli-obk --- compiler/rustc_driver/src/lib.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index ab7ee03b643..c658bf322e5 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -1253,12 +1253,16 @@ pub fn init_rustc_env_logger() { /// tracing crate version. In contrast to `init_rustc_env_logger` it allows you to choose an env var /// other than `RUSTC_LOG`. pub fn init_env_logger(env: &str) { - // Don't register a dispatcher if there's no filter to print anything - match std::env::var(env) { - Err(_) => return, - Ok(s) if s.is_empty() => return, - Ok(_) => {} - } + use tracing_subscriber::{ + filter::{self, EnvFilter, LevelFilter}, + layer::SubscriberExt, + }; + + let filter = match std::env::var(env) { + Ok(env) => EnvFilter::from_env(env), + _ => EnvFilter::default().add_directive(filter::Directive::from(LevelFilter: WARN)), + }; + let color_logs = match std::env::var(String::from(env) + "_COLOR") { Ok(value) => match value.as_ref() { "always" => true, @@ -1278,7 +1282,7 @@ pub fn init_env_logger(env: &str) { "non-Unicode log color value: expected one of always, never, or auto", ), }; - let filter = tracing_subscriber::EnvFilter::from_env(env); + let layer = tracing_tree::HierarchicalLayer::default() .with_writer(io::stderr) .with_indent_lines(true) @@ -1288,7 +1292,6 @@ pub fn init_env_logger(env: &str) { #[cfg(parallel_compiler)] let layer = layer.with_thread_ids(true).with_thread_names(true); - use tracing_subscriber::layer::SubscriberExt; let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer); tracing::subscriber::set_global_default(subscriber).unwrap(); } From eb67bf936829406ca58f9aa12169e05bdd3b2d2e Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 7 Oct 2021 09:52:51 -0700 Subject: [PATCH 2/8] Update compiler/rustc_driver/src/lib.rs Co-authored-by: Joshua Nelson --- compiler/rustc_driver/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index c658bf322e5..05c7e11cbc2 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -1260,7 +1260,7 @@ pub fn init_env_logger(env: &str) { let filter = match std::env::var(env) { Ok(env) => EnvFilter::from_env(env), - _ => EnvFilter::default().add_directive(filter::Directive::from(LevelFilter: WARN)), + _ => EnvFilter::default().add_directive(filter::Directive::from(LevelFilter::WARN)), }; let color_logs = match std::env::var(String::from(env) + "_COLOR") { From 01803025d2afd7b6869878734fa411e8c659f68b Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 7 Oct 2021 10:45:39 -0700 Subject: [PATCH 3/8] demote `rustc_peek` traces look not user-facing Signed-off-by: Eliza Weisman --- compiler/rustc_mir_dataflow/src/rustc_peek.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_mir_dataflow/src/rustc_peek.rs b/compiler/rustc_mir_dataflow/src/rustc_peek.rs index 29ffed99344..214d6376c7f 100644 --- a/compiler/rustc_mir_dataflow/src/rustc_peek.rs +++ b/compiler/rustc_mir_dataflow/src/rustc_peek.rs @@ -289,7 +289,7 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeMutBorrowedLocals<'_, 'tcx> { flow_state: &BitSet, call: PeekCall, ) { - warn!("peek_at: place={:?}", place); + info!("peek_at: place={:?}", place); let local = if let Some(l) = place.as_local() { l } else { @@ -311,7 +311,7 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeLiveLocals { flow_state: &BitSet, call: PeekCall, ) { - warn!("peek_at: place={:?}", place); + info!("peek_at: place={:?}", place); let local = if let Some(l) = place.as_local() { l } else { From 928c787fcee7a15f20da3407d479b69da601644a Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 7 Oct 2021 10:46:47 -0700 Subject: [PATCH 4/8] make them structured while i'm here Signed-off-by: Eliza Weisman --- compiler/rustc_mir_dataflow/src/rustc_peek.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_mir_dataflow/src/rustc_peek.rs b/compiler/rustc_mir_dataflow/src/rustc_peek.rs index 214d6376c7f..ee8fca961f6 100644 --- a/compiler/rustc_mir_dataflow/src/rustc_peek.rs +++ b/compiler/rustc_mir_dataflow/src/rustc_peek.rs @@ -289,7 +289,7 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeMutBorrowedLocals<'_, 'tcx> { flow_state: &BitSet, call: PeekCall, ) { - info!("peek_at: place={:?}", place); + info!(?place, "peek_at",); let local = if let Some(l) = place.as_local() { l } else { @@ -311,7 +311,7 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeLiveLocals { flow_state: &BitSet, call: PeekCall, ) { - info!("peek_at: place={:?}", place); + info!(?place, "peek_at"); let local = if let Some(l) = place.as_local() { l } else { From e00eac8b9c4af0bd6baa4b645773fdfa86829fcb Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 7 Oct 2021 10:48:48 -0700 Subject: [PATCH 5/8] use structured fields in some existing warnings Signed-off-by: Eliza Weisman --- compiler/rustc_codegen_ssa/src/back/link.rs | 9 ++++----- compiler/rustc_errors/src/emitter.rs | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index ed15b464872..19eff1a3a3c 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -844,8 +844,8 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( if out.contains(msg_segv) || out.contains(msg_bus) { warn!( "looks like the linker segfaulted when we tried to call it, \ - automatically retrying again. cmd = {:?}, out = {}.", - cmd, out, + automatically retrying again", + ?cmd, %out, ); continue; } @@ -853,9 +853,8 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( if is_illegal_instruction(&output.status) { warn!( "looks like the linker hit an illegal instruction when we \ - tried to call it, automatically retrying again. cmd = {:?}, ]\ - out = {}, status = {}.", - cmd, out, output.status, + tried to call it, automatically retrying again." + ?cmd, %out, status = %output.status, ); continue; } diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 29f352ae585..778d58eeadc 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -2308,7 +2308,7 @@ pub fn is_case_difference(sm: &SourceMap, suggested: &str, sp: Span) -> bool { let found = match sm.span_to_snippet(sp) { Ok(snippet) => snippet, Err(e) => { - warn!("Invalid span {:?}. Err={:?}", sp, e); + warn!(error = ?e, "Invalid span {:?}", sp); return false; } }; From b6f09a19b2345a6a898d176570496dea44b06aac Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 7 Oct 2021 11:29:47 -0700 Subject: [PATCH 6/8] comma-related changes Signed-off-by: Eliza Weisman --- compiler/rustc_codegen_ssa/src/back/link.rs | 2 +- compiler/rustc_mir_dataflow/src/rustc_peek.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 19eff1a3a3c..b5429064324 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -853,7 +853,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( if is_illegal_instruction(&output.status) { warn!( "looks like the linker hit an illegal instruction when we \ - tried to call it, automatically retrying again." + tried to call it, automatically retrying again.", ?cmd, %out, status = %output.status, ); continue; diff --git a/compiler/rustc_mir_dataflow/src/rustc_peek.rs b/compiler/rustc_mir_dataflow/src/rustc_peek.rs index ee8fca961f6..c0bf4b659aa 100644 --- a/compiler/rustc_mir_dataflow/src/rustc_peek.rs +++ b/compiler/rustc_mir_dataflow/src/rustc_peek.rs @@ -289,7 +289,7 @@ impl<'tcx> RustcPeekAt<'tcx> for MaybeMutBorrowedLocals<'_, 'tcx> { flow_state: &BitSet, call: PeekCall, ) { - info!(?place, "peek_at",); + info!(?place, "peek_at"); let local = if let Some(l) = place.as_local() { l } else { From 0e79545c306ca173fc406b61a81ea4e14400d293 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 7 Oct 2021 12:03:15 -0700 Subject: [PATCH 7/8] lol i forgot the syntax for my own crate's macros T_____T Signed-off-by: Eliza Weisman --- compiler/rustc_codegen_ssa/src/back/link.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index b5429064324..fd59bdca133 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -843,18 +843,18 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( let msg_bus = "clang: error: unable to execute command: Bus error: 10"; if out.contains(msg_segv) || out.contains(msg_bus) { warn!( + ?cmd, %out, "looks like the linker segfaulted when we tried to call it, \ automatically retrying again", - ?cmd, %out, ); continue; } if is_illegal_instruction(&output.status) { warn!( + ?cmd, %out, status = %output.status, "looks like the linker hit an illegal instruction when we \ tried to call it, automatically retrying again.", - ?cmd, %out, status = %output.status, ); continue; } From 84fc5db59b3a291090fe0cc9d1b91f463664d657 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Fri, 8 Oct 2021 10:56:08 -0700 Subject: [PATCH 8/8] bless warnings Signed-off-by: Eliza Weisman --- src/test/ui/consts/const_in_pattern/issue-73431.stderr | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/test/ui/consts/const_in_pattern/issue-73431.stderr diff --git a/src/test/ui/consts/const_in_pattern/issue-73431.stderr b/src/test/ui/consts/const_in_pattern/issue-73431.stderr new file mode 100644 index 00000000000..c82dea4aa50 --- /dev/null +++ b/src/test/ui/consts/const_in_pattern/issue-73431.stderr @@ -0,0 +1 @@ +WARN rustc_mir_build::thir::pattern::const_to_pat MIR const-checker found novel structural match violation. See #73448.