From dcd0c49e14ac265a9ff4ae90d18c77cc53ade583 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Mon, 9 Oct 2023 17:45:29 +0200 Subject: [PATCH] Prevent errors if `workspace` is not in the manifest. Signed-off-by: David Calavera --- src/cargo/ops/cargo_new.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 4cdd74d5ee3e..b78ba243e3eb 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -1022,7 +1022,7 @@ fn update_manifest_with_new_member( } } } - } else { + } else if workspace_document.contains_key("workspace") { let ws = workspace_document["workspace"] .as_table_mut() .with_context(|| format!("[workspace] is not a table"))?; @@ -1050,6 +1050,11 @@ fn update_manifest_with_new_member( } ws.insert("members", toml_edit::value(array)); + } else { + let mut array = Array::new(); + array.push(relpath); + array.decor_mut().set_suffix("\n"); + workspace_document["workspace"]["members"] = toml_edit::value(array); } paths::write(&root_manifest_path, workspace_document.to_string())