Skip to content

Commit e512c7b

Browse files
committed
fix(add): Report a missing source error for workspace dependencies
When you have ```toml [workspace.dependencies] apply.workspace = true ``` You have a source-less workspace dependency with an unused `workspace` field. In #13775, we removed support for source-less dependencies but missed this case. This mirrors the error message from `toml/mod.rs` that #13775 added. Other options I considered: - Making the presence of `workspace` an error in `cargo-util-schemas` - Validating `workspace.dependencies` in `toml/mod.rs`, even when its not inherited In both cases, they are behavior changes that and I wanted to keep the focus of this change small rather than get tied up in what behavior changes are safe or should be done with an Edition. The second option could still lead to this panic if we move some of that error reporting into later stages of Cargo. Fixes #1398
1 parent ac120d9 commit e512c7b

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/cargo/ops/cargo_add/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,11 @@ fn resolve_dependency(
516516
let query = dep.query(gctx)?;
517517
match query {
518518
MaybeWorkspace::Workspace(_) => {
519-
unreachable!("This should have been caught when parsing a workspace root")
519+
anyhow::bail!(
520+
"dependency ({}) specified without \
521+
providing a local path, Git repository, or version",
522+
dependency.toml_key()
523+
);
520524
}
521525
MaybeWorkspace::Other(query) => query,
522526
}

tests/testsuite/cargo_add/invalid_inherited_dependency/stderr.term.svg

Lines changed: 5 additions & 9 deletions
Loading

0 commit comments

Comments
 (0)