From 7e78c54630e249df3c438f14084ea266693dd3e3 Mon Sep 17 00:00:00 2001 From: Samuel Onoja Date: Fri, 9 May 2025 03:41:41 +0100 Subject: [PATCH 1/2] initial test commit --- tests/testsuite/bad_config.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index da7d473299e..c5fdaff2610 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -2641,6 +2641,39 @@ fn bad_dependency() { .run(); } +#[cargo_test] +fn bad_boolean_dependency() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.0" + edition = "2015" + authors = [] + + [dependencies] + bar = true + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check") + .with_status(101) + .with_stderr_data(str![[r#" +[ERROR] invalid type: boolean `true`, expected a version string like "0.9.8" or a detailed dependency like { version = "0.9.8" } + --> Cargo.toml:9:23 + | +9 | bar = true + | ^^^^ + | + +"#]]) + .run(); +} + #[cargo_test] fn bad_debuginfo() { let p = project() From 5dd597b621da49eafa1aa46365b6c3e65251ef19 Mon Sep 17 00:00:00 2001 From: Samuel Onoja Date: Fri, 9 May 2025 04:24:04 +0100 Subject: [PATCH 2/2] impl workspace hint for boolean dependencies hint for only bad dependency true literal and rename unit test to match --- crates/cargo-util-schemas/src/manifest/mod.rs | 22 +++++++++++++++---- tests/testsuite/bad_config.rs | 4 +++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/crates/cargo-util-schemas/src/manifest/mod.rs b/crates/cargo-util-schemas/src/manifest/mod.rs index 92dd3e88d08..101e8e1bdf3 100644 --- a/crates/cargo-util-schemas/src/manifest/mod.rs +++ b/crates/cargo-util-schemas/src/manifest/mod.rs @@ -787,12 +787,26 @@ impl<'de, P: Deserialize<'de> + Clone> de::Deserialize<'de> for TomlDependency

, { + use serde::de::Error as _; + let expected = "a version string like \"0.9.8\" or a \ + detailed dependency like { version = \"0.9.8\" }"; UntaggedEnumVisitor::new() - .expecting( - "a version string like \"0.9.8\" or a \ - detailed dependency like { version = \"0.9.8\" }", - ) + .expecting(expected) .string(|value| Ok(TomlDependency::Simple(value.to_owned()))) + .bool(|value| { + let expected = format!("invalid type: boolean `{value}`, expected {expected}"); + let err = if value { + format!( + "{expected}\n\ + note: if you meant to use a workspace member, you can write\n \ + dep.workspace = {value}" + ) + } else { + expected + }; + + Err(serde_untagged::de::Error::custom(err)) + }) .map(|value| value.deserialize().map(TomlDependency::Detailed)) .deserialize(deserializer) } diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index c5fdaff2610..406f0b1b7af 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -2642,7 +2642,7 @@ fn bad_dependency() { } #[cargo_test] -fn bad_boolean_dependency() { +fn bad_dependency_true_literal() { let p = project() .file( "Cargo.toml", @@ -2664,6 +2664,8 @@ fn bad_boolean_dependency() { .with_status(101) .with_stderr_data(str![[r#" [ERROR] invalid type: boolean `true`, expected a version string like "0.9.8" or a detailed dependency like { version = "0.9.8" } +[NOTE] if you meant to use a workspace member, you can write + dep.workspace = true --> Cargo.toml:9:23 | 9 | bar = true