Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

target check_consistency: ensure target feature string makes some basic sense #133410

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions compiler/rustc_target/src/spec/tests/tests_impl.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down
Loading