Skip to content

Commit 40e65a4

Browse files
authored
Unrolled build for rust-lang#133410
Rollup merge of rust-lang#133410 - RalfJung:target-feature-consistency, r=compiler-errors target check_consistency: ensure target feature string makes some basic sense
2 parents dff3e7c + 5d42f64 commit 40e65a4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

compiler/rustc_target/src/spec/tests/tests_impl.rs

+23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::assert_matches::assert_matches;
22

3+
use rustc_data_structures::fx::FxHashSet;
4+
35
use super::super::*;
46

57
// Test target self-consistency and JSON encoding/decoding roundtrip.
@@ -173,6 +175,27 @@ impl Target {
173175
}
174176
_ => {}
175177
}
178+
179+
// Check that the given target-features string makes some basic sense.
180+
if !self.features.is_empty() {
181+
let mut features_enabled = FxHashSet::default();
182+
let mut features_disabled = FxHashSet::default();
183+
for feat in self.features.split(',') {
184+
if let Some(feat) = feat.strip_prefix("+") {
185+
features_enabled.insert(feat);
186+
if features_disabled.contains(feat) {
187+
panic!("target feature `{feat}` is both enabled and disabled");
188+
}
189+
} else if let Some(feat) = feat.strip_prefix("-") {
190+
features_disabled.insert(feat);
191+
if features_enabled.contains(feat) {
192+
panic!("target feature `{feat}` is both enabled and disabled");
193+
}
194+
} else {
195+
panic!("target feature `{feat}` is invalid, must start with `+` or `-`");
196+
}
197+
}
198+
}
176199
}
177200

178201
// Add your target to the whitelist if it has `std` library

0 commit comments

Comments
 (0)