Skip to content

Commit 3e95c71

Browse files
committed
Rollup merge of rust-lang#49225 - QuietMisdreavus:all-the-features-all-the-time, r=alexcrichton
whitelist every target feature for rustdoc When rust-lang/stdarch#367 was attempted to be upstreamed, it failed to document on non-x86 targets because it made every intrinsic visible, even the ones on foreign arches. This change makes it so that whenever rustdoc asks for the target feature whitelist, it gets a list of every feature known to every arch in `rustc_trans/llvm_util.rs`. Before pushing, i temporarily updated the `stdsimd` submodule to include the `doc(cfg)` change, generated documentation for `aarch64-unknown-linux-gnu`, and it completed without a problem. The generated `core::arch` docs contained complete submodules for all main arches.
2 parents 346a46e + 2ba41e9 commit 3e95c71

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

src/librustc_trans/attributes.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,17 @@ fn cstr(s: &'static str) -> &CStr {
148148
pub fn provide(providers: &mut Providers) {
149149
providers.target_features_whitelist = |tcx, cnum| {
150150
assert_eq!(cnum, LOCAL_CRATE);
151-
Lrc::new(llvm_util::target_feature_whitelist(tcx.sess)
152-
.iter()
153-
.map(|c| c.to_string())
154-
.collect())
151+
if tcx.sess.opts.actually_rustdoc {
152+
// rustdoc needs to be able to document functions that use all the features, so
153+
// whitelist them all
154+
Lrc::new(llvm_util::all_known_features()
155+
.map(|c| c.to_string())
156+
.collect())
157+
} else {
158+
Lrc::new(llvm_util::target_feature_whitelist(tcx.sess)
159+
.iter()
160+
.map(|c| c.to_string())
161+
.collect())
162+
}
155163
};
156164
}

src/librustc_trans/llvm_util.rs

+14
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ const POWERPC_WHITELIST: &'static [&'static str] = &["altivec",
107107

108108
const MIPS_WHITELIST: &'static [&'static str] = &["fp64", "msa"];
109109

110+
/// When rustdoc is running, provide a list of all known features so that all their respective
111+
/// primtives may be documented.
112+
///
113+
/// IMPORTANT: If you're adding another whitelist to the above lists, make sure to add it to this
114+
/// iterator!
115+
pub fn all_known_features() -> impl Iterator<Item=&'static str> {
116+
ARM_WHITELIST.iter().cloned()
117+
.chain(AARCH64_WHITELIST.iter().cloned())
118+
.chain(X86_WHITELIST.iter().cloned())
119+
.chain(HEXAGON_WHITELIST.iter().cloned())
120+
.chain(POWERPC_WHITELIST.iter().cloned())
121+
.chain(MIPS_WHITELIST.iter().cloned())
122+
}
123+
110124
pub fn to_llvm_feature<'a>(sess: &Session, s: &'a str) -> &'a str {
111125
let arch = if sess.target.target.arch == "x86_64" {
112126
"x86"

src/stdsimd

0 commit comments

Comments
 (0)