also skip abi_required_features check in rustdoc
authorRalf Jung <post@ralfj.de>
Fri, 28 Feb 2025 15:56:36 +0000 (16:56 +0100)
committerPeter Michael Green <plugwash@debian.org>
Tue, 8 Apr 2025 23:21:49 +0000 (23:21 +0000)
(cherry picked from commit 4c939db0e775df21a0b409b7603eaaf0056e8f86)

compiler/rustc_codegen_ssa/src/target_features.rs
tests/rustdoc-ui/target-feature-stability.rs

index bffcdca299b212ad93e826fc764e727057469c9b..0c53a731221db73249e028ce7d32c8cada2de301 100644 (file)
@@ -65,11 +65,16 @@ pub(crate) fn from_target_feature_attr(
             // Only allow target features whose feature gates have been enabled
             // and which are permitted to be toggled.
             if let Err(reason) = stability.toggle_allowed(/*enable*/ true) {
-                tcx.dcx().emit_err(errors::ForbiddenTargetFeatureAttr {
-                    span: item.span(),
-                    feature,
-                    reason,
-                });
+                // We skip this error in rustdoc, where we want to allow all target features of
+                // all targets, so we can't check their ABI compatibility and anyway we are not
+                // generating code so "it's fine".
+                if !tcx.sess.opts.actually_rustdoc {
+                    tcx.dcx().emit_err(errors::ForbiddenTargetFeatureAttr {
+                        span: item.span(),
+                        feature,
+                        reason,
+                    });
+                }
             } else if let Some(nightly_feature) = stability.requires_nightly()
                 && !rust_features.enabled(nightly_feature)
             {
index 4ade9690310e3b73d0edde4527227a95af4ab996..17fa3ccfe3e89cab0084e08231bcc542f2c57775 100644 (file)
@@ -1,9 +1,13 @@
 //! This is a regression test for <https://github.com/rust-lang/rust/issues/137366>, ensuring
-//! that we can use the `neon` target feature on ARM-32 targets in rustdoc despite there
+//! that we can use the `neon` target feature on ARM32 targets in rustdoc despite there
 //! being a "forbidden" feature of the same name for aarch64, and rustdoc merging the
 //! target features of all targets.
 //@ check-pass
-//@ compile-flags: --target armv7-unknown-linux-gnueabihf
+//@ revisions: arm aarch64
+//@[arm] compile-flags: --target armv7-unknown-linux-gnueabihf
+//@[arm] needs-llvm-components: arm
+//@[aarch64] compile-flags: --target aarch64-unknown-none-softfloat
+//@[aarch64] needs-llvm-components: aarch64
 
 #![crate_type = "lib"]
 #![feature(no_core, lang_items)]
@@ -15,4 +19,10 @@ pub trait Sized {}
 
 // `fp-armv8` is "forbidden" on aarch64 as we tie it to `neon`.
 #[target_feature(enable = "fp-armv8")]
-pub fn fun() {}
+pub fn fun1() {}
+
+// This would usually be rejected as it changes the ABI.
+// But we disable that check in rustdoc since we are building "for all targets" and the
+// check can't really handle that.
+#[target_feature(enable = "soft-float")]
+pub fn fun2() {}