Skip to content

Commit 35b0e35

Browse files
advice against negative features in target specs
Co-authored-by: Jubilee <[email protected]>
1 parent 0c9d42c commit 35b0e35

File tree

1 file changed

+7
-0
lines changed
  • compiler/rustc_target/src/spec

1 file changed

+7
-0
lines changed

compiler/rustc_target/src/spec/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,10 @@ pub struct TargetOptions {
22132213
/// `-Ctarget-cpu` but can be overwritten with `-Ctarget-features`.
22142214
/// Corresponds to `llc -mattr=$features`.
22152215
/// Note that these are LLVM feature names, not Rust feature names!
2216+
///
2217+
/// Generally it is a bad idea to use negative features here since they
2218+
/// interact poorly with `-Ctarget-cpu`. Instead, try to use a lower
2219+
/// "base CPU" and enable the features you want to use.
22162220
pub features: StaticCow<str>,
22172221
/// Direct or use GOT indirect to reference external data symbols
22182222
pub direct_access_external_data: Option<bool>,
@@ -2608,6 +2612,9 @@ impl TargetOptions {
26082612
self.features.split(',').any(|f| f.strip_prefix('+').is_some_and(|f| f == search_feature))
26092613
}
26102614

2615+
/// We should try to minimize the number of negative features defined for any target
2616+
/// because they often interact very poorly with how `-Ctarget-cpu` works.
2617+
/// However, their mere existence is still a possibility, so!
26112618
pub(crate) fn has_neg_feature(&self, search_feature: &str) -> bool {
26122619
self.features.split(',').any(|f| f.strip_prefix('-').is_some_and(|f| f == search_feature))
26132620
}

0 commit comments

Comments
 (0)