Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ffad9aa

Browse files
committedNov 4, 2024·
mark some target features as 'forbidden' so they cannot be (un)set
For now, this is just a warning, but should become a hard error in the future
1 parent 2dece5b commit ffad9aa

23 files changed

+371
-157
lines changed
 

‎compiler/rustc_codegen_gcc/messages.ftl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ codegen_gcc_invalid_minimum_alignment =
88
codegen_gcc_lto_not_supported =
99
LTO is not supported. You may get a linker error.
1010
11+
codegen_gcc_forbidden_ctarget_feature =
12+
target feature `{$feature}` cannot be toggled with `-Ctarget-feature`
13+
1114
codegen_gcc_unwinding_inline_asm =
1215
GCC backend does not support unwinding from inline asm
1316
@@ -24,11 +27,15 @@ codegen_gcc_lto_dylib = lto cannot be used for `dylib` crate type without `-Zdyl
2427
codegen_gcc_lto_bitcode_from_rlib = failed to get bitcode from object file for LTO ({$gcc_err})
2528
2629
codegen_gcc_unknown_ctarget_feature =
27-
unknown feature specified for `-Ctarget-feature`: `{$feature}`
28-
.note = it is still passed through to the codegen backend
30+
unknown and unstable feature specified for `-Ctarget-feature`: `{$feature}`
31+
.note = it is still passed through to the codegen backend, but use of this feature might be unsound and the behavior of this feature can change in the future
2932
.possible_feature = you might have meant: `{$rust_feature}`
3033
.consider_filing_feature_request = consider filing a feature request
3134
35+
codegen_gcc_unstable_ctarget_feature =
36+
unstable feature specified for `-Ctarget-feature`: `{$feature}`
37+
.note = this feature is not stably supported; its behavior can change in the future
38+
3239
codegen_gcc_missing_features =
3340
add the missing features in a `target_feature` attribute
3441

‎compiler/rustc_codegen_gcc/src/errors.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ pub(crate) struct UnknownCTargetFeature<'a> {
1717
pub rust_feature: PossibleFeature<'a>,
1818
}
1919

20+
#[derive(Diagnostic)]
21+
#[diag(codegen_gcc_unstable_ctarget_feature)]
22+
#[note]
23+
pub(crate) struct UnstableCTargetFeature<'a> {
24+
pub feature: &'a str,
25+
}
26+
27+
#[derive(Diagnostic)]
28+
#[diag(codegen_gcc_forbidden_ctarget_feature)]
29+
pub(crate) struct ForbiddenCTargetFeature<'a> {
30+
pub feature: &'a str,
31+
}
32+
2033
#[derive(Subdiagnostic)]
2134
pub(crate) enum PossibleFeature<'a> {
2235
#[help(codegen_gcc_possible_feature)]

‎compiler/rustc_codegen_gcc/src/gcc_util.rs

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ use rustc_codegen_ssa::errors::TargetFeatureDisableOrEnable;
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_middle::bug;
77
use rustc_session::Session;
8-
use rustc_target::target_features::RUSTC_SPECIFIC_FEATURES;
8+
use rustc_target::target_features::{RUSTC_SPECIFIC_FEATURES, Stability};
99
use smallvec::{SmallVec, smallvec};
1010

11-
use crate::errors::{PossibleFeature, UnknownCTargetFeature, UnknownCTargetFeaturePrefix};
11+
use crate::errors::{
12+
ForbiddenCTargetFeature, PossibleFeature, UnknownCTargetFeature, UnknownCTargetFeaturePrefix,
13+
UnstableCTargetFeature,
14+
};
1215

1316
/// The list of GCC features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
1417
/// `--target` and similar).
@@ -43,7 +46,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
4346
);
4447

4548
// -Ctarget-features
46-
let supported_features = sess.target.supported_target_features();
49+
let known_features = sess.target.rust_target_features();
4750
let mut featsmap = FxHashMap::default();
4851
let feats = sess
4952
.opts
@@ -62,37 +65,49 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
6265
}
6366
};
6467

68+
// Get the backend feature name, if any.
69+
// This excludes rustc-specific features, that do not get passed down to GCC.
6570
let feature = backend_feature_name(s)?;
6671
// Warn against use of GCC specific feature names on the CLI.
67-
if diagnostics && !supported_features.iter().any(|&(v, _, _)| v == feature) {
68-
let rust_feature = supported_features.iter().find_map(|&(rust_feature, _, _)| {
69-
let gcc_features = to_gcc_features(sess, rust_feature);
70-
if gcc_features.contains(&feature) && !gcc_features.contains(&rust_feature) {
71-
Some(rust_feature)
72-
} else {
73-
None
72+
if diagnostics {
73+
let feature_state = known_features.iter().find(|&&(v, _, _)| v == feature);
74+
match feature_state {
75+
None => {
76+
let rust_feature =
77+
known_features.iter().find_map(|&(rust_feature, _, _)| {
78+
let gcc_features = to_gcc_features(sess, rust_feature);
79+
if gcc_features.contains(&feature)
80+
&& !gcc_features.contains(&rust_feature)
81+
{
82+
Some(rust_feature)
83+
} else {
84+
None
85+
}
86+
});
87+
let unknown_feature = if let Some(rust_feature) = rust_feature {
88+
UnknownCTargetFeature {
89+
feature,
90+
rust_feature: PossibleFeature::Some { rust_feature },
91+
}
92+
} else {
93+
UnknownCTargetFeature { feature, rust_feature: PossibleFeature::None }
94+
};
95+
sess.dcx().emit_warn(unknown_feature);
7496
}
75-
});
76-
let unknown_feature = if let Some(rust_feature) = rust_feature {
77-
UnknownCTargetFeature {
78-
feature,
79-
rust_feature: PossibleFeature::Some { rust_feature },
97+
Some((_, Stability::Stable, _)) => {}
98+
Some((_, Stability::Unstable(_), _)) => {
99+
// An unstable feature. Warn about using it.
100+
sess.dcx().emit_warn(UnstableCTargetFeature { feature });
80101
}
81-
} else {
82-
UnknownCTargetFeature { feature, rust_feature: PossibleFeature::None }
83-
};
84-
sess.dcx().emit_warn(unknown_feature);
85-
}
102+
Some((_, Stability::Forbidden { .. }, _)) => {
103+
sess.dcx().emit_err(ForbiddenCTargetFeature { feature });
104+
}
105+
}
86106

87-
if diagnostics {
88107
// FIXME(nagisa): figure out how to not allocate a full hashset here.
89108
featsmap.insert(feature, enable_disable == '+');
90109
}
91110

92-
// rustc-specific features do not get passed down to GCC…
93-
if RUSTC_SPECIFIC_FEATURES.contains(&feature) {
94-
return None;
95-
}
96111
// ... otherwise though we run through `to_gcc_features` when
97112
// passing requests down to GCC. This means that all in-language
98113
// features also work on the command line instead of having two

‎compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,9 @@ pub fn target_features(
491491
) -> Vec<Symbol> {
492492
// TODO(antoyo): use global_gcc_features.
493493
sess.target
494-
.supported_target_features()
494+
.rust_target_features()
495495
.iter()
496+
.filter(|(_, gate, _)| gate.is_supported())
496497
.filter_map(|&(feature, gate, _)| {
497498
if sess.is_nightly_build() || allow_unstable || gate.is_stable() {
498499
Some(feature)

‎compiler/rustc_codegen_llvm/messages.ftl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ codegen_llvm_dynamic_linking_with_lto =
77
88
codegen_llvm_fixed_x18_invalid_arch = the `-Zfixed-x18` flag is not supported on the `{$arch}` architecture
99
10+
codegen_llvm_forbidden_ctarget_feature =
11+
target feature `{$feature}` cannot be toggled with `-Ctarget-feature`: {$reason}
12+
.note = this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
13+
codegen_llvm_forbidden_ctarget_feature_issue = for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
14+
1015
codegen_llvm_from_llvm_diag = {$message}
1116
1217
codegen_llvm_from_llvm_optimization_diag = {$filename}:{$line}:{$column} {$pass_name} ({$kind}): {$message}

‎compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ pub(crate) struct UnstableCTargetFeature<'a> {
3131
pub feature: &'a str,
3232
}
3333

34+
#[derive(Diagnostic)]
35+
#[diag(codegen_llvm_forbidden_ctarget_feature)]
36+
#[note]
37+
#[note(codegen_llvm_forbidden_ctarget_feature_issue)]
38+
pub(crate) struct ForbiddenCTargetFeature<'a> {
39+
pub feature: &'a str,
40+
pub reason: &'a str,
41+
}
42+
3443
#[derive(Subdiagnostic)]
3544
pub(crate) enum PossibleFeature<'a> {
3645
#[help(codegen_llvm_possible_feature)]

‎compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 71 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ use rustc_session::Session;
1616
use rustc_session::config::{PrintKind, PrintRequest};
1717
use rustc_span::symbol::Symbol;
1818
use rustc_target::spec::{MergeFunctions, PanicStrategy, SmallDataThresholdSupport};
19-
use rustc_target::target_features::{RUSTC_SPECIAL_FEATURES, RUSTC_SPECIFIC_FEATURES};
19+
use rustc_target::target_features::{RUSTC_SPECIAL_FEATURES, RUSTC_SPECIFIC_FEATURES, Stability};
2020

2121
use crate::back::write::create_informational_target_machine;
2222
use crate::errors::{
23-
FixedX18InvalidArch, InvalidTargetFeaturePrefix, PossibleFeature, UnknownCTargetFeature,
24-
UnknownCTargetFeaturePrefix, UnstableCTargetFeature,
23+
FixedX18InvalidArch, ForbiddenCTargetFeature, InvalidTargetFeaturePrefix, PossibleFeature,
24+
UnknownCTargetFeature, UnknownCTargetFeaturePrefix, UnstableCTargetFeature,
2525
};
2626
use crate::llvm;
2727

@@ -280,19 +280,29 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
280280
}
281281
}
282282

283-
/// Used to generate cfg variables and apply features
284-
/// Must express features in the way Rust understands them
283+
/// Used to generate cfg variables and apply features.
284+
/// Must express features in the way Rust understands them.
285+
///
286+
/// We do not have to worry about RUSTC_SPECIFIC_FEATURES here, those are handled outside codegen.
285287
pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
286-
let mut features = vec![];
287-
288-
// Add base features for the target
288+
let mut features: FxHashSet<Symbol> = Default::default();
289+
290+
// Add base features for the target.
291+
// We do *not* add the -Ctarget-features there, and instead duplicate the logic for that below.
292+
// The reason is that if LLVM considers a feature implied but we do not, we don't want that to
293+
// show up in `cfg`. That way, `cfg` is entirely under our control -- except for the handling of
294+
// the target CPU, that is still expanded to target features (with all their implied features) by
295+
// LLVM.
289296
let target_machine = create_informational_target_machine(sess, true);
297+
// Compute which of the known target features are enabled in the 'base' target machine.
298+
// We only consider "supported" features; "forbidden" features are not reflected in `cfg` as of now.
290299
features.extend(
291300
sess.target
292-
.supported_target_features()
301+
.rust_target_features()
293302
.iter()
303+
.filter(|(_, gate, _)| gate.is_supported())
294304
.filter(|(feature, _, _)| {
295-
// skip checking special features, as LLVM may not understands them
305+
// skip checking special features, as LLVM may not understand them
296306
if RUSTC_SPECIAL_FEATURES.contains(feature) {
297307
return true;
298308
}
@@ -323,16 +333,22 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
323333
if enabled {
324334
features.extend(sess.target.implied_target_features(std::iter::once(feature)));
325335
} else {
336+
// We don't care about the order in `features` since the only thing we use it for is the
337+
// `features.contains` below.
338+
#[allow(rustc::potential_query_instability)]
326339
features.retain(|f| {
340+
// Keep a feature if it does not imply `feature`. Or, equivalently,
341+
// remove the reverse-dependencies of `feature`.
327342
!sess.target.implied_target_features(std::iter::once(*f)).contains(&feature)
328343
});
329344
}
330345
}
331346

332347
// Filter enabled features based on feature gates
333348
sess.target
334-
.supported_target_features()
349+
.rust_target_features()
335350
.iter()
351+
.filter(|(_, gate, _)| gate.is_supported())
336352
.filter_map(|&(feature, gate, _)| {
337353
if sess.is_nightly_build() || allow_unstable || gate.is_stable() {
338354
Some(feature)
@@ -392,9 +408,13 @@ fn print_target_features(out: &mut String, sess: &Session, tm: &llvm::TargetMach
392408
let mut known_llvm_target_features = FxHashSet::<&'static str>::default();
393409
let mut rustc_target_features = sess
394410
.target
395-
.supported_target_features()
411+
.rust_target_features()
396412
.iter()
397-
.filter_map(|(feature, _gate, _implied)| {
413+
.filter_map(|(feature, gate, _implied)| {
414+
if !gate.is_supported() {
415+
// Only list (experimentally) supported features.
416+
return None;
417+
}
398418
// LLVM asserts that these are sorted. LLVM and Rust both use byte comparison for these
399419
// strings.
400420
let llvm_feature = to_llvm_features(sess, *feature)?.llvm_feature_name;
@@ -567,7 +587,7 @@ pub(crate) fn global_llvm_features(
567587

568588
// -Ctarget-features
569589
if !only_base_features {
570-
let supported_features = sess.target.supported_target_features();
590+
let known_features = sess.target.rust_target_features();
571591
let mut featsmap = FxHashMap::default();
572592

573593
// insert implied features
@@ -601,50 +621,53 @@ pub(crate) fn global_llvm_features(
601621
}
602622
};
603623

624+
// Get the backend feature name, if any.
625+
// This excludes rustc-specific features, which do not get passed to LLVM.
604626
let feature = backend_feature_name(sess, s)?;
605627
// Warn against use of LLVM specific feature names and unstable features on the CLI.
606628
if diagnostics {
607-
let feature_state = supported_features.iter().find(|&&(v, _, _)| v == feature);
608-
if feature_state.is_none() {
609-
let rust_feature =
610-
supported_features.iter().find_map(|&(rust_feature, _, _)| {
611-
let llvm_features = to_llvm_features(sess, rust_feature)?;
612-
if llvm_features.contains(feature)
613-
&& !llvm_features.contains(rust_feature)
614-
{
615-
Some(rust_feature)
616-
} else {
617-
None
629+
let feature_state = known_features.iter().find(|&&(v, _, _)| v == feature);
630+
match feature_state {
631+
None => {
632+
let rust_feature =
633+
known_features.iter().find_map(|&(rust_feature, _, _)| {
634+
let llvm_features = to_llvm_features(sess, rust_feature)?;
635+
if llvm_features.contains(feature)
636+
&& !llvm_features.contains(rust_feature)
637+
{
638+
Some(rust_feature)
639+
} else {
640+
None
641+
}
642+
});
643+
let unknown_feature = if let Some(rust_feature) = rust_feature {
644+
UnknownCTargetFeature {
645+
feature,
646+
rust_feature: PossibleFeature::Some { rust_feature },
618647
}
619-
});
620-
let unknown_feature = if let Some(rust_feature) = rust_feature {
621-
UnknownCTargetFeature {
622-
feature,
623-
rust_feature: PossibleFeature::Some { rust_feature },
624-
}
625-
} else {
626-
UnknownCTargetFeature { feature, rust_feature: PossibleFeature::None }
627-
};
628-
sess.dcx().emit_warn(unknown_feature);
629-
} else if feature_state
630-
.is_some_and(|(_name, feature_gate, _implied)| !feature_gate.is_stable())
631-
{
632-
// An unstable feature. Warn about using it.
633-
sess.dcx().emit_warn(UnstableCTargetFeature { feature });
648+
} else {
649+
UnknownCTargetFeature {
650+
feature,
651+
rust_feature: PossibleFeature::None,
652+
}
653+
};
654+
sess.dcx().emit_warn(unknown_feature);
655+
}
656+
Some((_, Stability::Stable, _)) => {}
657+
Some((_, Stability::Unstable(_), _)) => {
658+
// An unstable feature. Warn about using it.
659+
sess.dcx().emit_warn(UnstableCTargetFeature { feature });
660+
}
661+
Some((_, Stability::Forbidden { reason }, _)) => {
662+
sess.dcx().emit_warn(ForbiddenCTargetFeature { feature, reason });
663+
}
634664
}
635-
}
636665

637-
if diagnostics {
638666
// FIXME(nagisa): figure out how to not allocate a full hashset here.
639667
featsmap.insert(feature, enable_disable == '+');
640668
}
641669

642-
// rustc-specific features do not get passed down to LLVM…
643-
if RUSTC_SPECIFIC_FEATURES.contains(&feature) {
644-
return None;
645-
}
646-
647-
// ... otherwise though we run through `to_llvm_features` when
670+
// We run through `to_llvm_features` when
648671
// passing requests down to LLVM. This means that all in-language
649672
// features also work on the command line instead of having two
650673
// different names when the LLVM name and the Rust name differ.

‎compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ codegen_ssa_failed_to_write = failed to write {$path}: {$error}
5858
5959
codegen_ssa_field_associated_value_expected = associated value expected for `{$name}`
6060
61+
codegen_ssa_forbidden_target_feature_attr =
62+
target feature `{$feature}` cannot be toggled with `#[target_feature]`: {$reason}
63+
6164
codegen_ssa_ignoring_emit_path = ignoring emit path because multiple .{$extension} files were produced
6265
6366
codegen_ssa_ignoring_output = ignoring -o because multiple .{$extension} files were produced

