Skip to content

Commit 575f609

Browse files
committed
Port unknown feature diagnostic to the new framework
1 parent 0aaad9e commit 575f609

File tree

5 files changed

+52
-17
lines changed

5 files changed

+52
-17
lines changed
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use rustc_errors::DiagnosticBuilder;
2+
use rustc_session::SessionDiagnostic;
3+
use rustc_errors::fluent;
4+
5+
pub(crate) enum UnknownCTargetFeature {
6+
UnknownFeaturePrefix { feature: String },
7+
UnknownFeature { feature: String, rust_feature: Option<String> },
8+
}
9+
10+
impl SessionDiagnostic<'_, ()> for UnknownCTargetFeature {
11+
fn into_diagnostic(self, sess: &'_ rustc_session::parse::ParseSess) -> DiagnosticBuilder<'_, ()> {
12+
match self {
13+
UnknownCTargetFeature::UnknownFeaturePrefix { feature } => {
14+
let mut diag = sess.struct_warn(fluent::codegen_llvm::unknown_ctarget_feature);
15+
diag.set_arg("feature", feature);
16+
diag.note(fluent::codegen_llvm::unknown_feature_prefix);
17+
diag
18+
}
19+
UnknownCTargetFeature::UnknownFeature { feature, rust_feature } => {
20+
let mut diag = sess.struct_warn(fluent::codegen_llvm::unknown_ctarget_feature);
21+
diag.set_arg("feature", feature);
22+
diag.note(fluent::codegen_llvm::unknown_feature);
23+
if let Some(rust_feature) = rust_feature {
24+
diag.help(fluent::codegen_llvm::rust_feature);
25+
diag.set_arg("rust_feature", rust_feature);
26+
} else {
27+
diag.note(fluent::codegen_llvm::unknown_feature_fill_request);
28+
}
29+
diag
30+
}
31+
}
32+
}
33+
}

compiler/rustc_codegen_llvm/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ mod context;
6262
mod coverageinfo;
6363
mod debuginfo;
6464
mod declare;
65+
mod errors;
6566
mod intrinsic;
6667

6768
// The following is a work around that replaces `pub mod llvm;` and that fixes issue 53912.

compiler/rustc_codegen_llvm/src/llvm_util.rs

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::back::write::create_informational_target_machine;
22
use crate::llvm;
3+
use crate::errors::UnknownCTargetFeature;
34
use libc::c_int;
45
use rustc_codegen_ssa::target_features::{
56
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
434435
Some(c @ '+' | c @ '-') => c,
435436
Some(_) => {
436437
if diagnostics {
437-
let mut diag = sess.struct_warn(&format!(
438-
"unknown feature specified for `-Ctarget-feature`: `{}`",
439-
s
440-
));
441-
diag.note("features must begin with a `+` to enable or `-` to disable it");
442-
diag.emit();
438+
sess.emit_warning(UnknownCTargetFeature::UnknownFeaturePrefix { feature: s.to_string() });
443439
}
444440
return None;
445441
}
@@ -456,17 +452,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
456452
None
457453
}
458454
});
459-
let mut diag = sess.struct_warn(&format!(
460-
"unknown feature specified for `-Ctarget-feature`: `{}`",
461-
feature
462-
));
463-
diag.note("it is still passed through to the codegen backend");
464-
if let Some(rust_feature) = rust_feature {
465-
diag.help(&format!("you might have meant: `{}`", rust_feature));
466-
} else {
467-
diag.note("consider filing a feature request");
468-
}
469-
diag.emit();
455+
sess.emit_warning(UnknownCTargetFeature::UnknownFeature { feature: feature.to_string(), rust_feature: rust_feature.map(|f| f.to_string()) });
470456
}
471457

472458
if diagnostics {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
codegen_llvm_unknown_ctarget_feature =
2+
unknown feature specified for `-Ctarget-feature`: `{$feature}`
3+
4+
codegen_llvm_unknown_feature_prefix =
5+
features must begin with a `+` to enable or `-` to disable it
6+
7+
codegen_llvm_unknown_feature =
8+
it is still passed through to the codegen backend
9+
10+
codegen_llvm_rust_feature =
11+
you might have meant: `{$rust_feature}`
12+
13+
codegen_llvm_unknown_feature_fill_request =
14+
consider filing a feature request

compiler/rustc_error_messages/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ fluent_messages! {
4242
borrowck => "../locales/en-US/borrowck.ftl",
4343
builtin_macros => "../locales/en-US/builtin_macros.ftl",
4444
codegen_gcc => "../locales/en-US/codegen_gcc.ftl",
45+
codegen_llvm => "../locales/en-US/codegen_llvm.ftl",
4546
codegen_ssa => "../locales/en-US/codegen_ssa.ftl",
4647
compiletest => "../locales/en-US/compiletest.ftl",
4748
const_eval => "../locales/en-US/const_eval.ftl",

0 commit comments

Comments
 (0)