diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index f12eef29c318..d66b2b570b8b 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1588,7 +1588,16 @@ impl TomlManifest { project.clone() } (Some(package), None) => package.clone(), - (None, Some(project)) => project.clone(), + (None, Some(project)) => { + if source_id.is_path() { + config.shell().warn(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"), }; diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index 9918e3c182ab..a8c193e18046 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -1054,3 +1054,29 @@ fn warn_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" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("check") + .with_status(0) + .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 [unoptimized + debuginfo] target(s) in [..] +", + ) + .run(); +}