aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model/src')
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs4
-rw-r--r--crates/ra_project_model/src/lib.rs69
2 files changed, 41 insertions, 32 deletions
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs
index 22d226a74..4fea459d5 100644
--- a/crates/ra_project_model/src/cargo_workspace.rs
+++ b/crates/ra_project_model/src/cargo_workspace.rs
@@ -164,7 +164,7 @@ impl CargoWorkspace {
164 // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures` 164 // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures`
165 // https://github.com/oli-obk/cargo_metadata/issues/79 165 // https://github.com/oli-obk/cargo_metadata/issues/79
166 meta.features(CargoOpt::NoDefaultFeatures); 166 meta.features(CargoOpt::NoDefaultFeatures);
167 } else if cargo_features.features.len() > 0 { 167 } else if !cargo_features.features.is_empty() {
168 meta.features(CargoOpt::SomeFeatures(cargo_features.features.clone())); 168 meta.features(CargoOpt::SomeFeatures(cargo_features.features.clone()));
169 } 169 }
170 if let Some(parent) = cargo_toml.parent() { 170 if let Some(parent) = cargo_toml.parent() {
@@ -197,7 +197,7 @@ impl CargoWorkspace {
197 let pkg_data = &mut packages[pkg]; 197 let pkg_data = &mut packages[pkg];
198 pkg_by_id.insert(id, pkg); 198 pkg_by_id.insert(id, pkg);
199 for meta_tgt in meta_pkg.targets { 199 for meta_tgt in meta_pkg.targets {
200 let is_proc_macro = meta_tgt.kind.as_slice() == &["proc-macro"]; 200 let is_proc_macro = meta_tgt.kind.as_slice() == ["proc-macro"];
201 let tgt = targets.alloc(TargetData { 201 let tgt = targets.alloc(TargetData {
202 pkg, 202 pkg,
203 name: meta_tgt.name, 203 name: meta_tgt.name,
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 250255813..e35f7fbbc 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -197,8 +197,9 @@ impl ProjectWorkspace {
197 if let (Some(&from), Some(&to)) = 197 if let (Some(&from), Some(&to)) =
198 (crates.get(&from_crate_id), crates.get(&to_crate_id)) 198 (crates.get(&from_crate_id), crates.get(&to_crate_id))
199 { 199 {
200 if let Err(_) = 200 if crate_graph
201 crate_graph.add_dep(from, CrateName::new(&dep.name).unwrap(), to) 201 .add_dep(from, CrateName::new(&dep.name).unwrap(), to)
202 .is_err()
202 { 203 {
203 log::error!( 204 log::error!(
204 "cyclic dependency {:?} -> {:?}", 205 "cyclic dependency {:?} -> {:?}",
@@ -237,8 +238,7 @@ impl ProjectWorkspace {
237 if let (Some(&from), Some(&to)) = 238 if let (Some(&from), Some(&to)) =
238 (sysroot_crates.get(&from), sysroot_crates.get(&to)) 239 (sysroot_crates.get(&from), sysroot_crates.get(&to))
239 { 240 {
240 if let Err(_) = 241 if crate_graph.add_dep(from, CrateName::new(name).unwrap(), to).is_err()
241 crate_graph.add_dep(from, CrateName::new(name).unwrap(), to)
242 { 242 {
243 log::error!("cyclic dependency between sysroot crates") 243 log::error!("cyclic dependency between sysroot crates")
244 } 244 }
@@ -279,11 +279,14 @@ impl ProjectWorkspace {
279 } 279 }
280 if tgt.is_proc_macro(&cargo) { 280 if tgt.is_proc_macro(&cargo) {
281 if let Some(proc_macro) = libproc_macro { 281 if let Some(proc_macro) = libproc_macro {
282 if let Err(_) = crate_graph.add_dep( 282 if crate_graph
283 crate_id, 283 .add_dep(
284 CrateName::new("proc_macro").unwrap(), 284 crate_id,
285 proc_macro, 285 CrateName::new("proc_macro").unwrap(),
286 ) { 286 proc_macro,
287 )
288 .is_err()
289 {
287 log::error!( 290 log::error!(
288 "cyclic dependency on proc_macro for {}", 291 "cyclic dependency on proc_macro for {}",
289 pkg.name(&cargo) 292 pkg.name(&cargo)
@@ -299,15 +302,19 @@ impl ProjectWorkspace {
299 // Set deps to the core, std and to the lib target of the current package 302 // Set deps to the core, std and to the lib target of the current package
300 for &from in pkg_crates.get(&pkg).into_iter().flatten() { 303 for &from in pkg_crates.get(&pkg).into_iter().flatten() {
301 if let Some(to) = lib_tgt { 304 if let Some(to) = lib_tgt {
302 if to != from { 305 if to != from
303 if let Err(_) = crate_graph.add_dep( 306 && crate_graph
304 from, 307 .add_dep(
305 // For root projects with dashes in their name, 308 from,
306 // cargo metadata does not do any normalization, 309 // For root projects with dashes in their name,
307 // so we do it ourselves currently 310 // cargo metadata does not do any normalization,
308 CrateName::normalize_dashes(pkg.name(&cargo)), 311 // so we do it ourselves currently
309 to, 312 CrateName::normalize_dashes(pkg.name(&cargo)),
310 ) { 313 to,
314 )
315 .is_err()
316 {
317 {
311 log::error!( 318 log::error!(
312 "cyclic dependency between targets of {}", 319 "cyclic dependency between targets of {}",
313 pkg.name(&cargo) 320 pkg.name(&cargo)
@@ -318,22 +325,25 @@ impl ProjectWorkspace {
318 // core is added as a dependency before std in order to 325 // core is added as a dependency before std in order to
319 // mimic rustcs dependency order 326 // mimic rustcs dependency order
320 if let Some(core) = libcore { 327 if let Some(core) = libcore {
321 if let Err(_) = 328 if crate_graph
322 crate_graph.add_dep(from, CrateName::new("core").unwrap(), core) 329 .add_dep(from, CrateName::new("core").unwrap(), core)
330 .is_err()
323 { 331 {
324 log::error!("cyclic dependency on core for {}", pkg.name(&cargo)) 332 log::error!("cyclic dependency on core for {}", pkg.name(&cargo))
325 } 333 }
326 } 334 }
327 if let Some(alloc) = liballoc { 335 if let Some(alloc) = liballoc {
328 if let Err(_) = 336 if crate_graph
329 crate_graph.add_dep(from, CrateName::new("alloc").unwrap(), alloc) 337 .add_dep(from, CrateName::new("alloc").unwrap(), alloc)
338 .is_err()
330 { 339 {
331 log::error!("cyclic dependency on alloc for {}", pkg.name(&cargo)) 340 log::error!("cyclic dependency on alloc for {}", pkg.name(&cargo))
332 } 341 }
333 } 342 }
334 if let Some(std) = libstd { 343 if let Some(std) = libstd {
335 if let Err(_) = 344 if crate_graph
336 crate_graph.add_dep(from, CrateName::new("std").unwrap(), std) 345 .add_dep(from, CrateName::new("std").unwrap(), std)
346 .is_err()
337 { 347 {
338 log::error!("cyclic dependency on std for {}", pkg.name(&cargo)) 348 log::error!("cyclic dependency on std for {}", pkg.name(&cargo))
339 } 349 }
@@ -347,11 +357,10 @@ impl ProjectWorkspace {
347 for dep in pkg.dependencies(&cargo) { 357 for dep in pkg.dependencies(&cargo) {
348 if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) { 358 if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) {
349 for &from in pkg_crates.get(&pkg).into_iter().flatten() { 359 for &from in pkg_crates.get(&pkg).into_iter().flatten() {
350 if let Err(_) = crate_graph.add_dep( 360 if crate_graph
351 from, 361 .add_dep(from, CrateName::new(&dep.name).unwrap(), to)
352 CrateName::new(&dep.name).unwrap(), 362 .is_err()
353 to, 363 {
354 ) {
355 log::error!( 364 log::error!(
356 "cyclic dependency {} -> {}", 365 "cyclic dependency {} -> {}",
357 pkg.name(&cargo), 366 pkg.name(&cargo),
@@ -409,7 +418,7 @@ fn find_cargo_toml(path: &Path) -> Result<PathBuf> {
409 } 418 }
410 curr = path.parent(); 419 curr = path.parent();
411 } 420 }
412 Err(CargoTomlNotFoundError(path.to_path_buf()))? 421 Err(CargoTomlNotFoundError(path.to_path_buf()).into())
413} 422}
414 423
415pub fn get_rustc_cfg_options() -> CfgOptions { 424pub fn get_rustc_cfg_options() -> CfgOptions {