fix(cargo): Add a warning on [project] table being used in a manifest

This commit is contained in:
Scott Schafer 2022-09-26 10:32:48 -06:00
parent cabee4f511
commit 8625d7274a
2 changed files with 82 additions and 1 deletions

View File

@ -1590,7 +1590,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"),
};

View File

@ -1104,3 +1104,75 @@ 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"
"#,
)
.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 [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]
name = "bar"
version = "0.0.1"
"#,
)
.file("src/lib.rs", "")
});
let p = p
.file(
"Cargo.toml",
&format!(
r#"
[package]
name = "foo"
version = "0.0.1"
[dependencies.bar]
version = "0.0.1"
git = '{}'
"#,
git_project.url()
),
)
.file("src/main.rs", "fn main() {}")
.build();
p.cargo("check")
.with_stderr(
"\
[UPDATING] git repository `[..]`
[CHECKING] bar v0.0.1 ([..])
[CHECKING] foo v0.0.1 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
)
.run();
}