Skip to content

Commit f5c1f7f

Browse files
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 b0ed5ac + 5d42f64 commit f5c1f7f

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.
@@ -170,6 +172,27 @@ impl Target {
170172
}
171173
_ => {}
172174
}
175+
176+
// Check that the given target-features string makes some basic sense.
177+
if !self.features.is_empty() {
178+
let mut features_enabled = FxHashSet::default();
179+
let mut features_disabled = FxHashSet::default();
180+
for feat in self.features.split(',') {
181+
if let Some(feat) = feat.strip_prefix("+") {
182+
features_enabled.insert(feat);
183+
if features_disabled.contains(feat) {
184+
panic!("target feature `{feat}` is both enabled and disabled");
185+
}
186+
} else if let Some(feat) = feat.strip_prefix("-") {
187+
features_disabled.insert(feat);
188+
if features_enabled.contains(feat) {
189+
panic!("target feature `{feat}` is both enabled and disabled");
190+
}
191+
} else {
192+
panic!("target feature `{feat}` is invalid, must start with `+` or `-`");
193+
}
194+
}
195+
}
173196
}
174197

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

0 commit comments

Comments
 (0)