This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
compiler/rustc_target/src/spec/tests Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 11use std:: assert_matches:: assert_matches;
22
3+ use rustc_data_structures:: fx:: FxHashSet ;
4+
35use 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
You can’t perform that action at this time.
0 commit comments