mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
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:
commit
7e9c2ef30f
@ -1672,14 +1672,11 @@ fn detailed_dep_to_dependency<P: ResolveToPath + Clone>(
|
|||||||
kind: Option<DepKind>,
|
kind: Option<DepKind>,
|
||||||
) -> CargoResult<Dependency> {
|
) -> CargoResult<Dependency> {
|
||||||
if orig.version.is_none() && orig.path.is_none() && orig.git.is_none() {
|
if orig.version.is_none() && orig.path.is_none() && orig.git.is_none() {
|
||||||
let msg = format!(
|
anyhow::bail!(
|
||||||
"dependency ({}) specified without \
|
"dependency ({name_in_toml}) specified without \
|
||||||
providing a local path, Git repository, version, or \
|
providing a local path, Git repository, version, or \
|
||||||
workspace dependency to use. This will be considered an \
|
workspace dependency to use"
|
||||||
error in future versions",
|
|
||||||
name_in_toml
|
|
||||||
);
|
);
|
||||||
manifest_ctx.warnings.push(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(version) = &orig.version {
|
if let Some(version) = &orig.version {
|
||||||
|
@ -792,10 +792,13 @@ fn empty_dependencies() {
|
|||||||
Package::new("bar", "0.0.1").publish();
|
Package::new("bar", "0.0.1").publish();
|
||||||
|
|
||||||
p.cargo("check")
|
p.cargo("check")
|
||||||
.with_stderr_contains(
|
.with_status(101)
|
||||||
|
.with_stderr(
|
||||||
"\
|
"\
|
||||||
warning: dependency (bar) specified without providing a local path, Git repository, version, \
|
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
|
||||||
or workspace dependency to use. This will be considered an error in future versions
|
|
||||||
|
Caused by:
|
||||||
|
dependency (bar) specified without providing a local path, Git repository, version, or workspace dependency to use
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.run();
|
.run();
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
[workspace]
|
|
||||||
|
|
||||||
[package]
|
|
||||||
name = "cargo-list-test-fixture"
|
|
||||||
version = "0.0.0"
|
|
||||||
edition = "2015"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
your-face = { }
|
|
@ -1 +0,0 @@
|
|||||||
|
|
@ -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);
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
[workspace]
|
|
||||||
|
|
||||||
[package]
|
|
||||||
name = "cargo-list-test-fixture"
|
|
||||||
version = "0.0.0"
|
|
||||||
edition = "2015"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
your-face = { }
|
|
@ -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 |
@ -20,7 +20,6 @@ mod dev_build_conflict;
|
|||||||
mod dev_prefer_existing_version;
|
mod dev_prefer_existing_version;
|
||||||
mod dry_run;
|
mod dry_run;
|
||||||
mod empty_dep_name;
|
mod empty_dep_name;
|
||||||
mod empty_dep_table;
|
|
||||||
mod features;
|
mod features;
|
||||||
mod features_activated_over_limit;
|
mod features_activated_over_limit;
|
||||||
mod features_deactivated_over_limit;
|
mod features_deactivated_over_limit;
|
||||||
|
@ -1300,14 +1300,10 @@ fn error_workspace_dependency_looked_for_workspace_itself() {
|
|||||||
.with_status(101)
|
.with_status(101)
|
||||||
.with_stderr(
|
.with_stderr(
|
||||||
"\
|
"\
|
||||||
[WARNING] [CWD]/Cargo.toml: unused manifest key: workspace.dependencies.dep.workspace
|
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
|
||||||
[WARNING] [CWD]/Cargo.toml: dependency (dep) specified without providing a local path, Git repository, version, \
|
|
||||||
or workspace dependency to use. \
|
Caused by:
|
||||||
This will be considered an error in future versions
|
dependency (dep) specified without providing a local path, Git repository, version, or workspace dependency to use
|
||||||
[UPDATING] `dummy-registry` index
|
|
||||||
[ERROR] no matching package named `dep` found
|
|
||||||
location searched: registry `crates-io`
|
|
||||||
required by package `bar v1.2.3 ([CWD])`
|
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.run();
|
.run();
|
||||||
@ -1627,15 +1623,10 @@ fn cannot_inherit_in_patch() {
|
|||||||
.with_status(101)
|
.with_status(101)
|
||||||
.with_stderr(
|
.with_stderr(
|
||||||
"\
|
"\
|
||||||
[WARNING] [CWD]/Cargo.toml: unused manifest key: patch.crates-io.bar.workspace
|
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
|
||||||
[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`
|
|
||||||
|
|
||||||
Caused by:
|
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();
|
.run();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user