Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate: Discard the existence of [project] and change WARNING to ERROR #13762

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions crates/cargo-util-schemas/src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub struct TomlManifest {
// when adding new fields, be sure to check whether `requires_package` should disallow them
pub cargo_features: Option<Vec<String>>,
pub package: Option<Box<TomlPackage>>,
pub project: Option<Box<TomlPackage>>,
pub profile: Option<TomlProfiles>,
pub lib: Option<TomlLibTarget>,
pub bin: Option<Vec<TomlBinTarget>>,
Expand Down Expand Up @@ -87,7 +86,7 @@ impl TomlManifest {
}

pub fn package(&self) -> Option<&Box<TomlPackage>> {
self.package.as_ref().or(self.project.as_ref())
self.package.as_ref()
}

pub fn dev_dependencies(&self) -> Option<&BTreeMap<PackageName, InheritableDependency>> {
Expand Down
31 changes: 6 additions & 25 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ fn resolve_toml(
let mut resolved_toml = manifest::TomlManifest {
cargo_features: original_toml.cargo_features.clone(),
package: None,
project: None,
profile: original_toml.profile.clone(),
lib: original_toml.lib.clone(),
bin: original_toml.bin.clone(),
Expand Down Expand Up @@ -935,28 +934,11 @@ fn to_real_manifest(
);
};

let original_package = match (&original_toml.package, &original_toml.project) {
(Some(_), Some(project)) => {
warnings.push(format!(
"manifest at `{}` contains both `project` and `package`, \
this could become a hard error in the future",
package_root.display()
));
project.clone()
}
(Some(package), None) => package.clone(),
(None, Some(project)) => {
warnings.push(format!(
"manifest at `{}` contains `[project]` instead of `[package]`, \
this could become a hard error in the future",
package_root.display()
));
project.clone()
}
(None, None) => bail!("no `package` section found"),
let package_name = match &original_toml.package {
Some(package) => package.clone().name,
None => bail!("no `package` section found"),
};

let package_name = &original_package.name;
if package_name.contains(':') {
features.require(Feature::open_namespaces())?;
}
Expand Down Expand Up @@ -1068,7 +1050,7 @@ fn to_real_manifest(
let targets = to_targets(
&features,
&resolved_toml,
package_name,
&package_name,
package_root,
edition,
&resolved_package.build,
Expand Down Expand Up @@ -1109,7 +1091,7 @@ fn to_real_manifest(

validate_dependencies(original_toml.dependencies.as_ref(), None, None, warnings)?;
if original_toml.dev_dependencies.is_some() && original_toml.dev_dependencies2.is_some() {
warn_on_deprecated("dev-dependencies", package_name, "package", warnings);
warn_on_deprecated("dev-dependencies", &package_name, "package", warnings);
}
validate_dependencies(
original_toml.dev_dependencies(),
Expand All @@ -1118,7 +1100,7 @@ fn to_real_manifest(
warnings,
)?;
if original_toml.build_dependencies.is_some() && original_toml.build_dependencies2.is_some() {
warn_on_deprecated("build-dependencies", package_name, "package", warnings);
warn_on_deprecated("build-dependencies", &package_name, "package", warnings);
}
validate_dependencies(
original_toml.build_dependencies(),
Expand Down Expand Up @@ -2444,7 +2426,6 @@ fn prepare_toml_for_publish(
let all = |_d: &manifest::TomlDependency| true;
let mut manifest = manifest::TomlManifest {
package: Some(package),
project: None,
profile: me.profile.clone(),
lib,
bin,
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ fn sparse_lockfile() {
.file(
"Cargo.toml",
r#"
[project]
[package]
name = "a"
version = "0.5.0"
authors = []
Expand Down
59 changes: 1 addition & 58 deletions tests/testsuite/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,37 +979,6 @@ fn rustc_workspace_wrapper_excludes_published_deps() {
.run();
}

#[cargo_test]
fn warn_manifest_package_and_project() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"

[project]
name = "foo"
version = "0.0.1"
edition = "2015"
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("check")
.with_stderr(
"\
[WARNING] manifest at `[CWD]` contains both `project` and `package`, this could become a hard error in the future
[CHECKING] foo v0.0.1 ([CWD])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
",
)
.run();
}

#[cargo_test]
fn git_manifest_package_and_project() {
let p = project();
Expand Down Expand Up @@ -1065,40 +1034,14 @@ fn git_manifest_package_and_project() {
.run();
}

#[cargo_test]
fn warn_manifest_with_project() {
let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.0.1"
edition = "2015"
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("check")
.with_stderr(
"\
[WARNING] manifest at `[CWD]` contains `[project]` instead of `[package]`, this could become a hard error in the future
[CHECKING] foo v0.0.1 ([CWD])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
",
)
.run();
}

#[cargo_test]
fn git_manifest_with_project() {
let p = project();
let git_project = git::new("bar", |p| {
p.file(
"Cargo.toml",
r#"
[project]
[package]
name = "bar"
version = "0.0.1"
edition = "2015"
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn simple_add_with_asymmetric() {
.file(
"Cargo.toml",
r#"
[project]
[package]
name = "foo"
version = "0.0.1"
authors = []
Expand Down Expand Up @@ -170,7 +170,7 @@ fn simple_remove_with_asymmetric() {
.file(
"Cargo.toml",
r#"
[project]
[package]
name = "foo"
version = "0.0.1"
authors = []
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2864,7 +2864,7 @@ You may press ctrl-c [..]
.file(
"Cargo.toml",
r#"
[project]
[package]
name = "bar"
version = "0.0.1"
edition = "2015"
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/yank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn explicit_version_with_asymmetric() {
.file(
"Cargo.toml",
r#"
[project]
[package]
name = "foo"
version = "0.0.1"
authors = []
Expand Down
Loading