diff options
Diffstat (limited to 'crates/ra_cfg')
-rw-r--r-- | crates/ra_cfg/src/cfg_expr.rs | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/crates/ra_cfg/src/cfg_expr.rs b/crates/ra_cfg/src/cfg_expr.rs index 98f44f56d..85b100c6a 100644 --- a/crates/ra_cfg/src/cfg_expr.rs +++ b/crates/ra_cfg/src/cfg_expr.rs | |||
@@ -33,33 +33,6 @@ impl CfgExpr { | |||
33 | CfgExpr::Not(pred) => pred.fold(query).map(|s| !s), | 33 | CfgExpr::Not(pred) => pred.fold(query).map(|s| !s), |
34 | } | 34 | } |
35 | } | 35 | } |
36 | |||
37 | /// Return minimal features needed | ||
38 | pub fn minimal_features_needed(&self) -> Vec<SmolStr> { | ||
39 | let mut features = vec![]; | ||
40 | self.collect_minimal_features_needed(&mut features); | ||
41 | |||
42 | features | ||
43 | } | ||
44 | |||
45 | fn collect_minimal_features_needed(&self, features: &mut Vec<SmolStr>) { | ||
46 | match self { | ||
47 | CfgExpr::KeyValue { key, value } if key == "feature" => features.push(value.clone()), | ||
48 | CfgExpr::All(preds) => { | ||
49 | preds.iter().for_each(|cfg| cfg.collect_minimal_features_needed(features)); | ||
50 | } | ||
51 | CfgExpr::Any(preds) => { | ||
52 | for cfg in preds { | ||
53 | let len_features = features.len(); | ||
54 | cfg.collect_minimal_features_needed(features); | ||
55 | if len_features != features.len() { | ||
56 | break; | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | _ => {} | ||
61 | } | ||
62 | } | ||
63 | } | 36 | } |
64 | 37 | ||
65 | pub fn parse_cfg(tt: &Subtree) -> CfgExpr { | 38 | pub fn parse_cfg(tt: &Subtree) -> CfgExpr { |
@@ -160,32 +133,4 @@ mod tests { | |||
160 | ]), | 133 | ]), |
161 | ); | 134 | ); |
162 | } | 135 | } |
163 | |||
164 | #[test] | ||
165 | fn test_cfg_expr_minimal_features_needed() { | ||
166 | let (subtree, _) = get_token_tree_generated(r#"#![cfg(feature = "baz")]"#); | ||
167 | let cfg_expr = parse_cfg(&subtree); | ||
168 | |||
169 | assert_eq!(cfg_expr.minimal_features_needed(), vec![SmolStr::new("baz")]); | ||
170 | |||
171 | let (subtree, _) = | ||
172 | get_token_tree_generated(r#"#![cfg(all(feature = "baz", feature = "foo"))]"#); | ||
173 | let cfg_expr = parse_cfg(&subtree); | ||
174 | |||
175 | assert_eq!( | ||
176 | cfg_expr.minimal_features_needed(), | ||
177 | vec![SmolStr::new("baz"), SmolStr::new("foo")] | ||
178 | ); | ||
179 | |||
180 | let (subtree, _) = | ||
181 | get_token_tree_generated(r#"#![cfg(any(feature = "baz", feature = "foo", unix))]"#); | ||
182 | let cfg_expr = parse_cfg(&subtree); | ||
183 | |||
184 | assert_eq!(cfg_expr.minimal_features_needed(), vec![SmolStr::new("baz")]); | ||
185 | |||
186 | let (subtree, _) = get_token_tree_generated(r#"#![cfg(foo)]"#); | ||
187 | let cfg_expr = parse_cfg(&subtree); | ||
188 | |||
189 | assert!(cfg_expr.minimal_features_needed().is_empty()); | ||
190 | } | ||
191 | } | 136 | } |