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 26, 2022
1 parent cabee4f commit 8625d72
Show file tree
Hide file tree
Showing 2 changed files with 82 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 @@ -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"),
};

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

0 comments on commit 8625d72

Please sign in to comment.