Skip to content

Commit 7e9c2ef

Browse files
committed
Auto merge of #13775 - epage:incomplete-dep, r=weihanglo
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
2 parents 2956296 + cf23e4b commit 7e9c2ef

File tree

9 files changed

+15
-103
lines changed

9 files changed

+15
-103
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,14 +1672,11 @@ fn detailed_dep_to_dependency<P: ResolveToPath + Clone>(
16721672
kind: Option<DepKind>,
16731673
) -> CargoResult<Dependency> {
16741674
if orig.version.is_none() && orig.path.is_none() && orig.git.is_none() {
1675-
let msg = format!(
1676-
"dependency ({}) specified without \
1675+
anyhow::bail!(
1676+
"dependency ({name_in_toml}) specified without \
16771677
providing a local path, Git repository, version, or \
1678-
workspace dependency to use. This will be considered an \
1679-
error in future versions",
1680-
name_in_toml
1678+
workspace dependency to use"
16811679
);
1682-
manifest_ctx.warnings.push(msg);
16831680
}
16841681

16851682
if let Some(version) = &orig.version {

tests/testsuite/bad_config.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,10 +792,13 @@ fn empty_dependencies() {
792792
Package::new("bar", "0.0.1").publish();
793793

794794
p.cargo("check")
795-
.with_stderr_contains(
795+
.with_status(101)
796+
.with_stderr(
796797
"\
797-
warning: dependency (bar) specified without providing a local path, Git repository, version, \
798-
or workspace dependency to use. This will be considered an error in future versions
798+
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
799+
800+
Caused by:
801+
dependency (bar) specified without providing a local path, Git repository, version, or workspace dependency to use
799802
",
800803
)
801804
.run();

tests/testsuite/cargo_add/empty_dep_table/in/Cargo.toml

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/testsuite/cargo_add/empty_dep_table/in/src/lib.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/testsuite/cargo_add/empty_dep_table/mod.rs

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/testsuite/cargo_add/empty_dep_table/out/Cargo.toml

Lines changed: 0 additions & 9 deletions
This file was deleted.

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

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/testsuite/cargo_add/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ mod dev_build_conflict;
2020
mod dev_prefer_existing_version;
2121
mod dry_run;
2222
mod empty_dep_name;
23-
mod empty_dep_table;
2423
mod features;
2524
mod features_activated_over_limit;
2625
mod features_deactivated_over_limit;

tests/testsuite/inheritable_workspace_fields.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,14 +1300,10 @@ fn error_workspace_dependency_looked_for_workspace_itself() {
13001300
.with_status(101)
13011301
.with_stderr(
13021302
"\
1303-
[WARNING] [CWD]/Cargo.toml: unused manifest key: workspace.dependencies.dep.workspace
1304-
[WARNING] [CWD]/Cargo.toml: dependency (dep) specified without providing a local path, Git repository, version, \
1305-
or workspace dependency to use. \
1306-
This will be considered an error in future versions
1307-
[UPDATING] `dummy-registry` index
1308-
[ERROR] no matching package named `dep` found
1309-
location searched: registry `crates-io`
1310-
required by package `bar v1.2.3 ([CWD])`
1303+
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
1304+
1305+
Caused by:
1306+
dependency (dep) specified without providing a local path, Git repository, version, or workspace dependency to use
13111307
",
13121308
)
13131309
.run();
@@ -1627,15 +1623,10 @@ fn cannot_inherit_in_patch() {
16271623
.with_status(101)
16281624
.with_stderr(
16291625
"\
1630-
[WARNING] [CWD]/Cargo.toml: unused manifest key: patch.crates-io.bar.workspace
1631-
[WARNING] [CWD]/Cargo.toml: dependency (bar) specified without providing a local path, Git repository, version, \
1632-
or workspace dependency to use. \
1633-
This will be considered an error in future versions
1634-
[UPDATING] `dummy-registry` index
1635-
[ERROR] failed to resolve patches for `https://github.com/rust-lang/crates.io-index`
1626+
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
16361627
16371628
Caused by:
1638-
patch for `bar` in `https://github.com/rust-lang/crates.io-index` points to the same source, but patches must point to different sources
1629+
dependency (bar) specified without providing a local path, Git repository, version, or workspace dependency to use
16391630
",
16401631
)
16411632
.run();

0 commit comments

Comments
 (0)