Skip to content

Commit 691bcaa

Browse files
committed
make this just a warning (for use with the -C flag) for now; also show a reason why it is forbidden
1 parent a69de2c commit 691bcaa

File tree

13 files changed

+36
-23
lines changed

13 files changed

+36
-23
lines changed

compiler/rustc_codegen_gcc/src/gcc_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
9797
// An unstable feature. Warn about using it.
9898
sess.dcx().emit_warn(UnstableCTargetFeature { feature });
9999
}
100-
Some((_, Stability::Forbidden, _)) => {
100+
Some((_, Stability::Forbidden { .. }, _)) => {
101101
sess.dcx().emit_err(ForbiddenCTargetFeature { feature });
102102
}
103103
}

compiler/rustc_codegen_llvm/messages.ftl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ codegen_llvm_dynamic_linking_with_lto =
88
codegen_llvm_fixed_x18_invalid_arch = the `-Zfixed-x18` flag is not supported on the `{$arch}` architecture
99
1010
codegen_llvm_forbidden_ctarget_feature =
11-
target feature `{$feature}` cannot be toggled with `-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>
1214
1315
codegen_llvm_from_llvm_diag = {$message}
1416

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ pub(crate) struct UnstableCTargetFeature<'a> {
3333

3434
#[derive(Diagnostic)]
3535
#[diag(codegen_llvm_forbidden_ctarget_feature)]
36+
#[note]
37+
#[note(codegen_llvm_forbidden_ctarget_feature_issue)]
3638
pub(crate) struct ForbiddenCTargetFeature<'a> {
3739
pub feature: &'a str,
40+
pub reason: &'a str,
3841
}
3942

4043
#[derive(Subdiagnostic)]

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,8 @@ pub(crate) fn global_llvm_features(
679679
// An unstable feature. Warn about using it.
680680
sess.dcx().emit_warn(UnstableCTargetFeature { feature });
681681
}
682-
Some((_, Stability::Forbidden, _)) => {
683-
sess.dcx().emit_err(ForbiddenCTargetFeature { feature });
682+
Some((_, Stability::Forbidden { reason }, _)) => {
683+
sess.dcx().emit_warn(ForbiddenCTargetFeature { feature, reason });
684684
}
685685
}
686686

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ codegen_ssa_failed_to_write = failed to write {$path}: {$error}
5959
codegen_ssa_field_associated_value_expected = associated value expected for `{$name}`
6060
6161
codegen_ssa_forbidden_target_feature =
62-
target feature `{$feature}` cannot be toggled with `#[target_feature]`
62+
target feature `{$feature}` cannot be toggled with `#[target_feature]`: {$reason}
6363
6464
codegen_ssa_ignoring_emit_path = ignoring emit path because multiple .{$extension} files were produced
6565

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,7 @@ pub struct ForbiddenTargetFeature<'a> {
10231023
#[primary_span]
10241024
pub span: Span,
10251025
pub feature: &'a str,
1026+
pub reason: &'a str,
10261027
}
10271028

10281029
#[derive(Diagnostic)]

