Skip to content

Commit

Permalink
fix(cargo): Add a warning on [project] table being used in a manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
Muscraft committed Sep 23, 2022
1 parent 76e9e1b commit f784e7a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
};

Expand Down
26 changes: 26 additions & 0 deletions tests/testsuite/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit f784e7a

Please sign in to comment.