diff options
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 640a5ebd3..a4d117e34 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -134,13 +134,16 @@ impl ProjectWorkspace { | |||
134 | json_project::Edition::Edition2015 => Edition::Edition2015, | 134 | json_project::Edition::Edition2015 => Edition::Edition2015, |
135 | json_project::Edition::Edition2018 => Edition::Edition2018, | 135 | json_project::Edition::Edition2018 => Edition::Edition2018, |
136 | }; | 136 | }; |
137 | let mut cfg_options = default_cfg_options.clone(); | 137 | let cfg_options = { |
138 | for name in &krate.atom_cfgs { | 138 | let mut opts = default_cfg_options.clone(); |
139 | cfg_options = cfg_options.atom(name.into()); | 139 | for name in &krate.atom_cfgs { |
140 | } | 140 | opts.insert_atom(name.into()); |
141 | for (key, value) in &krate.key_value_cfgs { | 141 | } |
142 | cfg_options = cfg_options.key_value(key.into(), value.into()); | 142 | for (key, value) in &krate.key_value_cfgs { |
143 | } | 143 | opts.insert_key_value(key.into(), value.into()); |
144 | } | ||
145 | opts | ||
146 | }; | ||
144 | crates.insert( | 147 | crates.insert( |
145 | crate_id, | 148 | crate_id, |
146 | crate_graph.add_crate_root(file_id, edition, cfg_options), | 149 | crate_graph.add_crate_root(file_id, edition, cfg_options), |
@@ -171,7 +174,12 @@ impl ProjectWorkspace { | |||
171 | for krate in sysroot.crates() { | 174 | for krate in sysroot.crates() { |
172 | if let Some(file_id) = load(krate.root(&sysroot)) { | 175 | if let Some(file_id) = load(krate.root(&sysroot)) { |
173 | // Crates from sysroot have `cfg(test)` disabled | 176 | // Crates from sysroot have `cfg(test)` disabled |
174 | let cfg_options = default_cfg_options.clone().remove_atom(&"test".into()); | 177 | let cfg_options = { |
178 | let mut opts = default_cfg_options.clone(); | ||
179 | opts.remove_atom("test"); | ||
180 | opts | ||
181 | }; | ||
182 | |||
175 | let crate_id = | 183 | let crate_id = |
176 | crate_graph.add_crate_root(file_id, Edition::Edition2018, cfg_options); | 184 | crate_graph.add_crate_root(file_id, Edition::Edition2018, cfg_options); |
177 | sysroot_crates.insert(krate, crate_id); | 185 | sysroot_crates.insert(krate, crate_id); |
@@ -202,9 +210,11 @@ impl ProjectWorkspace { | |||
202 | let root = tgt.root(&cargo); | 210 | let root = tgt.root(&cargo); |
203 | if let Some(file_id) = load(root) { | 211 | if let Some(file_id) = load(root) { |
204 | let edition = pkg.edition(&cargo); | 212 | let edition = pkg.edition(&cargo); |
205 | let cfg_options = default_cfg_options | 213 | let cfg_options = { |
206 | .clone() | 214 | let mut opts = default_cfg_options.clone(); |
207 | .features(pkg.features(&cargo).iter().map(Into::into)); | 215 | opts.insert_features(pkg.features(&cargo).iter().map(Into::into)); |
216 | opts | ||
217 | }; | ||
208 | let crate_id = | 218 | let crate_id = |
209 | crate_graph.add_crate_root(file_id, edition, cfg_options); | 219 | crate_graph.add_crate_root(file_id, edition, cfg_options); |
210 | names.insert(crate_id, pkg.name(&cargo).to_string()); | 220 | names.insert(crate_id, pkg.name(&cargo).to_string()); |
@@ -321,11 +331,11 @@ pub fn get_rustc_cfg_options() -> CfgOptions { | |||
321 | Ok(rustc_cfgs) => { | 331 | Ok(rustc_cfgs) => { |
322 | for line in rustc_cfgs.lines() { | 332 | for line in rustc_cfgs.lines() { |
323 | match line.find('=') { | 333 | match line.find('=') { |
324 | None => cfg_options = cfg_options.atom(line.into()), | 334 | None => cfg_options.insert_atom(line.into()), |
325 | Some(pos) => { | 335 | Some(pos) => { |
326 | let key = &line[..pos]; | 336 | let key = &line[..pos]; |
327 | let value = line[pos + 1..].trim_matches('"'); | 337 | let value = line[pos + 1..].trim_matches('"'); |
328 | cfg_options = cfg_options.key_value(key.into(), value.into()); | 338 | cfg_options.insert_key_value(key.into(), value.into()); |
329 | } | 339 | } |
330 | } | 340 | } |
331 | } | 341 | } |