From 8c5bdb973a3a154d7ed5d5a8cc7ab39ab7a61376 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Tue, 21 Sep 2021 01:53:04 +0200 Subject: [PATCH] Fix ICE with `--cap-lints=allow` and `-Zfuel=...=0` --- compiler/rustc_session/src/session.rs | 7 ++++++- src/test/ui/lint/issue-79546-fuel-ice.rs | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/lint/issue-79546-fuel-ice.rs diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index d6f4a3ae4f1..27215556045 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -902,7 +902,12 @@ impl Session { let mut fuel = self.optimization_fuel.lock(); ret = fuel.remaining != 0; if fuel.remaining == 0 && !fuel.out_of_fuel { - self.warn(&format!("optimization-fuel-exhausted: {}", msg())); + if self.diagnostic().can_emit_warnings() { + // We only call `msg` in case we can actually emit warnings. + // Otherwise, this could cause a `delay_good_path_bug` to + // trigger (issue #79546). + self.warn(&format!("optimization-fuel-exhausted: {}", msg())); + } fuel.out_of_fuel = true; } else if fuel.remaining > 0 { fuel.remaining -= 1; diff --git a/src/test/ui/lint/issue-79546-fuel-ice.rs b/src/test/ui/lint/issue-79546-fuel-ice.rs new file mode 100644 index 00000000000..0e9f54088b8 --- /dev/null +++ b/src/test/ui/lint/issue-79546-fuel-ice.rs @@ -0,0 +1,8 @@ +// Regression test for the ICE described in #79546. + +// compile-flags: --cap-lints=allow -Zfuel=issue79546=0 +// check-pass +#![crate_name="issue79546"] + +struct S; +fn main() {}