Skip to content

Commit 185ef7b

Browse files
committed
Port MissingFeatures and TargetFeatureDisableOrEnable
1 parent 33ef16f commit 185ef7b

File tree

4 files changed

+45
-14
lines changed

4 files changed

+45
-14
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_target::spec::{FramePointer, SanitizerSet, StackProbeType, StackProtec
1212
use smallvec::SmallVec;
1313

1414
use crate::attributes;
15-
use crate::errors::SanitizerMemtagRequiresMte;
15+
use crate::errors::{MissingFeatures, SanitizerMemtagRequiresMte, TargetFeatureDisableOrEnable};
1616
use crate::llvm::AttributePlace::Function;
1717
use crate::llvm::{self, AllocKindFlags, Attribute, AttributeKind, AttributePlace, MemoryEffects};
1818
use crate::llvm_util;
@@ -394,13 +394,11 @@ pub fn from_fn_attrs<'ll, 'tcx>(
394394
.get_attrs(instance.def_id(), sym::target_feature)
395395
.next()
396396
.map_or_else(|| cx.tcx.def_span(instance.def_id()), |a| a.span);
397-
let msg = format!(
398-
"the target features {} must all be either enabled or disabled together",
399-
f.join(", ")
400-
);
401-
let mut err = cx.tcx.sess.struct_span_err(span, &msg);
402-
err.help("add the missing features in a `target_feature` attribute");
403-
err.emit();
397+
cx.tcx
398+
.sess
399+
.create_err(TargetFeatureDisableOrEnable { features: f, span: Some(span) })
400+
.subdiagnostic(MissingFeatures)
401+
.emit();
404402
return;
405403
}
406404

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use std::borrow::Cow;
22

33
use rustc_errors::fluent;
44
use rustc_errors::DiagnosticBuilder;
5-
use rustc_macros::SessionDiagnostic;
5+
use rustc_errors::ErrorGuaranteed;
6+
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
67
use rustc_session::SessionDiagnostic;
78
use rustc_span::Span;
89

@@ -117,3 +118,29 @@ pub(crate) struct DlltoolFailImportLibrary<'a> {
117118
pub(crate) struct UnknownArchiveKind<'a> {
118119
pub kind: &'a str,
119120
}
121+
122+
pub(crate) struct TargetFeatureDisableOrEnable<'a> {
123+
pub features: &'a [&'a str],
124+
pub span: Option<Span>,
125+
}
126+
127+
#[derive(SessionSubdiagnostic)]
128+
#[help(codegen_llvm::missing_features)]
129+
pub(crate) struct MissingFeatures;
130+
131+
impl SessionDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {
132+
fn into_diagnostic(
133+
self,
134+
sess: &'_ rustc_session::parse::ParseSess,
135+
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
136+
let mut diag = if let Some(span) = self.span {
137+
let mut diag = sess.struct_err(fluent::codegen_llvm::target_feature_disable_or_enable);
138+
diag.set_span(span);
139+
diag
140+
} else {
141+
sess.struct_err(fluent::codegen_llvm::target_feature_disable_or_enable)
142+
};
143+
diag.set_arg("features", self.features.join(", "));
144+
diag
145+
}
146+
}

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::back::write::create_informational_target_machine;
2-
use crate::errors::UnknownCTargetFeature;
2+
use crate::errors::{TargetFeatureDisableOrEnable, UnknownCTargetFeature};
33
use crate::llvm;
44
use libc::c_int;
55
use rustc_codegen_ssa::target_features::{
@@ -480,10 +480,10 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
480480
features.extend(feats);
481481

482482
if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) {
483-
sess.err(&format!(
484-
"target features {} must all be enabled or disabled together",
485-
f.join(", ")
486-
));
483+
sess.emit_err(TargetFeatureDisableOrEnable {
484+
features: f,
485+
span: None
486+
});
487487
}
488488

489489
features

compiler/rustc_error_messages/locales/en-US/codegen_llvm.ftl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,9 @@ codegen_llvm_dlltool_fail_import_library =
5151
5252
codegen_llvm_unknown_archive_kind =
5353
Don't know how to build archive of type: {$kind}
54+
55+
codegen_llvm_target_feature_disable_or_enable =
56+
target features {$features} must all be enabled or disabled together
57+
58+
codegen_llvm_missing_features =
59+
add the missing features in a `target_feature` attribute

0 commit comments

Comments
 (0)