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
This commit is contained in:
bors 2024-04-18 22:02:05 +00:00
commit 7e9c2ef30f
9 changed files with 15 additions and 103 deletions

View file

@ -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 {

View file

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

View file

@ -1,9 +0,0 @@
[workspace]
[package]
name = "cargo-list-test-fixture"
version = "0.0.0"
edition = "2015"
[dependencies]
your-face = { }

View file

@ -1,32 +0,0 @@
use cargo_test_support::compare::assert_ui;
use cargo_test_support::current_dir;
use cargo_test_support::file;
use cargo_test_support::prelude::*;
use cargo_test_support::str;
use cargo_test_support::Project;
#[cargo_test]
fn case() {
cargo_test_support::registry::init();
cargo_test_support::registry::Package::new("your-face", "99999.0.0+my-package")
.feature("nose", &[])
.feature("mouth", &[])
.feature("eyes", &[])
.feature("ears", &[])
.publish();
let project = Project::from_template(current_dir!().join("in"));
let project_root = project.root();
let cwd = &project_root;
snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("your-face --features eyes")
.current_dir(cwd)
.assert()
.code(101)
.stdout_matches(str![""])
.stderr_matches(file!["stderr.term.svg"]);
assert_ui().subset_matches(current_dir!().join("out"), &project_root);
}

View file

@ -1,9 +0,0 @@
[workspace]
[package]
name = "cargo-list-test-fixture"
version = "0.0.0"
edition = "2015"
[dependencies]
your-face = { }

View file

@ -1,27 +0,0 @@
<svg width="1213px" height="56px" xmlns="http://www.w3.org/2000/svg">
<style>
.fg { fill: #AAAAAA }
.bg { background: #000000 }
.fg-red { fill: #AA0000 }
.container {
padding: 0 10px;
line-height: 18px;
}
.bold { font-weight: bold; }
tspan {
font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
white-space: pre;
line-height: 18px;
}
</style>
<rect width="100%" height="100%" y="0" rx="4.5" class="bg" />
<text xml:space="preserve" class="container fg">
<tspan x="10px" y="28px"><tspan class="fg-red bold">error</tspan><tspan class="bold">:</tspan><tspan> unrecognized dependency source for `your-face`, expected a local path, Git repository, version, or workspace dependency to be specified</tspan>
</tspan>
<tspan x="10px" y="46px">
</tspan>
</text>
</svg>

Before

Width:  |  Height:  |  Size: 861 B

View file

@ -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;

View file

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