1
Fork 0

Port unknown feature diagnostic to the new framework

This commit is contained in:
SLASHLogin 2022-08-25 15:34:30 +02:00
parent 0aaad9e757
commit 575f6098da
5 changed files with 52 additions and 17 deletions

View file

@ -0,0 +1,33 @@
use rustc_errors::DiagnosticBuilder;
use rustc_session::SessionDiagnostic;
use rustc_errors::fluent;
pub(crate) enum UnknownCTargetFeature {
UnknownFeaturePrefix { feature: String },
UnknownFeature { feature: String, rust_feature: Option<String> },
}
impl SessionDiagnostic<'_, ()> for UnknownCTargetFeature {
fn into_diagnostic(self, sess: &'_ rustc_session::parse::ParseSess) -> DiagnosticBuilder<'_, ()> {
match self {
UnknownCTargetFeature::UnknownFeaturePrefix { feature } => {
let mut diag = sess.struct_warn(fluent::codegen_llvm::unknown_ctarget_feature);
diag.set_arg("feature", feature);
diag.note(fluent::codegen_llvm::unknown_feature_prefix);
diag
}
UnknownCTargetFeature::UnknownFeature { feature, rust_feature } => {
let mut diag = sess.struct_warn(fluent::codegen_llvm::unknown_ctarget_feature);
diag.set_arg("feature", feature);
diag.note(fluent::codegen_llvm::unknown_feature);
if let Some(rust_feature) = rust_feature {
diag.help(fluent::codegen_llvm::rust_feature);
diag.set_arg("rust_feature", rust_feature);
} else {
diag.note(fluent::codegen_llvm::unknown_feature_fill_request);
}
diag
}
}
}
}

View file

@ -62,6 +62,7 @@ mod context;
mod coverageinfo;
mod debuginfo;
mod declare;
mod errors;
mod intrinsic;
// The following is a work around that replaces `pub mod llvm;` and that fixes issue 53912.

View file

@ -1,5 +1,6 @@
use crate::back::write::create_informational_target_machine;
use crate::llvm;
use crate::errors::UnknownCTargetFeature;
use libc::c_int;
use rustc_codegen_ssa::target_features::{
supported_target_features, tied_target_features, RUSTC_SPECIFIC_FEATURES,
@ -434,12 +435,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
Some(c @ '+' | c @ '-') => c,
Some(_) => {
if diagnostics {
let mut diag = sess.struct_warn(&format!(
"unknown feature specified for `-Ctarget-feature`: `{}`",
s
));
diag.note("features must begin with a `+` to enable or `-` to disable it");
diag.emit();
sess.emit_warning(UnknownCTargetFeature::UnknownFeaturePrefix { feature: s.to_string() });
}
return None;
}
@ -456,17 +452,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
None
}
});
let mut diag = sess.struct_warn(&format!(
"unknown feature specified for `-Ctarget-feature`: `{}`",
feature
));
diag.note("it is still passed through to the codegen backend");
if let Some(rust_feature) = rust_feature {
diag.help(&format!("you might have meant: `{}`", rust_feature));
} else {
diag.note("consider filing a feature request");
}
diag.emit();
sess.emit_warning(UnknownCTargetFeature::UnknownFeature { feature: feature.to_string(), rust_feature: rust_feature.map(|f| f.to_string()) });
}
if diagnostics {