‎compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use rustc_span::symbol::Ident;
2020
use rustc_span::{Span, sym};
2121
use rustc_target::spec::{SanitizerSet, abi};
2222

23-
use crate::errors::{self, MissingFeatures, TargetFeatureDisableOrEnable};
24-
use crate::target_features::{check_target_feature_trait_unsafe, from_target_feature};
23+
use crate::errors;
24+
use crate::target_features::{check_target_feature_trait_unsafe, from_target_feature_attr};
2525

2626
fn linkage_by_name(tcx: TyCtxt<'_>, def_id: LocalDefId, name: &str) -> Linkage {
2727
use rustc_middle::mir::mono::Linkage::*;
@@ -73,7 +73,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
7373
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_BUILTINS;
7474
}
7575

76-
let supported_target_features = tcx.supported_target_features(LOCAL_CRATE);
76+
let rust_target_features = tcx.rust_target_features(LOCAL_CRATE);
7777

7878
let mut inline_span = None;
7979
let mut link_ordinal_span = None;
@@ -281,10 +281,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
281281
check_target_feature_trait_unsafe(tcx, did, attr.span);
282282
}
283283
}
284-
from_target_feature(
284+
from_target_feature_attr(
285285
tcx,
286286
attr,
287-
supported_target_features,
287+
rust_target_features,
288288
&mut codegen_fn_attrs.target_features,
289289
);
290290
}
@@ -676,10 +676,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
676676
.next()
677677
.map_or_else(|| tcx.def_span(did), |a| a.span);
678678
tcx.dcx()
679-
.create_err(TargetFeatureDisableOrEnable {
679+
.create_err(errors::TargetFeatureDisableOrEnable {
680680
features,
681681
span: Some(span),
682-
missing_features: Some(MissingFeatures),
682+
missing_features: Some(errors::MissingFeatures),
683683
})
684684
.emit();
685685
}

‎compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,15 @@ pub(crate) struct TargetFeatureSafeTrait {
10181018
pub def: Span,
10191019
}
10201020

1021+
#[derive(Diagnostic)]
1022+
#[diag(codegen_ssa_forbidden_target_feature_attr)]
1023+
pub struct ForbiddenTargetFeatureAttr<'a> {
1024+
#[primary_span]
1025+
pub span: Span,
1026+
pub feature: &'a str,
1027+
pub reason: &'a str,
1028+
}
1029+
10211030
#[derive(Diagnostic)]
10221031
#[diag(codegen_ssa_failed_to_get_layout)]
10231032
pub struct FailedToGetLayout<'tcx> {

