diff --git a/crates/project_model/src/cargo_workspace.rs b/crates/project_model/src/cargo_workspace.rs index c0ed37fc1287..a09e1a9ffb91 100644 --- a/crates/project_model/src/cargo_workspace.rs +++ b/crates/project_model/src/cargo_workspace.rs @@ -99,8 +99,10 @@ pub struct PackageData { pub dependencies: Vec, /// Rust edition for this package pub edition: Edition, - /// List of features to activate - pub features: Vec, + /// Features provided by the crate, mapped to the features required by that feature. + pub features: FxHashMap>, + /// List of features enabled on this package + pub active_features: Vec, /// List of config flags defined by this package's build script pub cfgs: Vec, /// List of cargo-related environment variables with their value @@ -281,7 +283,8 @@ pub fn from_cargo_metadata( is_member, edition, dependencies: Vec::new(), - features: Vec::new(), + features: meta_pkg.features.into_iter().collect(), + active_features: Vec::new(), cfgs: cfgs.get(&id).cloned().unwrap_or_default(), envs: envs.get(&id).cloned().unwrap_or_default(), out_dir: out_dir_by_id.get(&id).cloned(), @@ -328,7 +331,7 @@ pub fn from_cargo_metadata( let dep = PackageDependency { name: dep_node.name, pkg }; packages[source].dependencies.push(dep); } - packages[source].features.extend(node.features); + packages[source].active_features.extend(node.features); } let workspace_root = AbsPathBuf::assert(meta.workspace_root); diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs index 8e0481ae9745..073c48af760f 100644 --- a/crates/project_model/src/workspace.rs +++ b/crates/project_model/src/workspace.rs @@ -481,7 +481,7 @@ fn add_target_crate_root( let edition = pkg.edition; let cfg_options = { let mut opts = cfg_options.clone(); - for feature in pkg.features.iter() { + for feature in pkg.active_features.iter() { opts.insert_key_value("feature".into(), feature.into()); } opts.extend(pkg.cfgs.iter().cloned());