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())