Skip to content

Commit ad4897a

Browse files
authored
Unrolled build for rust-lang#121658
Rollup merge of rust-lang#121658 - jieyouxu:ice-outdated-nightly, r=oli-obk Hint user to update nightly on ICEs produced from outdated nightly This is a conservative best-effort approach to detect a potentially outdated nightly; it will fallback to the regular ICE-reporting if any of the following cases are true: - Channel is not nightly - Version information is not available - Version date is not parseable as a YYYY-MM-DD or is missing - System time is at least 36 hours ahead of the user's nightly release datetime. - Any internal features are used. Note that I'm not sure how to make a test for this: I tested this manually by `CFG_VER_DATE="2020-02-02" ./x build library --stage 1`, and also changing the channel detection in `rustc_driver_impl` from `Some("nightly")` to `Some("nightly" | "dev")`, and then running `rustc +stage1 test.rs -Ztreat-err-as-bug=1` with a non-existent `test.rs`. <img width="1145" alt="Screenshot 2024-02-27 at 01 12 28" src="https://github.com/rust-lang/rust/assets/39484203/eff6af2e-4b19-4a70-af57-cd739ecf0e84"> Closes rust-lang#118832.
2 parents b6d2d84 + 9c963fc commit ad4897a

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-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

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
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_outdated =
5+
it seems that this compiler `{$version}` is outdated, a newer nightly should have been released in the mean time
6+
.update = please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists
7+
.url = if the problem still persists, we would appreciate a bug report: {$bug_report_url}
48
driver_impl_ice_exclude_cargo_defaults = some of the compiler flags provided by cargo are hidden
59
610
driver_impl_ice_flags = compiler flags: {$flags}

compiler/rustc_driver_impl/src/lib.rs

+31-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use std::str;
5858
use std::sync::atomic::{AtomicBool, Ordering};
5959
use std::sync::{Arc, OnceLock};
6060
use std::time::{Instant, SystemTime};
61-
use time::OffsetDateTime;
61+
use time::{Date, OffsetDateTime, Time};
6262

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

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

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

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

compiler/rustc_driver_impl/src/session_diagnostics.rs

+11
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ 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+
4960
#[derive(Diagnostic)]
5061
#[diag(driver_impl_ice_version)]
5162
pub(crate) struct IceVersion<'a> {

0 commit comments

Comments
 (0)