Skip to content

Commit 333d3d6

Browse files
authored
Rollup merge of #93566 - Aaron1011:rustc-backtrace, r=davidtwco
Make rustc use `RUST_BACKTRACE=full` by default Compiler panics should be rare - when they do occur, we want the report filed by the user to contain as much information as possible. This is especially important when the panic is due to an incremental compilation bug, since we may not have enough information to reproduce it. This PR sets `RUST_BACKTRACE=full` inside `rustc` if the user has not explicitly set `RUST_BACKTRACE`. This is more verbose than `RUST_BACKTRACE=1`, but this may make it easier to debug incremental compilation issues. Users who find this too verbose can still manually set `RUST_BACKTRACE` before invoking the compiler. This only affects `rustc` (and any tool using `rustc_driver::install_ice_hook`). It does *not* affect any user crates or the standard library - backtraces will continue to be off by default in any application *compiled* by rustc.
2 parents 761705e + 891368f commit 333d3d6

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

compiler/rustc_driver/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,15 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12401240
///
12411241
/// A custom rustc driver can skip calling this to set up a custom ICE hook.
12421242
pub fn install_ice_hook() {
1243+
// If the user has not explicitly overriden "RUST_BACKTRACE", then produce
1244+
// full backtraces. When a compiler ICE happens, we want to gather
1245+
// as much information as possible to present in the issue opened
1246+
// by the user. Compiler developers and other rustc users can
1247+
// opt in to less-verbose backtraces by manually setting "RUST_BACKTRACE"
1248+
// (e.g. `RUST_BACKTRACE=1`)
1249+
if std::env::var("RUST_BACKTRACE").is_err() {
1250+
std::env::set_var("RUST_BACKTRACE", "full");
1251+
}
12431252
SyncLazy::force(&DEFAULT_HOOK);
12441253
}
12451254

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// unset-rustc-env:RUST_BACKTRACE
2+
// compile-flags:-Z treat-err-as-bug=1
3+
// error-pattern:stack backtrace:
4+
// failure-status:101
5+
// normalize-stderr-test "note: .*" -> ""
6+
// normalize-stderr-test "thread 'rustc' .*" -> ""
7+
// normalize-stderr-test " .*\n" -> ""
8+
9+
fn main() { missing_ident; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0425]: cannot find value `missing_ident` in this scope
2+
LL | fn main() { missing_ident; }
3+
4+
5+
stack backtrace:
6+
7+
error: internal compiler error: unexpected panic
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
query stack during panic:
18+
end of query stack

0 commit comments

Comments
 (0)