Skip to content

Commit df9c125

Browse files
committed
fix(cargo): Add a warning on [project] table being used in a manifest
1 parent 9b4b584 commit df9c125

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 10 additions & 1 deletion
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

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

0 commit comments

Comments
 (0)