about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorSLASHLogin <loginmlgxd@gmail.com>2022-08-25 15:34:30 +0200
committerSLASHLogin <loginmlgxd@gmail.com>2022-11-09 14:56:20 +0100
commit575f6098da83cef33676ef67e39b73b2b910a042 (patch)
treed6c39e411c4e351d4f0ba47faf90e2d613bccc38 /compiler/rustc_codegen_llvm/src
parent0aaad9e757207657064d70bf9e6c1e6eb327bf15 (diff)
downloadrust-575f6098da83cef33676ef67e39b73b2b910a042.tar.gz
rust-575f6098da83cef33676ef67e39b73b2b910a042.zip
Port unknown feature diagnostic to the new framework
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
-rw-r--r--compiler/rustc_codegen_llvm/src/errors.rs33
-rw-r--r--compiler/rustc_codegen_llvm/src/lib.rs1
-rw-r--r--compiler/rustc_codegen_llvm/src/llvm_util.rs20
3 files changed, 37 insertions, 17 deletions
diff --git a/compiler/rustc_codegen_llvm/src/errors.rs b/compiler/rustc_codegen_llvm/src/errors.rs
new file mode 100644
index 00000000000..b1f85e656b8
--- /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<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
+            }
+        }
+    }
+}
\ 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 d51aced85df..af632b2ff54 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 2fd58567c48..f8f174692c0 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<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 {