Skip to content

Commit 75a507c

Browse files
author
George-lewis
committed
Add suggestion to upgrade the compiler
1 parent ca9ff83 commit 75a507c

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

compiler/rustc_session/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ session_feature_diagnostic_for_issue =
2424
session_feature_diagnostic_help =
2525
add `#![feature({$feature})]` to the crate attributes to enable
2626
27+
session_feature_suggest_upgrade_compiler =
28+
this compiler is version {$version} built on {$date}, consider upgrading?
29+
2730
session_file_is_not_writeable = output file {$file} is not writeable -- check its permissions
2831
2932
session_file_write_fail = failed to write `{$path}` due to error `{$err}`

compiler/rustc_session/src/errors.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ pub struct FeatureDiagnosticForIssue {
3131
pub n: NonZeroU32,
3232
}
3333

34+
#[derive(Subdiagnostic)]
35+
#[note(session_feature_suggest_upgrade_compiler)]
36+
pub struct SuggestUpgradeCompiler {
37+
version: &'static str,
38+
date: &'static str
39+
}
40+
41+
impl SuggestUpgradeCompiler {
42+
pub fn new() -> Self {
43+
let version = option_env!("CFG_VERSION").unwrap_or("unknown");
44+
let date = option_env!("CFG_VER_DATE").unwrap_or("unknown");
45+
46+
Self { version, date }
47+
}
48+
}
49+
3450
#[derive(Subdiagnostic)]
3551
#[help(session_feature_diagnostic_help)]
3652
pub struct FeatureDiagnosticHelp {

compiler/rustc_session/src/parse.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use crate::config::{Cfg, CheckCfg};
55
use crate::errors::{
6-
CliFeatureDiagnosticHelp, FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGateError,
6+
CliFeatureDiagnosticHelp, FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGateError, SuggestUpgradeCompiler,
77
};
88
use crate::lint::{
99
builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId,
@@ -183,6 +183,8 @@ pub fn add_feature_diagnostics_for_issue(
183183
} else {
184184
err.subdiagnostic(FeatureDiagnosticHelp { feature });
185185
}
186+
187+
err.subdiagnostic(SuggestUpgradeCompiler::new());
186188
}
187189
}
188190

0 commit comments

Comments
 (0)