Skip to content

Commit b55faad

Browse files
author
George-lewis
committed
Add suggestion to upgrade the compiler
1 parent 1d8d7b1 commit b55faad

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

compiler/rustc_session/messages.ftl

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

+16
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ pub struct FeatureDiagnosticForIssue {
3030
pub n: NonZeroU32,
3131
}
3232

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

compiler/rustc_session/src/parse.rs

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use crate::config::{Cfg, CheckCfg};
55
use crate::errors::{
66
CliFeatureDiagnosticHelp, FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGateError,
7+
SuggestUpgradeCompiler,
78
};
89
use crate::lint::{
910
builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId,
@@ -179,6 +180,8 @@ pub fn add_feature_diagnostics_for_issue(
179180
} else {
180181
err.subdiagnostic(FeatureDiagnosticHelp { feature });
181182
}
183+
184+
err.subdiagnostic(SuggestUpgradeCompiler::new());
182185
}
183186
}
184187

0 commit comments

Comments
 (0)