Skip to content

Commit a5245ef

Browse files
committed
Hint user to update nightly on ICEs produced from outdated nightly
1 parent 829308e commit a5245ef

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed

compiler/rustc_driver_impl/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ rustc_trait_selection = { path = "../rustc_trait_selection" }
5050
rustc_ty_utils = { path = "../rustc_ty_utils" }
5151
serde_json = "1.0.59"
5252
shlex = "1.0"
53-
time = { version = "0.3", default-features = false, features = ["alloc", "formatting"] }
53+
time = { version = "0.3", default-features = false, features = ["alloc", "formatting", "parsing", "macros"] }
5454
tracing = { version = "0.1.35" }
5555
# tidy-alphabetical-end
5656

compiler/rustc_driver_impl/messages.ftl

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
driver_impl_ice = the compiler unexpectedly panicked. this is a bug.
22
driver_impl_ice_bug_report = we would appreciate a bug report: {$bug_report_url}
33
driver_impl_ice_bug_report_internal_feature = using internal features is not supported and expected to cause internal compiler errors when used incorrectly
4+
driver_impl_ice_bug_report_internal_feature_outdated =
5+
using internal features is not supported and expected to cause internal compiler errors when used incorrectly
6+
.outdated = it seems this '{$version}' is outdated, a newer nightly should have been released in the mean time
7+
.update = please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists
8+
driver_impl_ice_bug_report_outdated =
9+
it seems this '{$version}' is outdated, a newer nightly should have been released in the mean time
10+
.update = please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists
11+
.url = we would appreciate a bug report: {$bug_report_url}
412
driver_impl_ice_exclude_cargo_defaults = some of the compiler flags provided by cargo are hidden
513
614
driver_impl_ice_flags = compiler flags: {$flags}

compiler/rustc_driver_impl/src/lib.rs

+38-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use std::str;
5757
use std::sync::atomic::{AtomicBool, Ordering};
5858
use std::sync::{Arc, OnceLock};
5959
use std::time::{Instant, SystemTime};
60-
use time::OffsetDateTime;
60+
use time::{Date, OffsetDateTime, Time};
6161

6262
#[allow(unused_macros)]
6363
macro do_not_use_print($($t:tt)*) {
@@ -1370,6 +1370,9 @@ pub fn install_ice_hook(
13701370
using_internal_features
13711371
}
13721372

1373+
const DATE_FORMAT: &[time::format_description::FormatItem<'static>] =
1374+
&time::macros::format_description!("[year]-[month]-[day]");
1375+
13731376
/// Prints the ICE message, including query stack, but without backtrace.
13741377
///
13751378
/// The message will point the user at `bug_report_url` to report the ICE.
@@ -1398,10 +1401,41 @@ fn report_ice(
13981401
dcx.emit_err(session_diagnostics::Ice);
13991402
}
14001403

1401-
if using_internal_features.load(std::sync::atomic::Ordering::Relaxed) {
1402-
dcx.emit_note(session_diagnostics::IceBugReportInternalFeature);
1404+
use time::ext::NumericalDuration;
1405+
1406+
// Try to hint user to update nightly if applicable when reporting an ICE.
1407+
// Attempt to calculate when current version was released, and add 12 hours
1408+
// as buffer. If the current version's release timestamp is older than
1409+
// the system's current time + 24 hours + 12 hours buffer if we're on
1410+
// nightly.
1411+
if let Some("nightly") = option_env!("CFG_RELEASE_CHANNEL")
1412+
&& let Some(version) = option_env!("CFG_VERSION")
1413+
&& let Some(ver_date_str) = option_env!("CFG_VER_DATE")
1414+
&& let Ok(ver_date) = Date::parse(&ver_date_str, DATE_FORMAT)
1415+
&& let ver_datetime = OffsetDateTime::new_utc(ver_date, Time::MIDNIGHT)
1416+
&& let system_datetime = OffsetDateTime::from(SystemTime::now())
1417+
&& system_datetime.checked_sub(36.hours()).is_some_and(|d| d > ver_datetime)
1418+
{
1419+
if using_internal_features.load(std::sync::atomic::Ordering::Relaxed) {
1420+
dcx.emit_note(session_diagnostics::IceBugReportInternalFeatureOutdated {
1421+
version,
1422+
note_update: (),
1423+
note_outdated: (),
1424+
});
1425+
} else {
1426+
dcx.emit_note(session_diagnostics::IceBugReportOutdated {
1427+
version,
1428+
bug_report_url,
1429+
note_update: (),
1430+
note_url: (),
1431+
});
1432+
}
14031433
} else {
1404-
dcx.emit_note(session_diagnostics::IceBugReport { bug_report_url });
1434+
if using_internal_features.load(std::sync::atomic::Ordering::Relaxed) {
1435+
dcx.emit_note(session_diagnostics::IceBugReportInternalFeature);
1436+
} else {
1437+
dcx.emit_note(session_diagnostics::IceBugReport { bug_report_url });
1438+
}
14051439
}
14061440

14071441
let version = util::version_str!().unwrap_or("unknown_version");

compiler/rustc_driver_impl/src/session_diagnostics.rs

+21
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@ pub(crate) struct IceBugReport<'a> {
4646
#[diag(driver_impl_ice_bug_report_internal_feature)]
4747
pub(crate) struct IceBugReportInternalFeature;
4848

49+
#[derive(Diagnostic)]
50+
#[diag(driver_impl_ice_bug_report_outdated)]
51+
pub(crate) struct IceBugReportOutdated<'a> {
52+
pub version: &'a str,
53+
pub bug_report_url: &'a str,
54+
#[note(driver_impl_update)]
55+
pub note_update: (),
56+
#[note(driver_impl_url)]
57+
pub note_url: (),
58+
}
59+
60+
#[derive(Diagnostic)]
61+
#[diag(driver_impl_ice_bug_report_internal_feature_outdated)]
62+
pub(crate) struct IceBugReportInternalFeatureOutdated<'a> {
63+
pub version: &'a str,
64+
#[note(driver_impl_outdated)]
65+
pub note_outdated: (),
66+
#[note(driver_impl_update)]
67+
pub note_update: (),
68+
}
69+
4970
#[derive(Diagnostic)]
5071
#[diag(driver_impl_ice_version)]
5172
pub(crate) struct IceVersion<'a> {

0 commit comments

Comments
 (0)