‎compiler/rustc_codegen_ssa/src/target_features.rs

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ use rustc_middle::ty::TyCtxt;
1111
use rustc_session::parse::feature_err;
1212
use rustc_span::Span;
1313
use rustc_span::symbol::{Symbol, sym};
14+
use rustc_target::target_features::{self, Stability};
1415

1516
use crate::errors;
1617

17-
pub(crate) fn from_target_feature(
18+
/// Compute the enabled target features from the `#[target_feature]` function attribute.
19+
/// Enabled target features are added to `target_features`.
20+
pub(crate) fn from_target_feature_attr(
1821
tcx: TyCtxt<'_>,
1922
attr: &ast::Attribute,
20-
supported_target_features: &UnordMap<String, Option<Symbol>>,
23+
rust_target_features: &UnordMap<String, target_features::Stability>,
2124
target_features: &mut Vec<TargetFeature>,
2225
) {
2326
let Some(list) = attr.meta_item_list() else { return };
@@ -46,12 +49,12 @@ pub(crate) fn from_target_feature(
4649

4750
// We allow comma separation to enable multiple features.
4851
added_target_features.extend(value.as_str().split(',').filter_map(|feature| {
49-
let Some(feature_gate) = supported_target_features.get(feature) else {
52+
let Some(stability) = rust_target_features.get(feature) else {
5053
let msg = format!("the feature named `{feature}` is not valid for this target");
5154
let mut err = tcx.dcx().struct_span_err(item.span(), msg);
5255
err.span_label(item.span(), format!("`{feature}` is not valid for this target"));
5356
if let Some(stripped) = feature.strip_prefix('+') {
54-
let valid = supported_target_features.contains_key(stripped);
57+
let valid = rust_target_features.contains_key(stripped);
5558
if valid {
5659
err.help("consider removing the leading `+` in the feature name");
5760
}
@@ -61,18 +64,31 @@ pub(crate) fn from_target_feature(
6164
};
6265

6366
// Only allow target features whose feature gates have been enabled.
64-
let allowed = match feature_gate.as_ref().copied() {
65-
Some(name) => rust_features.enabled(name),
66-
None => true,
67+
let allowed = match stability {
68+
Stability::Forbidden { .. } => false,
69+
Stability::Stable => true,
70+
Stability::Unstable(name) => rust_features.enabled(*name),
6771
};
6872
if !allowed {
69-
feature_err(
70-
&tcx.sess,
71-
feature_gate.unwrap(),
72-
item.span(),
73-
format!("the target feature `{feature}` is currently unstable"),
74-
)
75-
.emit();
73+
match stability {
74+
Stability::Stable => unreachable!(),
75+
&Stability::Unstable(lang_feature_name) => {
76+
feature_err(
77+
&tcx.sess,
78+
lang_feature_name,
79+
item.span(),
80+
format!("the target feature `{feature}` is currently unstable"),
81+
)
82+
.emit();
83+
}
84+
Stability::Forbidden { reason } => {
85+
tcx.dcx().emit_err(errors::ForbiddenTargetFeatureAttr {
86+
span: item.span(),
87+
feature,
88+
reason,
89+
});
90+
}
91+
}
7692
}
7793
Some(Symbol::intern(feature))
7894
}));
@@ -138,20 +154,20 @@ pub(crate) fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId,
138154

139155
pub(crate) fn provide(providers: &mut Providers) {
140156
*providers = Providers {
141-
supported_target_features: |tcx, cnum| {
157+
rust_target_features: |tcx, cnum| {
142158
assert_eq!(cnum, LOCAL_CRATE);
143159
if tcx.sess.opts.actually_rustdoc {
144160
// rustdoc needs to be able to document functions that use all the features, so
145161
// whitelist them all
146-
rustc_target::target_features::all_known_features()
147-
.map(|(a, b)| (a.to_string(), b.as_feature_name()))
162+
rustc_target::target_features::all_rust_features()
163+
.map(|(a, b)| (a.to_string(), b))
148164
.collect()
149165
} else {
150166
tcx.sess
151167
.target
152-
.supported_target_features()
168+
.rust_target_features()
153169
.iter()
154-
.map(|&(a, b, _)| (a.to_string(), b.as_feature_name()))
170+
.map(|&(a, b, _)| (a.to_string(), b))
155171
.collect()
156172
}
157173
},

‎compiler/rustc_middle/src/query/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,10 +2185,11 @@ rustc_queries! {
21852185
desc { "computing autoderef types for `{}`", goal.canonical.value.value }
21862186
}
21872187

2188-
query supported_target_features(_: CrateNum) -> &'tcx UnordMap<String, Option<Symbol>> {
2188+
/// Returns the Rust target features for the current target. These are not always the same as LLVM target features!
2189+
query rust_target_features(_: CrateNum) -> &'tcx UnordMap<String, rustc_target::target_features::Stability> {
21892190
arena_cache
21902191
eval_always
2191-
desc { "looking up supported target features" }
2192+
desc { "looking up Rust target features" }
21922193
}
21932194

21942195
query implied_target_features(feature: Symbol) -> &'tcx Vec<Symbol> {

‎compiler/rustc_session/src/config/cfg.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,9 @@ impl CheckCfg {
370370
ins!(sym::sanitizer_cfi_normalize_integers, no_values);
371371

372372
ins!(sym::target_feature, empty_values).extend(
373-
rustc_target::target_features::all_known_features()
374-
.map(|(f, _sb)| f)
373+
rustc_target::target_features::all_rust_features()
374+
.filter(|(_, s)| s.is_supported())
375+
.map(|(f, _s)| f)
375376
.chain(rustc_target::target_features::RUSTC_SPECIFIC_FEATURES.iter().cloned())
376377
.map(Symbol::intern),
377378
);

‎compiler/rustc_target/src/target_features.rs

Lines changed: 91 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
//! Declares Rust's target feature names for each target.
2+
//! Note that these are similar to but not always identical to LLVM's feature names,
3+
//! and Rust adds some features that do not correspond to LLVM features at all.
14
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
26
use rustc_span::symbol::{Symbol, sym};
37

48
/// Features that control behaviour of rustc, rather than the codegen.
9+
/// These exist globally and are not in the target-specific lists below.
510
pub const RUSTC_SPECIFIC_FEATURES: &[&str] = &["crt-static"];
611

7-
/// Features that require special handling when passing to LLVM.
12+
/// Features that require special handling when passing to LLVM:
13+
/// these are target-specific (i.e., must also be listed in the target-specific list below)
14+
/// but do not correspond to an LLVM target feature.
815
pub const RUSTC_SPECIAL_FEATURES: &[&str] = &["backchain"];
916

1017
/// Stability information for target features.
@@ -16,26 +23,47 @@ pub enum Stability {
1623
/// This target feature is unstable; using it in `#[target_feature]` or `#[cfg(target_feature)]`
1724
/// requires enabling the given nightly feature.
1825
Unstable(Symbol),
26+
/// This feature can not be set via `-Ctarget-feature` or `#[target_feature]`, it can only be set in the basic
27+
/// target definition. Used in particular for features that change the floating-point ABI.
28+
Forbidden { reason: &'static str },
1929
}
2030
use Stability::*;
2131

22-
impl Stability {
23-
pub fn as_feature_name(self) -> Option<Symbol> {
32+
impl<CTX> HashStable<CTX> for Stability {
33+
#[inline]
34+
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
35+
std::mem::discriminant(self).hash_stable(hcx, hasher);
2436
match self {
25-
Stable => None,
26-
Unstable(s) => Some(s),
37+
Stable => {}
38+
Unstable(sym) => {
39+
sym.hash_stable(hcx, hasher);
40+
}
41+
Forbidden { .. } => {}
2742
}
2843
}
44+
}
2945

46+
impl Stability {
3047
pub fn is_stable(self) -> bool {
3148
matches!(self, Stable)
3249
}
50+
51+
/// Forbidden features are not supported.
52+
pub fn is_supported(self) -> bool {
53+
!matches!(self, Forbidden { .. })
54+
}
3355
}
3456

3557
// Here we list target features that rustc "understands": they can be used in `#[target_feature]`
3658
// and `#[cfg(target_feature)]`. They also do not trigger any warnings when used with
3759
// `-Ctarget-feature`.
3860
//
61+
// Note that even unstable (and even entirely unlisted) features can be used with `-Ctarget-feature`
62+
// on stable. Using a feature not on the list of Rust target features only emits a warning.
63+
// Only `cfg(target_feature)` and `#[target_feature]` actually do any stability gating.
64+
// `cfg(target_feature)` for unstable features just works on nightly without any feature gate.
65+
// `#[target_feature]` requires a feature gate.
66+
//
3967
// When adding features to the below lists
4068
// check whether they're named already elsewhere in rust
4169
// e.g. in stdarch and whether the given name matches LLVM's
@@ -46,17 +74,27 @@ impl Stability {
4674
// per-function level, since we would then allow safe calls from functions with `+soft-float` to
4775
// functions without that feature!
4876
//
49-
// When adding a new feature, be particularly mindful of features that affect function ABIs. Those
50-
// need to be treated very carefully to avoid introducing unsoundness! This often affects features
51-
// that enable/disable hardfloat support (see https://github.com/rust-lang/rust/issues/116344 for an
52-
// example of this going wrong), but features enabling new SIMD registers are also a concern (see
53-
// https://github.com/rust-lang/rust/issues/116558 for an example of this going wrong).
77+
// It is important for soundness that features allowed here do *not* change the function call ABI.
78+
// For example, disabling the `x87` feature on x86 changes how scalar floats are passed as
79+
// arguments, so enabling toggling that feature would be unsound. In fact, since `-Ctarget-feature`
80+
// will just allow unknown features (with a warning), we have to explicitly list features that change
81+
// the ABI as `Forbidden` to ensure using them causes an error. Note that this is only effective if
82+
// such features can never be toggled via `-Ctarget-cpu`! If that is ever a possibility, we will need
83+
// extra checks ensuring that the LLVM-computed target features for a CPU did not (un)set a
84+
// `Forbidden` feature. See https://github.com/rust-lang/rust/issues/116344 for some more context.
85+
// FIXME: add such "forbidden" features for non-x86 targets.
86+
//
87+
// The one exception to features that change the ABI is features that enable larger vector
88+
// registers. Those are permitted to be listed here. This is currently unsound (see
89+
// https://github.com/rust-lang/rust/issues/116558); in the future we will have to ensure that
90+
// functions can only use such vectors as arguments/return types if the corresponding target feature
91+
// is enabled.
5492
//
5593
// Stabilizing a target feature requires t-lang approval.
5694

5795
type ImpliedFeatures = &'static [&'static str];
5896

59-
const ARM_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
97+
const ARM_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
6098
// tidy-alphabetical-start
6199
("aclass", Unstable(sym::arm_target_feature), &[]),
62100
("aes", Unstable(sym::arm_target_feature), &["neon"]),
@@ -70,6 +108,7 @@ const ARM_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
70108
("neon", Unstable(sym::arm_target_feature), &["vfp3"]),
71109
("rclass", Unstable(sym::arm_target_feature), &[]),
72110
("sha2", Unstable(sym::arm_target_feature), &["neon"]),
111+
("soft-float", Forbidden { reason: "unsound because it changes float ABI" }, &[]),
73112
// This is needed for inline assembly, but shouldn't be stabilized as-is
74113
// since it should be enabled per-function using #[instruction_set], not
75114
// #[target_feature].
@@ -87,9 +126,10 @@ const ARM_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
87126
("vfp4", Unstable(sym::arm_target_feature), &["vfp3"]),
88127
("virtualization", Unstable(sym::arm_target_feature), &[]),
89128
// tidy-alphabetical-end
129+
// FIXME: need to also forbid turning off `fpregs` on hardfloat targets
90130
];
91131

92-
const AARCH64_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
132+
const AARCH64_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
93133
// tidy-alphabetical-start
94134
// FEAT_AES & FEAT_PMULL
95135
("aes", Stable, &["neon"]),
@@ -277,7 +317,7 @@ const AARCH64_TIED_FEATURES: &[&[&str]] = &[
277317
&["paca", "pacg"], // Together these represent `pauth` in LLVM
278318
];
279319

280-
const X86_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
320+
const X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
281321
// tidy-alphabetical-start
282322
("adx", Stable, &[]),
283323
("aes", Stable, &["sse2"]),
@@ -328,6 +368,7 @@ const X86_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
328368
("sha512", Unstable(sym::sha512_sm_x86), &["avx2"]),
329369
("sm3", Unstable(sym::sha512_sm_x86), &["avx"]),
330370
("sm4", Unstable(sym::sha512_sm_x86), &["avx2"]),
371+
("soft-float", Forbidden { reason: "unsound because it changes float ABI" }, &[]),
331372
("sse", Stable, &[]),
332373
("sse2", Stable, &["sse"]),
333374
("sse3", Stable, &["sse2"]),
@@ -344,16 +385,17 @@ const X86_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
344385
("xsaveopt", Stable, &["xsave"]),
345386
("xsaves", Stable, &["xsave"]),
346387
// tidy-alphabetical-end
388+
// FIXME: need to also forbid turning off `x87` on hardfloat targets
347389
];
348390

349-
const HEXAGON_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
391+
const HEXAGON_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
350392
// tidy-alphabetical-start
351393
("hvx", Unstable(sym::hexagon_target_feature), &[]),
352394
("hvx-length128b", Unstable(sym::hexagon_target_feature), &["hvx"]),
353395
// tidy-alphabetical-end
354396
];
355397

356-
const POWERPC_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
398+
const POWERPC_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
357399
// tidy-alphabetical-start
358400
("altivec", Unstable(sym::powerpc_target_feature), &[]),
359401
("partword-atomics", Unstable(sym::powerpc_target_feature), &[]),
@@ -367,15 +409,15 @@ const POWERPC_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
367409
// tidy-alphabetical-end
368410
];
369411

370-
const MIPS_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
412+
const MIPS_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
371413
// tidy-alphabetical-start
372414
("fp64", Unstable(sym::mips_target_feature), &[]),
373415
("msa", Unstable(sym::mips_target_feature), &[]),
374416
("virt", Unstable(sym::mips_target_feature), &[]),
375417
// tidy-alphabetical-end
376418
];
377419

378-
const RISCV_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
420+
const RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
379421
// tidy-alphabetical-start
380422
("a", Stable, &["zaamo", "zalrsc"]),
381423
("c", Stable, &[]),
@@ -415,7 +457,7 @@ const RISCV_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
415457
// tidy-alphabetical-end
416458
];
417459

418-
const WASM_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
460+
const WASM_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
419461
// tidy-alphabetical-start
420462
("atomics", Unstable(sym::wasm_target_feature), &[]),
421463
("bulk-memory", Stable, &[]),
@@ -431,10 +473,10 @@ const WASM_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
431473
// tidy-alphabetical-end
432474
];
433475

434-
const BPF_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] =
476+
const BPF_FEATURES: &[(&str, Stability, ImpliedFeatures)] =
435477
&[("alu32", Unstable(sym::bpf_target_feature), &[])];
436478

437-
const CSKY_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
479+
const CSKY_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
438480
// tidy-alphabetical-start
439481
("10e60", Unstable(sym::csky_target_feature), &["7e10"]),
440482
("2e3", Unstable(sym::csky_target_feature), &["e2"]),
@@ -481,7 +523,7 @@ const CSKY_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
481523
// tidy-alphabetical-end
482524
];
483525

484-
const LOONGARCH_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
526+
const LOONGARCH_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
485527
// tidy-alphabetical-start
486528
("d", Unstable(sym::loongarch_target_feature), &["f"]),
487529
("f", Unstable(sym::loongarch_target_feature), &[]),
@@ -495,7 +537,7 @@ const LOONGARCH_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
495537
// tidy-alphabetical-end
496538
];
497539

498-
const IBMZ_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
540+
const IBMZ_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
499541
// tidy-alphabetical-start
500542
("backchain", Unstable(sym::s390x_target_feature), &[]),
501543
("vector", Unstable(sym::s390x_target_feature), &[]),
@@ -506,41 +548,39 @@ const IBMZ_ALLOWED_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
506548
/// primitives may be documented.
507549
///
508550
/// IMPORTANT: If you're adding another feature list above, make sure to add it to this iterator!
509-
pub fn all_known_features() -> impl Iterator<Item = (&'static str, Stability)> {
551+
pub fn all_rust_features() -> impl Iterator<Item = (&'static str, Stability)> {
510552
std::iter::empty()
511-
.chain(ARM_ALLOWED_FEATURES.iter())
512-
.chain(AARCH64_ALLOWED_FEATURES.iter())
513-
.chain(X86_ALLOWED_FEATURES.iter())
514-
.chain(HEXAGON_ALLOWED_FEATURES.iter())
515-
.chain(POWERPC_ALLOWED_FEATURES.iter())
516-
.chain(MIPS_ALLOWED_FEATURES.iter())
517-
.chain(RISCV_ALLOWED_FEATURES.iter())
518-
.chain(WASM_ALLOWED_FEATURES.iter())
519-
.chain(BPF_ALLOWED_FEATURES.iter())
520-
.chain(CSKY_ALLOWED_FEATURES)
521-
.chain(LOONGARCH_ALLOWED_FEATURES)
522-
.chain(IBMZ_ALLOWED_FEATURES)
553+
.chain(ARM_FEATURES.iter())
554+
.chain(AARCH64_FEATURES.iter())
555+
.chain(X86_FEATURES.iter())
556+
.chain(HEXAGON_FEATURES.iter())
557+
.chain(POWERPC_FEATURES.iter())
558+
.chain(MIPS_FEATURES.iter())
559+
.chain(RISCV_FEATURES.iter())
560+
.chain(WASM_FEATURES.iter())
561+
.chain(BPF_FEATURES.iter())
562+
.chain(CSKY_FEATURES)
563+
.chain(LOONGARCH_FEATURES)
564+
.chain(IBMZ_FEATURES)
523565
.cloned()
524566
.map(|(f, s, _)| (f, s))
525567
}
526568

527569
impl super::spec::Target {
528-
pub fn supported_target_features(
529-
&self,
530-
) -> &'static [(&'static str, Stability, ImpliedFeatures)] {
570+
pub fn rust_target_features(&self) -> &'static [(&'static str, Stability, ImpliedFeatures)] {
531571
match &*self.arch {
532-
"arm" => ARM_ALLOWED_FEATURES,
533-
"aarch64" | "arm64ec" => AARCH64_ALLOWED_FEATURES,
534-
"x86" | "x86_64" => X86_ALLOWED_FEATURES,
535-
"hexagon" => HEXAGON_ALLOWED_FEATURES,
536-
"mips" | "mips32r6" | "mips64" | "mips64r6" => MIPS_ALLOWED_FEATURES,
537-
"powerpc" | "powerpc64" => POWERPC_ALLOWED_FEATURES,
538-
"riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES,
539-
"wasm32" | "wasm64" => WASM_ALLOWED_FEATURES,
540-
"bpf" => BPF_ALLOWED_FEATURES,
541-
"csky" => CSKY_ALLOWED_FEATURES,
542-
"loongarch64" => LOONGARCH_ALLOWED_FEATURES,
543-
"s390x" => IBMZ_ALLOWED_FEATURES,
572+
"arm" => ARM_FEATURES,
573+
"aarch64" | "arm64ec" => AARCH64_FEATURES,
574+
"x86" | "x86_64" => X86_FEATURES,
575+
"hexagon" => HEXAGON_FEATURES,
576+
"mips" | "mips32r6" | "mips64" | "mips64r6" => MIPS_FEATURES,
577+
"powerpc" | "powerpc64" => POWERPC_FEATURES,
578+
"riscv32" | "riscv64" => RISCV_FEATURES,
579+
"wasm32" | "wasm64" => WASM_FEATURES,
580+
"bpf" => BPF_FEATURES,
581+
"csky" => CSKY_FEATURES,
582+
"loongarch64" => LOONGARCH_FEATURES,
583+
"s390x" => IBMZ_FEATURES,
544584
_ => &[],
545585
}
546586
}
@@ -557,7 +597,7 @@ impl super::spec::Target {
557597
base_features: impl Iterator<Item = Symbol>,
558598
) -> FxHashSet<Symbol> {
559599
let implied_features = self
560-
.supported_target_features()
600+
.rust_target_features()
561601
.iter()
562602
.map(|(f, _, i)| (Symbol::intern(f), i))
563603
.collect::<FxHashMap<_, _>>();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=lib
2+
//@ needs-llvm-components: x86
3+
#![feature(no_core, lang_items)]
4+
#![no_std]
5+
#![no_core]
6+
7+
#[lang = "sized"]
8+
pub trait Sized {}
9+
10+
#[target_feature(enable = "soft-float")]
11+
//~^ERROR: cannot be toggled with
12+
pub unsafe fn my_fun() {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: target feature `soft-float` cannot be toggled with `#[target_feature]`: unsound because it changes float ABI
2+
--> $DIR/forbidden-target-feature-attribute.rs:10:18
3+
|
4+
LL | #[target_feature(enable = "soft-float")]
5+
| ^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to 1 previous error
8+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ compile-flags: --target=x86_64-unknown-none --crate-type=lib
2+
//@ needs-llvm-components: x86
3+
//@ check-pass
4+
#![feature(no_core, lang_items)]
5+
#![no_std]
6+
#![no_core]
7+
#![allow(unexpected_cfgs)]
8+
9+
#[lang = "sized"]
10+
pub trait Sized {}
11+
12+
// The compile_error macro does not exist, so if the `cfg` evaluates to `true` this
13+
// complains about the missing macro rather than showing the error... but that's good enough.
14+
#[cfg(target_feature = "soft-float")]
15+
compile_error!("the soft-float feature should not be exposed in `cfg`");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=lib
2+
//@ needs-llvm-components: x86
3+
//@ compile-flags: -Ctarget-feature=-soft-float
4+
// For now this is just a warning.
5+
//@ build-pass
6+
#![feature(no_core, lang_items)]
7+
#![no_std]
8+
#![no_core]
9+
10+
#[lang = "sized"]
11+
pub trait Sized {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
warning: target feature `soft-float` cannot be toggled with `-Ctarget-feature`: unsound because it changes float ABI
2+
|
3+
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4+
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
5+
6+
warning: 1 warning emitted
7+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=lib
2+
//@ needs-llvm-components: x86
3+
//@ compile-flags: -Ctarget-feature=+soft-float
4+
// For now this is just a warning.
5+
//@ build-pass
6+
#![feature(no_core, lang_items)]
7+
#![no_std]
8+
#![no_core]
9+
10+
#[lang = "sized"]
11+
pub trait Sized {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
warning: target feature `soft-float` cannot be toggled with `-Ctarget-feature`: unsound because it changes float ABI
2+
|
3+
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4+
= note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
5+
6+
warning: 1 warning emitted
7+

0 commit comments

Comments
 (0)
Please sign in to comment.