diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 0c66b7158c1..676e882e15c 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1318,6 +1318,17 @@ impl DetailedTomlDependency { cx.warnings.push(msg); } + if let Some(version) = &self.version { + if version.contains('+') { + cx.warnings.push(format!( + "version requirement `{}` for dependency `{}` \ + includes semver metadata which will be ignored, removing the \ + metadata is recommended to avoid confusion", + version, name_in_toml + )); + } + } + if self.git.is_none() { let git_only_keys = [ (&self.branch, "branch"), diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index 3da9972ac18..20f6d9de529 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -1280,3 +1280,25 @@ Caused by: ) .run(); } + +#[test] +fn warn_semver_metadata() { + Package::new("bar", "1.0.0").publish(); + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "1.0.0" + + [dependencies] + bar = "1.0.0+1234" + "#, + ) + .file("src/lib.rs", "") + .build(); + p.cargo("check") + .with_stderr_contains("[WARNING] version requirement `1.0.0+1234` for dependency `bar`[..]") + .run(); +}