about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGeorge-lewis <george-lewis@user.noreply.github.com>2023-12-16 16:23:18 -0500
committerGeorge-lewis <george-lewis@user.noreply.github.com>2024-01-13 12:11:12 -0500
commitb55faad3149ecf196a498ea1c0cf6195f22c9d89 (patch)
treeded4b4007056d3608fb5bee1b7d872f9736dc97b
parent1d8d7b16cbcd048e98359cd0d42b03bc1710cca8 (diff)
downloadrust-b55faad3149ecf196a498ea1c0cf6195f22c9d89.tar.gz
rust-b55faad3149ecf196a498ea1c0cf6195f22c9d89.zip
Add suggestion to upgrade the compiler
-rw-r--r--compiler/rustc_session/messages.ftl3
-rw-r--r--compiler/rustc_session/src/errors.rs16
-rw-r--r--compiler/rustc_session/src/parse.rs3
3 files changed, 22 insertions, 0 deletions
diff --git a/compiler/rustc_session/messages.ftl b/compiler/rustc_session/messages.ftl
index f2e646c70f5..d9e1082eb41 100644
--- a/compiler/rustc_session/messages.ftl
+++ b/compiler/rustc_session/messages.ftl
@@ -24,6 +24,9 @@ session_feature_diagnostic_for_issue =
 session_feature_diagnostic_help =
     add `#![feature({$feature})]` to the crate attributes to enable
 
+session_feature_suggest_upgrade_compiler =
+    this compiler is version {$version} built on {$date}, consider upgrading?
+
 session_file_is_not_writeable = output file {$file} is not writeable -- check its permissions
 
 session_file_write_fail = failed to write `{$path}` due to error `{$err}`
diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs
index b672e760feb..24782b41cc8 100644
--- a/compiler/rustc_session/src/errors.rs
+++ b/compiler/rustc_session/src/errors.rs
@@ -31,6 +31,22 @@ pub struct FeatureDiagnosticForIssue {
 }
 
 #[derive(Subdiagnostic)]
+#[note(session_feature_suggest_upgrade_compiler)]
+pub struct SuggestUpgradeCompiler {
+    version: &'static str,
+    date: &'static str,
+}
+
+impl SuggestUpgradeCompiler {
+    pub fn new() -> Self {
+        let version = option_env!("CFG_VERSION").unwrap_or("unknown");
+        let date = option_env!("CFG_VER_DATE").unwrap_or("unknown");
+
+        Self { version, date }
+    }
+}
+
+#[derive(Subdiagnostic)]
 #[help(session_feature_diagnostic_help)]
 pub struct FeatureDiagnosticHelp {
     pub feature: Symbol,
diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs
index 598178c3c2a..39cc194fd6f 100644
--- a/compiler/rustc_session/src/parse.rs
+++ b/compiler/rustc_session/src/parse.rs
@@ -4,6 +4,7 @@
 use crate::config::{Cfg, CheckCfg};
 use crate::errors::{
     CliFeatureDiagnosticHelp, FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGateError,
+    SuggestUpgradeCompiler,
 };
 use crate::lint::{
     builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId,
@@ -179,6 +180,8 @@ pub fn add_feature_diagnostics_for_issue(
         } else {
             err.subdiagnostic(FeatureDiagnosticHelp { feature });
         }
+
+        err.subdiagnostic(SuggestUpgradeCompiler::new());
     }
 }