Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/cfg/src/lib.rs')
-rw-r--r--crates/cfg/src/lib.rs20
1 files changed, 12 insertions, 8 deletions
diff --git a/crates/cfg/src/lib.rs b/crates/cfg/src/lib.rs
index 6a6213a871..08545b6851 100644
--- a/crates/cfg/src/lib.rs
+++ b/crates/cfg/src/lib.rs
@@ -148,16 +148,20 @@ pub struct CfgDiff {
}
impl CfgDiff {
- /// Create a new CfgDiff. Will return None if the same item appears more than once in the set
- /// of both.
- pub fn new(enable: Vec<CfgAtom>, disable: Vec<CfgAtom>) -> Option<CfgDiff> {
- let mut occupied = FxHashSet::default();
- if enable.iter().chain(disable.iter()).any(|item| !occupied.insert(item)) {
- // was present
- return None;
+ /// Create a new CfgDiff.
+ pub fn new(mut enable: Vec<CfgAtom>, mut disable: Vec<CfgAtom>) -> CfgDiff {
+ enable.sort();
+ enable.dedup();
+ disable.sort();
+ disable.dedup();
+ for i in (0..enable.len()).rev() {
+ if let Some(j) = disable.iter().position(|atom| *atom == enable[i]) {
+ enable.remove(i);
+ disable.remove(j);
+ }
}
- Some(CfgDiff { enable, disable })
+ CfgDiff { enable, disable }
}
/// Returns the total number of atoms changed by this diff.