]> git.lizzy.rs Git - rust.git/commitdiff
Move feature desugaring to the right abstraction layer
authorAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 8 May 2020 00:56:53 +0000 (02:56 +0200)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Fri, 8 May 2020 00:56:53 +0000 (02:56 +0200)
crates/ra_cfg/src/lib.rs
crates/ra_project_model/src/lib.rs

index 697a0458147d76fb376fc73f99f242f7d0a474a2..57feabcb27cb57e981aa2898113716ff94cdb971 100644 (file)
@@ -2,8 +2,6 @@
 
 mod cfg_expr;
 
-use std::iter::IntoIterator;
-
 use ra_syntax::SmolStr;
 use rustc_hash::FxHashSet;
 
@@ -48,18 +46,4 @@ pub fn remove_atom(&mut self, name: &str) {
     pub fn insert_key_value(&mut self, key: SmolStr, value: SmolStr) {
         self.key_values.insert((key, value));
     }
-
-    /// Shortcut to set features
-    pub fn insert_features(&mut self, iter: impl IntoIterator<Item = SmolStr>) {
-        iter.into_iter().for_each(|feat| self.insert_key_value("feature".into(), feat));
-    }
-
-    /// Shortcut to set cfgs
-    pub fn insert_cfgs(&mut self, iter: impl IntoIterator<Item = SmolStr>) {
-        iter.into_iter().for_each(|cfg| match cfg.find('=') {
-            Some(split) => self
-                .insert_key_value(cfg[0..split].into(), cfg[split + 1..].trim_matches('"').into()),
-            None => self.insert_atom(cfg),
-        });
-    }
 }
index 8703429d4457cb6ae6f2265a29e81e3e0721979f..c226ffa57f10baf8bd1f7d5f118cdaecd1329730 100644 (file)
@@ -398,8 +398,18 @@ pub fn to_crate_graph(
                             let edition = cargo[pkg].edition;
                             let cfg_options = {
                                 let mut opts = default_cfg_options.clone();
-                                opts.insert_features(cargo[pkg].features.iter().map(Into::into));
-                                opts.insert_cfgs(cargo[pkg].cfgs.iter().map(Into::into));
+                                for feature in cargo[pkg].features.iter() {
+                                    opts.insert_key_value("feature".into(), feature.into());
+                                }
+                                for cfg in cargo[pkg].cfgs.iter() {
+                                    match cfg.find('=') {
+                                        Some(split) => opts.insert_key_value(
+                                            cfg[..split].into(),
+                                            cfg[split + 1..].trim_matches('"').into(),
+                                        ),
+                                        None => opts.insert_atom(cfg.into()),
+                                    };
+                                }
                                 opts
                             };
                             let mut env = Env::default();