Skip to content

Commit

Permalink
Add suggestion to upgrade the compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
George-lewis committed Dec 27, 2023
1 parent ca9ff83 commit 75a507c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions compiler/rustc_session/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
16 changes: 16 additions & 0 deletions compiler/rustc_session/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ pub struct FeatureDiagnosticForIssue {
pub n: NonZeroU32,
}

#[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 {
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_session/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::config::{Cfg, CheckCfg};
use crate::errors::{
CliFeatureDiagnosticHelp, FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGateError,
CliFeatureDiagnosticHelp, FeatureDiagnosticForIssue, FeatureDiagnosticHelp, FeatureGateError, SuggestUpgradeCompiler,
};
use crate::lint::{
builtin::UNSTABLE_SYNTAX_PRE_EXPANSION, BufferedEarlyLint, BuiltinLintDiagnostics, Lint, LintId,
Expand Down Expand Up @@ -183,6 +183,8 @@ pub fn add_feature_diagnostics_for_issue(
} else {
err.subdiagnostic(FeatureDiagnosticHelp { feature });
}

err.subdiagnostic(SuggestUpgradeCompiler::new());
}
}

Expand Down

0 comments on commit 75a507c

Please sign in to comment.