Skip to content

Commit 58ff183

Browse files
author
George-lewis
committed
Add suggestion to upgrade the compiler
1 parent 3ad8e2d commit 58ff183

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
@@ -32,6 +32,22 @@ pub struct FeatureDiagnosticForIssue {
3232
pub n: NonZeroU32,
3333
}
3434

35+
#[derive(Subdiagnostic)]
36+
#[note(session_feature_suggest_upgrade_compiler)]
37+
pub struct SuggestUpgradeCompiler {
38+
version: &'static str,
39+
date: &'static str
40+
}
41+
42+
impl SuggestUpgradeCompiler {
43+
pub fn new() -> Self {
44+
let version = option_env!("CFG_VERSION").unwrap_or("unknown");
45+
let date = option_env!("CFG_VER_DATE").unwrap_or("unknown");
46+
47+
Self { version, date }
48+
}
49+
}
50+
3551
#[derive(Subdiagnostic)]
3652
#[help(session_feature_diagnostic_help)]
3753
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,
@@ -184,6 +184,8 @@ pub fn add_feature_diagnostics_for_issue(
184184
} else {
185185
err.subdiagnostic(FeatureDiagnosticHelp { feature });
186186
}
187+
188+
err.subdiagnostic(SuggestUpgradeCompiler::new());
187189
}
188190
}
189191

0 commit comments

Comments
 (0)