aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r--crates/ra_project_model/src/lib.rs44
1 files changed, 31 insertions, 13 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 640a5ebd3..8b8663a78 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());
@@ -310,6 +320,14 @@ fn find_cargo_toml(path: &Path) -> Result<PathBuf> {
310pub fn get_rustc_cfg_options() -> CfgOptions { 320pub fn get_rustc_cfg_options() -> CfgOptions {
311 let mut cfg_options = CfgOptions::default(); 321 let mut cfg_options = CfgOptions::default();
312 322
323 // Some nightly-only cfgs, which are required for stdlib
324 {
325 cfg_options.insert_atom("target_thread_local".into());
326 for &target_has_atomic in ["16", "32", "64", "8", "cas", "ptr"].iter() {
327 cfg_options.insert_key_value("target_has_atomic".into(), target_has_atomic.into())
328 }
329 }
330
313 match (|| -> Result<_> { 331 match (|| -> Result<_> {
314 // `cfg(test)` and `cfg(debug_assertion)` are handled outside, so we suppress them here. 332 // `cfg(test)` and `cfg(debug_assertion)` are handled outside, so we suppress them here.
315 let output = Command::new("rustc").args(&["--print", "cfg", "-O"]).output()?; 333 let output = Command::new("rustc").args(&["--print", "cfg", "-O"]).output()?;
@@ -321,11 +339,11 @@ pub fn get_rustc_cfg_options() -> CfgOptions {
321 Ok(rustc_cfgs) => { 339 Ok(rustc_cfgs) => {
322 for line in rustc_cfgs.lines() { 340 for line in rustc_cfgs.lines() {
323 match line.find('=') { 341 match line.find('=') {
324 None => cfg_options = cfg_options.atom(line.into()), 342 None => cfg_options.insert_atom(line.into()),
325 Some(pos) => { 343 Some(pos) => {
326 let key = &line[..pos]; 344 let key = &line[..pos];
327 let value = line[pos + 1..].trim_matches('"'); 345 let value = line[pos + 1..].trim_matches('"');
328 cfg_options = cfg_options.key_value(key.into(), value.into()); 346 cfg_options.insert_key_value(key.into(), value.into());
329 } 347 }
330 } 348 }
331 } 349 }