Skip to content

Commit 541b2c6

Browse files
RalfJungcuviper
authored andcommitted
also skip abi_required_features check in rustdoc
(cherry picked from commit 4c939db)
1 parent 207a543 commit 541b2c6

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

compiler/rustc_codegen_ssa/src/target_features.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,16 @@ pub(crate) fn from_target_feature_attr(
6565
// Only allow target features whose feature gates have been enabled
6666
// and which are permitted to be toggled.
6767
if let Err(reason) = stability.toggle_allowed(/*enable*/ true) {
68-
tcx.dcx().emit_err(errors::ForbiddenTargetFeatureAttr {
69-
span: item.span(),
70-
feature,
71-
reason,
72-
});
68+
// We skip this error in rustdoc, where we want to allow all target features of
69+
// all targets, so we can't check their ABI compatibility and anyway we are not
70+
// generating code so "it's fine".
71+
if !tcx.sess.opts.actually_rustdoc {
72+
tcx.dcx().emit_err(errors::ForbiddenTargetFeatureAttr {
73+
span: item.span(),
74+
feature,
75+
reason,
76+
});
77+
}
7378
} else if let Some(nightly_feature) = stability.requires_nightly()
7479
&& !rust_features.enabled(nightly_feature)
7580
{

tests/rustdoc-ui/target-feature-stability.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
//! This is a regression test for <https://github.com/rust-lang/rust/issues/137366>, ensuring
2-
//! that we can use the `neon` target feature on ARM-32 targets in rustdoc despite there
2+
//! that we can use the `neon` target feature on ARM32 targets in rustdoc despite there
33
//! being a "forbidden" feature of the same name for aarch64, and rustdoc merging the
44
//! target features of all targets.
55
//@ check-pass
6-
//@ compile-flags: --target armv7-unknown-linux-gnueabihf
6+
//@ revisions: arm aarch64
7+
//@[arm] compile-flags: --target armv7-unknown-linux-gnueabihf
8+
//@[arm] needs-llvm-components: arm
9+
//@[aarch64] compile-flags: --target aarch64-unknown-none-softfloat
10+
//@[aarch64] needs-llvm-components: aarch64
711

812
#![crate_type = "lib"]
913
#![feature(no_core, lang_items)]
@@ -15,4 +19,10 @@ pub trait Sized {}
1519

1620
// `fp-armv8` is "forbidden" on aarch64 as we tie it to `neon`.
1721
#[target_feature(enable = "fp-armv8")]
18-
pub fn fun() {}
22+
pub fn fun1() {}
23+
24+
// This would usually be rejected as it changes the ABI.
25+
// But we disable that check in rustdoc since we are building "for all targets" and the
26+
// check can't really handle that.
27+
#[target_feature(enable = "soft-float")]
28+
pub fn fun2() {}

0 commit comments

Comments
 (0)