From 575f6098da83cef33676ef67e39b73b2b910a042 Mon Sep 17 00:00:00 2001 From: SLASHLogin Date: Thu, 25 Aug 2022 15:34:30 +0200 Subject: [PATCH] Port unknown feature diagnostic to the new framework --- compiler/rustc_codegen_llvm/src/errors.rs | 33 +++++++++++++++++++ compiler/rustc_codegen_llvm/src/lib.rs | 1 + compiler/rustc_codegen_llvm/src/llvm_util.rs | 20 ++--------- .../locales/en-US/codegen_llvm.ftl | 14 ++++++++ compiler/rustc_error_messages/src/lib.rs | 1 + 5 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 compiler/rustc_codegen_llvm/src/errors.rs create mode 100644 compiler/rustc_error_messages/locales/en-US/codegen_llvm.ftl diff --git a/compiler/rustc_codegen_llvm/src/errors.rs b/compiler/rustc_codegen_llvm/src/errors.rs new file mode 100644 index 000000000000..b1f85e656b82 --- /dev/null +++ b/compiler/rustc_codegen_llvm/src/errors.rs @@ -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 }, +} + +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 + } + } + } +} \ No newline at end of file diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index d51aced85df4..af632b2ff54b 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -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. diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index 2fd58567c487..f8f174692c06 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -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 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 "../locales/en-US/borrowck.ftl", builtin_macros => "../locales/en-US/builtin_macros.ftl", codegen_gcc => "../locales/en-US/codegen_gcc.ftl", + codegen_llvm => "../locales/en-US/codegen_llvm.ftl", codegen_ssa => "../locales/en-US/codegen_ssa.ftl", compiletest => "../locales/en-US/compiletest.ftl", const_eval => "../locales/en-US/const_eval.ftl",