Skip to content

Commit 8625d72

Browse files
committed
fix(cargo): Add a warning on [project] table being used in a manifest
1 parent cabee4f commit 8625d72

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

src/cargo/util/toml/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,16 @@ impl TomlManifest {
15901590
project.clone()
15911591
}
15921592
(Some(package), None) => package.clone(),
1593-
(None, Some(project)) => project.clone(),
1593+
(None, Some(project)) => {
1594+
if source_id.is_path() {
1595+
config.shell().warn(format!(
1596+
"manifest at `{}` contains `[project]` instead of `[package]`, \
1597+
this could become a hard error in the future",
1598+
package_root.display()
1599+
))?;
1600+
}
1601+
project.clone()
1602+
}
15941603
(None, None) => bail!("no `package` section found"),
15951604
};
15961605

tests/testsuite/check.rs

+72
Original file line numberDiff line numberDiff line change
@@ -1104,3 +1104,75 @@ fn git_manifest_package_and_project() {
11041104
)
11051105
.run();
11061106
}
1107+
1108+
#[cargo_test]
1109+
fn warn_manifest_with_project() {
1110+
let p = project()
1111+
.file(
1112+
"Cargo.toml",
1113+
r#"
1114+
[project]
1115+
name = "foo"
1116+
version = "0.0.1"
1117+
"#,
1118+
)
1119+
.file("src/main.rs", "fn main() {}")
1120+
.build();
1121+
1122+
p.cargo("check")
1123+
.with_stderr(
1124+
"\
1125+
[WARNING] manifest at `[CWD]` contains `[project]` instead of `[package]`, this could become a hard error in the future
1126+
[CHECKING] foo v0.0.1 ([CWD])
1127+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1128+
",
1129+
)
1130+
.run();
1131+
}
1132+
1133+
#[cargo_test]
1134+
fn git_manifest_with_project() {
1135+
let p = project();
1136+
let git_project = git::new("bar", |p| {
1137+
p.file(
1138+
"Cargo.toml",
1139+
r#"
1140+
[project]
1141+
name = "bar"
1142+
version = "0.0.1"
1143+
"#,
1144+
)
1145+
.file("src/lib.rs", "")
1146+
});
1147+
1148+
let p = p
1149+
.file(
1150+
"Cargo.toml",
1151+
&format!(
1152+
r#"
1153+
[package]
1154+
name = "foo"
1155+
version = "0.0.1"
1156+
1157+
[dependencies.bar]
1158+
version = "0.0.1"
1159+
git = '{}'
1160+
1161+
"#,
1162+
git_project.url()
1163+
),
1164+
)
1165+
.file("src/main.rs", "fn main() {}")
1166+
.build();
1167+
1168+
p.cargo("check")
1169+
.with_stderr(
1170+
"\
1171+
[UPDATING] git repository `[..]`
1172+
[CHECKING] bar v0.0.1 ([..])
1173+
[CHECKING] foo v0.0.1 ([CWD])
1174+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1175+
",
1176+
)
1177+
.run();
1178+
}

0 commit comments

Comments
 (0)