Skip to content

Commit

Permalink
Update diagnostic message
Browse files Browse the repository at this point in the history
  • Loading branch information
George-lewis committed Dec 27, 2023
1 parent c23b720 commit 08676d0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_session/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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?
this compiler was built on {$date}; consider upgrading if it is out of date
session_file_is_not_writeable = output file {$file} is not writeable -- check its permissions
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_session/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ 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");
pub fn new() -> Option<Self> {
let date = option_env!("CFG_VER_DATE")?;

Self { version, date }
Some(Self { date })
}
}

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 @@ -185,7 +185,9 @@ pub fn add_feature_diagnostics_for_issue(
err.subdiagnostic(FeatureDiagnosticHelp { feature });
}

err.subdiagnostic(SuggestUpgradeCompiler::new());
if let Some(suggestion) = SuggestUpgradeCompiler::new() {
err.subdiagnostic(suggestion);
}
}
}

Expand Down

0 comments on commit 08676d0

Please sign in to comment.