Filter out unused cargo features from config

This commit is contained in:
Lukas Wirth 2023-05-26 21:52:39 +02:00
parent ee8c18cb6e
commit 35b208aaa7
6 changed files with 50 additions and 12 deletions

View file

@ -10,7 +10,7 @@ use base_db::Edition;
use cargo_metadata::{CargoOpt, MetadataCommand};
use la_arena::{Arena, Idx};
use paths::{AbsPath, AbsPathBuf};
use rustc_hash::FxHashMap;
use rustc_hash::{FxHashMap, FxHashSet};
use serde::Deserialize;
use serde_json::from_value;
@ -491,6 +491,21 @@ impl CargoWorkspace {
None
}
/// Returns the union of the features of all member crates in this workspace.
pub fn workspace_features(&self) -> FxHashSet<String> {
self.packages()
.filter_map(|package| {
let package = &self[package];
if package.is_member {
Some(package.features.keys().cloned())
} else {
None
}
})
.flatten()
.collect()
}
fn is_unique(&self, name: &str) -> bool {
self.packages.iter().filter(|(_, v)| v.name == name).count() == 1
}