compiler/rustc_codegen_ssa/src/target_features.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn from_target_feature_attr(
6666

6767
// Only allow features whose feature gates have been enabled.
6868
let allowed = match stability {
69-
Stability::Forbidden => false,
69+
Stability::Forbidden { .. } => false,
7070
Stability::Stable => true,
7171
Stability::Unstable(sym::arm_target_feature) => rust_features.arm_target_feature,
7272
Stability::Unstable(sym::hexagon_target_feature) => {
@@ -125,10 +125,11 @@ pub fn from_target_feature_attr(
125125
)
126126
.emit();
127127
}
128-
Stability::Forbidden => {
128+
Stability::Forbidden { reason } => {
129129
tcx.dcx().emit_err(errors::ForbiddenTargetFeature {
130130
span: item.span(),
131131
feature,
132+
reason,
132133
});
133134
}
134135
}

compiler/rustc_target/src/target_features.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub enum Stability {
2525
Unstable(Symbol),
2626
/// This feature can not be set via `-Ctarget-feature` or `#[target_feature]`, it can only be set in the basic
2727
/// target definition. Used in particular for features that change the floating-point ABI.
28-
Forbidden,
28+
Forbidden { reason: &'static str },
2929
}
3030
use Stability::*;
3131

@@ -38,7 +38,7 @@ impl<CTX> HashStable<CTX> for Stability {
3838
Unstable(sym) => {
3939
sym.hash_stable(hcx, hasher);
4040
}
41-
Forbidden => {}
41+
Forbidden { .. } => {}
4242
}
4343
}
4444
}
@@ -50,7 +50,7 @@ impl Stability {
5050

5151
/// Forbidden features are not supported.
5252
pub fn is_supported(self) -> bool {
53-
!matches!(self, Forbidden)
53+
!matches!(self, Forbidden { .. })
5454
}
5555
}
5656

@@ -101,13 +101,13 @@ const ARM_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
101101
("dotprod", Unstable(sym::arm_target_feature), &["neon"]),
102102
("dsp", Unstable(sym::arm_target_feature), &[]),
103103
("fp-armv8", Unstable(sym::arm_target_feature), &["vfp4"]),
104-
("fpregs", Forbidden, &[]), // changes float ABI
104+
("fpregs", Forbidden { reason: "unsound because it changes float ABI" }, &[]),
105105
("i8mm", Unstable(sym::arm_target_feature), &["neon"]),
106106
("mclass", Unstable(sym::arm_target_feature), &[]),
107107
("neon", Unstable(sym::arm_target_feature), &["vfp3"]),
108108
("rclass", Unstable(sym::arm_target_feature), &[]),
109109
("sha2", Unstable(sym::arm_target_feature), &["neon"]),
110-
("soft-float", Forbidden, &[]), // changes float ABI
110+
("soft-float", Forbidden { reason: "unsound because it changes float ABI" }, &[]),
111111
// This is needed for inline assembly, but shouldn't be stabilized as-is
112112
// since it should be enabled per-function using #[instruction_set], not
113113
// #[target_feature].
@@ -366,7 +366,7 @@ const X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
366366
("sha512", Unstable(sym::sha512_sm_x86), &["avx2"]),
367367
("sm3", Unstable(sym::sha512_sm_x86), &["avx"]),
368368
("sm4", Unstable(sym::sha512_sm_x86), &["avx2"]),
369-
("soft-float", Forbidden, &[]), // changes float ABI
369+
("soft-float", Forbidden { reason: "unsound because it changes float ABI" }, &[]),
370370
("sse", Stable, &[]),
371371
("sse2", Stable, &["sse"]),
372372
("sse3", Stable, &["sse2"]),
@@ -377,7 +377,7 @@ const X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
377377
("tbm", Unstable(sym::tbm_target_feature), &[]),
378378
("vaes", Unstable(sym::avx512_target_feature), &["avx2", "aes"]),
379379
("vpclmulqdq", Unstable(sym::avx512_target_feature), &["avx", "pclmulqdq"]),
380-
("x87", Forbidden, &[]), // changes float ABI
380+
("x87", Forbidden { reason: "unsound because it changes float ABI" }, &[]),
381381
("xop", Unstable(sym::xop_target_feature), &[/*"fma4", */ "avx", "sse4a"]),
382382
("xsave", Stable, &[]),
383383
("xsavec", Stable, &["xsave"]),

tests/ui/target-feature/forbidden-target-feature-attribute.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: target feature `soft-float` cannot be toggled with `#[target_feature]`
1+
error: target feature `soft-float` cannot be toggled with `#[target_feature]`: unsound because it changes float ABI
22
--> $DIR/forbidden-target-feature-attribute.rs:10:18
33
|
44
LL | #[target_feature(enable = "soft-float")]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//@ compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=lib
22
//@ needs-llvm-components: x86
33
//@ compile-flags: -Ctarget-feature=-soft-float
4+
// For now this is just a warning.
5+
//@ build-pass
46
#![feature(no_core, lang_items)]
57
#![no_std]
68
#![no_core]
79

810
#[lang = "sized"]
911
pub trait Sized {}
10-
11-
fn main() {}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
error: target feature `soft-float` cannot be toggled with `-Ctarget-feature`
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>
25

3-
error: aborting due to 1 previous error
6+
warning: 1 warning emitted
47

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//@ compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=lib
22
//@ needs-llvm-components: x86
33
//@ compile-flags: -Ctarget-feature=+soft-float
4+
// For now this is just a warning.
5+
//@ build-pass
46
#![feature(no_core, lang_items)]
57
#![no_std]
68
#![no_core]
79

810
#[lang = "sized"]
911
pub trait Sized {}
10-
11-
fn main() {}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
error: target feature `soft-float` cannot be toggled with `-Ctarget-feature`
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>
25

3-
error: aborting due to 1 previous error
6+
warning: 1 warning emitted
47

0 commit comments

Comments
 (0)