diff options
| author | Ralf Jung <post@ralfj.de> | 2024-11-24 09:11:11 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-11-24 09:55:07 +0100 |
| commit | 5d42f64ad2f39c1f65ff3fb5b2c73b52c81f8a87 (patch) | |
| tree | fbd74f98aa8ac2be33c8646eed03ff2f46018be9 | |
| parent | 4e4c20d2abe6a218991152b735800fbaf51aedd6 (diff) | |
| download | rust-5d42f64ad2f39c1f65ff3fb5b2c73b52c81f8a87.tar.gz rust-5d42f64ad2f39c1f65ff3fb5b2c73b52c81f8a87.zip | |
target check_consistency: ensure target feature string makes some basic sense
| -rw-r--r-- | compiler/rustc_target/src/spec/tests/tests_impl.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/compiler/rustc_target/src/spec/tests/tests_impl.rs b/compiler/rustc_target/src/spec/tests/tests_impl.rs index bd47d12ef9f..b0d3befae83 100644 --- a/compiler/rustc_target/src/spec/tests/tests_impl.rs +++ b/compiler/rustc_target/src/spec/tests/tests_impl.rs @@ -1,5 +1,7 @@ use std::assert_matches::assert_matches; +use rustc_data_structures::fx::FxHashSet; + use super::super::*; // Test target self-consistency and JSON encoding/decoding roundtrip. @@ -170,6 +172,27 @@ impl Target { } _ => {} } + + // Check that the given target-features string makes some basic sense. + if !self.features.is_empty() { + let mut features_enabled = FxHashSet::default(); + let mut features_disabled = FxHashSet::default(); + for feat in self.features.split(',') { + if let Some(feat) = feat.strip_prefix("+") { + features_enabled.insert(feat); + if features_disabled.contains(feat) { + panic!("target feature `{feat}` is both enabled and disabled"); + } + } else if let Some(feat) = feat.strip_prefix("-") { + features_disabled.insert(feat); + if features_enabled.contains(feat) { + panic!("target feature `{feat}` is both enabled and disabled"); + } + } else { + panic!("target feature `{feat}` is invalid, must start with `+` or `-`"); + } + } + } } // Add your target to the whitelist if it has `std` library |
