Skip to content

Commit

Permalink
Auto merge of #13775 - epage:incomplete-dep, r=weihanglo
Browse files Browse the repository at this point in the history
fix(toml)!: Disallow source-less dependencies

### What does this PR try to resolve?

This is part of #13629 addressing “dependency without path, version, git, workspace specified”.

This turns deps like
```toml
foo = { optional = true }
```
from `version="*"` deps with a warning into errors. This breaking change was deemed acceptable because this behavior has been considered a bug from the beginning.
We have gotten little to no feedback about people wanting this behavior.

This improves our forwards-compatibility story as we can add new dependency sources and they won't be considered a wildcard registry dependency on older cargo.

### How should we test and review this PR?

I removed the `cargo_add` test because it is redundant.

We no longer get the “unused key” warnings because those warnings get deferred to after this error gets reported.

### Additional information
  • Loading branch information
bors committed Apr 18, 2024
2 parents 2956296 + cf23e4b commit 7e9c2ef
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 103 deletions.
9 changes: 3 additions & 6 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1672,14 +1672,11 @@ fn detailed_dep_to_dependency<P: ResolveToPath + Clone>(
kind: Option<DepKind>,
) -> CargoResult<Dependency> {
if orig.version.is_none() && orig.path.is_none() && orig.git.is_none() {
let msg = format!(
"dependency ({}) specified without \
anyhow::bail!(
"dependency ({name_in_toml}) specified without \
providing a local path, Git repository, version, or \
workspace dependency to use. This will be considered an \
error in future versions",
name_in_toml
workspace dependency to use"
);
manifest_ctx.warnings.push(msg);
}

if let Some(version) = &orig.version {
Expand Down
9 changes: 6 additions & 3 deletions tests/testsuite/bad_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,13 @@ fn empty_dependencies() {
Package::new("bar", "0.0.1").publish();

p.cargo("check")
.with_stderr_contains(
.with_status(101)
.with_stderr(
"\
warning: dependency (bar) specified without providing a local path, Git repository, version, \
or workspace dependency to use. This will be considered an error in future versions
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
Caused by:
dependency (bar) specified without providing a local path, Git repository, version, or workspace dependency to use
",
)
.run();
Expand Down
9 changes: 0 additions & 9 deletions tests/testsuite/cargo_add/empty_dep_table/in/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion tests/testsuite/cargo_add/empty_dep_table/in/src/lib.rs

This file was deleted.

32 changes: 0 additions & 32 deletions tests/testsuite/cargo_add/empty_dep_table/mod.rs

This file was deleted.

9 changes: 0 additions & 9 deletions tests/testsuite/cargo_add/empty_dep_table/out/Cargo.toml

This file was deleted.

27 changes: 0 additions & 27 deletions tests/testsuite/cargo_add/empty_dep_table/stderr.term.svg

This file was deleted.

1 change: 0 additions & 1 deletion tests/testsuite/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod dev_build_conflict;
mod dev_prefer_existing_version;
mod dry_run;
mod empty_dep_name;
mod empty_dep_table;
mod features;
mod features_activated_over_limit;
mod features_deactivated_over_limit;
Expand Down
21 changes: 6 additions & 15 deletions tests/testsuite/inheritable_workspace_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1300,14 +1300,10 @@ fn error_workspace_dependency_looked_for_workspace_itself() {
.with_status(101)
.with_stderr(
"\
[WARNING] [CWD]/Cargo.toml: unused manifest key: workspace.dependencies.dep.workspace
[WARNING] [CWD]/Cargo.toml: dependency (dep) specified without providing a local path, Git repository, version, \
or workspace dependency to use. \
This will be considered an error in future versions
[UPDATING] `dummy-registry` index
[ERROR] no matching package named `dep` found
location searched: registry `crates-io`
required by package `bar v1.2.3 ([CWD])`
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
Caused by:
dependency (dep) specified without providing a local path, Git repository, version, or workspace dependency to use
",
)
.run();
Expand Down Expand Up @@ -1627,15 +1623,10 @@ fn cannot_inherit_in_patch() {
.with_status(101)
.with_stderr(
"\
[WARNING] [CWD]/Cargo.toml: unused manifest key: patch.crates-io.bar.workspace
[WARNING] [CWD]/Cargo.toml: dependency (bar) specified without providing a local path, Git repository, version, \
or workspace dependency to use. \
This will be considered an error in future versions
[UPDATING] `dummy-registry` index
[ERROR] failed to resolve patches for `https://github.com/rust-lang/crates.io-index`
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
Caused by:
patch for `bar` in `https://github.com/rust-lang/crates.io-index` points to the same source, but patches must point to different sources
dependency (bar) specified without providing a local path, Git repository, version, or workspace dependency to use
",
)
.run();
Expand Down

0 comments on commit 7e9c2ef

Please sign in to comment.