Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/project-model/src/workspace.rs')
-rw-r--r--crates/project-model/src/workspace.rs66
1 files changed, 37 insertions, 29 deletions
diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs
index 655da118bb..f031fef165 100644
--- a/crates/project-model/src/workspace.rs
+++ b/crates/project-model/src/workspace.rs
@@ -24,7 +24,7 @@ use crate::{
CargoConfig, CargoWorkspace, CfgOverrides, InvocationStrategy, ManifestPath, Package,
ProjectJson, ProjectManifest, RustSourceWorkspaceConfig, Sysroot, TargetData, TargetKind,
WorkspaceBuildScripts,
- build_dependencies::BuildScriptOutput,
+ build_dependencies::{BuildScriptOutput, ProcMacroDylibPath},
cargo_config_file,
cargo_workspace::{CargoMetadataConfig, DepKind, FetchMetadata, PackageData, RustLibSource},
env::{cargo_config_env, inject_cargo_env, inject_cargo_package_env, inject_rustc_tool_env},
@@ -424,12 +424,12 @@ impl ProjectWorkspace {
sysroot.set_workspace(loaded_sysroot);
}
- if !cargo.requires_rustc_private() {
- if let Err(e) = &mut rustc {
- // We don't need the rustc sources here,
- // so just discard the error.
- _ = e.take();
- }
+ if !cargo.requires_rustc_private()
+ && let Err(e) = &mut rustc
+ {
+ // We don't need the rustc sources here,
+ // so just discard the error.
+ _ = e.take();
}
Ok(ProjectWorkspace {
@@ -1163,17 +1163,15 @@ fn project_json_to_crate_graph(
crate = display_name.as_ref().map(|name| name.canonical_name().as_str()),
"added root to crate graph"
);
- if *is_proc_macro {
- if let Some(path) = proc_macro_dylib_path.clone() {
- let node = Ok((
- display_name
- .as_ref()
- .map(|it| it.canonical_name().as_str().to_owned())
- .unwrap_or_else(|| format!("crate{}", idx.0)),
- path,
- ));
- proc_macros.insert(crate_graph_crate_id, node);
- }
+ if *is_proc_macro && let Some(path) = proc_macro_dylib_path.clone() {
+ let node = Ok((
+ display_name
+ .as_ref()
+ .map(|it| it.canonical_name().as_str().to_owned())
+ .unwrap_or_else(|| format!("crate{}", idx.0)),
+ path,
+ ));
+ proc_macros.insert(crate_graph_crate_id, node);
}
(idx, crate_graph_crate_id)
},
@@ -1319,14 +1317,12 @@ fn cargo_to_crate_graph(
// Add dep edge of all targets to the package's lib target
if let Some((to, name)) = lib_tgt.clone() {
- if to != from && kind != TargetKind::BuildScript {
- // (build script can not depend on its library target)
-
- // For root projects with dashes in their name,
- // cargo metadata does not do any normalization,
- // so we do it ourselves currently
- let name = CrateName::normalize_dashes(&name);
- add_dep(crate_graph, from, name, to);
+ match to != from && kind != TargetKind::BuildScript {
+ true => {
+ let name = CrateName::normalize_dashes(&name);
+ add_dep(crate_graph, from, name, to);
+ }
+ false => (),
}
}
}
@@ -1638,9 +1634,21 @@ fn add_target_crate_root(
let proc_macro = match build_data {
Some((BuildScriptOutput { proc_macro_dylib_path, .. }, has_errors)) => {
match proc_macro_dylib_path {
- Some(path) => Ok((cargo_name.to_owned(), path.clone())),
- None if has_errors => Err(ProcMacroLoadingError::FailedToBuild),
- None => Err(ProcMacroLoadingError::MissingDylibPath),
+ ProcMacroDylibPath::Path(path) => Ok((cargo_name.to_owned(), path.clone())),
+ ProcMacroDylibPath::NotBuilt => Err(ProcMacroLoadingError::NotYetBuilt),
+ ProcMacroDylibPath::NotProcMacro | ProcMacroDylibPath::DylibNotFound(_)
+ if has_errors =>
+ {
+ Err(ProcMacroLoadingError::FailedToBuild)
+ }
+ ProcMacroDylibPath::NotProcMacro => {
+ Err(ProcMacroLoadingError::ExpectedProcMacroArtifact)
+ }
+ ProcMacroDylibPath::DylibNotFound(candidates) => {
+ Err(ProcMacroLoadingError::MissingDylibPath(
+ candidates.iter().map(ToString::to_string).collect(),
+ ))
+ }
}
}
None => Err(ProcMacroLoadingError::NotYetBuilt),