diff options
author | Benjamin Coenen <[email protected]> | 2020-05-22 08:23:31 +0100 |
---|---|---|
committer | Benjamin Coenen <[email protected]> | 2020-05-22 08:23:31 +0100 |
commit | 43339058e32e8bb0d218390b9df5b5a68fe57ca7 (patch) | |
tree | 75ab113f7728d08a4093621b8a02b3005760843e /crates/ra_cfg/src/cfg_expr.rs | |
parent | a7c8aa7c60c05db66ba4e89ae9e05c82e62507a5 (diff) |
add support of feature flag for runnables #4464
Signed-off-by: Benjamin Coenen <[email protected]>
Diffstat (limited to 'crates/ra_cfg/src/cfg_expr.rs')
-rw-r--r-- | crates/ra_cfg/src/cfg_expr.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/crates/ra_cfg/src/cfg_expr.rs b/crates/ra_cfg/src/cfg_expr.rs index a4b201e0e..98f44f56d 100644 --- a/crates/ra_cfg/src/cfg_expr.rs +++ b/crates/ra_cfg/src/cfg_expr.rs | |||
@@ -35,14 +35,11 @@ impl CfgExpr { | |||
35 | } | 35 | } |
36 | 36 | ||
37 | /// Return minimal features needed | 37 | /// Return minimal features needed |
38 | pub fn minimal_features_needed(&self) -> Option<Vec<SmolStr>> { | 38 | pub fn minimal_features_needed(&self) -> Vec<SmolStr> { |
39 | let mut features = vec![]; | 39 | let mut features = vec![]; |
40 | self.collect_minimal_features_needed(&mut features); | 40 | self.collect_minimal_features_needed(&mut features); |
41 | if features.is_empty() { | 41 | |
42 | None | 42 | features |
43 | } else { | ||
44 | Some(features) | ||
45 | } | ||
46 | } | 43 | } |
47 | 44 | ||
48 | fn collect_minimal_features_needed(&self, features: &mut Vec<SmolStr>) { | 45 | fn collect_minimal_features_needed(&self, features: &mut Vec<SmolStr>) { |
@@ -169,14 +166,14 @@ mod tests { | |||
169 | let (subtree, _) = get_token_tree_generated(r#"#![cfg(feature = "baz")]"#); | 166 | let (subtree, _) = get_token_tree_generated(r#"#![cfg(feature = "baz")]"#); |
170 | let cfg_expr = parse_cfg(&subtree); | 167 | let cfg_expr = parse_cfg(&subtree); |
171 | 168 | ||
172 | assert_eq!(cfg_expr.minimal_features_needed().unwrap(), vec![SmolStr::new("baz")]); | 169 | assert_eq!(cfg_expr.minimal_features_needed(), vec![SmolStr::new("baz")]); |
173 | 170 | ||
174 | let (subtree, _) = | 171 | let (subtree, _) = |
175 | get_token_tree_generated(r#"#![cfg(all(feature = "baz", feature = "foo"))]"#); | 172 | get_token_tree_generated(r#"#![cfg(all(feature = "baz", feature = "foo"))]"#); |
176 | let cfg_expr = parse_cfg(&subtree); | 173 | let cfg_expr = parse_cfg(&subtree); |
177 | 174 | ||
178 | assert_eq!( | 175 | assert_eq!( |
179 | cfg_expr.minimal_features_needed().unwrap(), | 176 | cfg_expr.minimal_features_needed(), |
180 | vec![SmolStr::new("baz"), SmolStr::new("foo")] | 177 | vec![SmolStr::new("baz"), SmolStr::new("foo")] |
181 | ); | 178 | ); |
182 | 179 | ||
@@ -184,11 +181,11 @@ mod tests { | |||
184 | get_token_tree_generated(r#"#![cfg(any(feature = "baz", feature = "foo", unix))]"#); | 181 | get_token_tree_generated(r#"#![cfg(any(feature = "baz", feature = "foo", unix))]"#); |
185 | let cfg_expr = parse_cfg(&subtree); | 182 | let cfg_expr = parse_cfg(&subtree); |
186 | 183 | ||
187 | assert_eq!(cfg_expr.minimal_features_needed().unwrap(), vec![SmolStr::new("baz")]); | 184 | assert_eq!(cfg_expr.minimal_features_needed(), vec![SmolStr::new("baz")]); |
188 | 185 | ||
189 | let (subtree, _) = get_token_tree_generated(r#"#![cfg(foo)]"#); | 186 | let (subtree, _) = get_token_tree_generated(r#"#![cfg(foo)]"#); |
190 | let cfg_expr = parse_cfg(&subtree); | 187 | let cfg_expr = parse_cfg(&subtree); |
191 | 188 | ||
192 | assert!(cfg_expr.minimal_features_needed().is_none()); | 189 | assert!(cfg_expr.minimal_features_needed().is_empty()); |
193 | } | 190 | } |
194 | } | 191 | } |