Skip to content

Commit 8818c95

Browse files
committed
Disallow enabling features without their implied features
1 parent 0b98a0c commit 8818c95

File tree

5 files changed

+11
-23
lines changed

5 files changed

+11
-23
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub fn check_tied_features(
277277
/// Used to generate cfg variables and apply features
278278
/// Must express features in the way Rust understands them
279279
pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
280-
let mut features = FxHashSet::default();
280+
let mut features = vec![];
281281

282282
// Add base features for the target
283283
let target_machine = create_informational_target_machine(sess, true);
@@ -313,7 +313,9 @@ pub fn target_features(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
313313
if enabled {
314314
features.extend(sess.target.implied_target_features(std::iter::once(feature)));
315315
} else {
316-
features.remove(&feature);
316+
features.retain(|f| {
317+
!sess.target.implied_target_features(std::iter::once(*f)).contains(&feature)
318+
});
317319
}
318320
}
319321

compiler/rustc_codegen_ssa/src/target_features.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_ast::ast;
22
use rustc_attr::InstructionSetAttr;
33
use rustc_data_structures::fx::FxIndexSet;
4-
use rustc_data_structures::unord::{ExtendUnord, UnordMap, UnordSet};
4+
use rustc_data_structures::unord::{UnordMap, UnordSet};
55
use rustc_errors::Applicability;
66
use rustc_hir::def::DefKind;
77
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
@@ -108,8 +108,7 @@ pub fn from_target_feature(
108108
// Add implied features
109109
let mut implied_target_features = UnordSet::new();
110110
for feature in added_target_features.iter() {
111-
implied_target_features
112-
.extend_unord(tcx.implied_target_features(*feature).clone().into_items());
111+
implied_target_features.extend(tcx.implied_target_features(*feature).clone());
113112
}
114113
for feature in added_target_features.iter() {
115114
implied_target_features.remove(feature);
@@ -179,7 +178,8 @@ pub(crate) fn provide(providers: &mut Providers) {
179178
}
180179
},
181180
implied_target_features: |tcx, feature| {
182-
tcx.sess.target.implied_target_features(std::iter::once(feature)).into()
181+
UnordSet::from(tcx.sess.target.implied_target_features(std::iter::once(feature)))
182+
.into_sorted_stable_ord()
183183
},
184184
asm_target_features,
185185
..*providers

compiler/rustc_const_eval/src/interpret/call.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -319,18 +319,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
319319
.iter()
320320
.any(|feature| !self.tcx.sess.target_features.contains(&feature.name))
321321
{
322-
// Don't include implicit features in the error, unless only implicit features are
323-
// missing. This should be rare, because it can only happen when an implicit feature
324-
// is disabled, e.g. `+avx2,-avx`
325-
let missing_explicit_features = attrs.target_features.iter().any(|feature| {
326-
!feature.implied && !self.tcx.sess.target_features.contains(&feature.name)
327-
});
328322
throw_ub_custom!(
329323
fluent::const_eval_unavailable_target_features_for_fn,
330324
unavailable_feats = attrs
331325
.target_features
332326
.iter()
333-
.filter(|&feature| !(missing_explicit_features && feature.implied)
327+
.filter(|&feature| !feature.implied
334328
&& !self.tcx.sess.target_features.contains(&feature.name))
335329
.fold(String::new(), |mut s, feature| {
336330
if !s.is_empty() {

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,7 @@ rustc_queries! {
21832183
desc { "looking up supported target features" }
21842184
}
21852185

2186-
query implied_target_features(feature: Symbol) -> &'tcx UnordSet<Symbol> {
2186+
query implied_target_features(feature: Symbol) -> &'tcx Vec<Symbol> {
21872187
arena_cache
21882188
eval_always
21892189
desc { "looking up implied target features" }

compiler/rustc_mir_build/src/check_unsafety.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -447,19 +447,11 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
447447
self.body_target_features.iter().any(|f| f.name == feature.name)
448448
})
449449
{
450-
// Don't include implicit features in the error, unless only implicit
451-
// features are missing.
452-
let missing_explicit_features = callee_features.iter().any(|feature| {
453-
!feature.implied
454-
&& !self.body_target_features.iter().any(|body_feature| {
455-
!feature.implied && body_feature.name == feature.name
456-
})
457-
});
458450
let missing: Vec<_> = callee_features
459451
.iter()
460452
.copied()
461453
.filter(|feature| {
462-
!(missing_explicit_features && feature.implied)
454+
!feature.implied
463455
&& !self
464456
.body_target_features
465457
.iter()

0 commit comments

Comments
 (0)