Skip to content

Commit 8cf0c95

Browse files
committed
Auto merge of #6806 - ehuss:warn-semver-metadata, r=Eh2406
Warn on version req with metadata. Metadata in a version requirement (such as `1.0.0+1234`) is ignored. This adds a warning that it will be ignored. On crates.io I found about 5 crates, plus a few dozen google-* crates (presumably all created by the same person) which have dependencies of this form. See discussion at #6504 (comment). cc rust-lang/crates.io#1059 for ongoing discussion about what to do about publishing such versions.
2 parents c1384e8 + 70e4e87 commit 8cf0c95

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/cargo/util/toml/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,17 @@ impl DetailedTomlDependency {
13181318
cx.warnings.push(msg);
13191319
}
13201320

1321+
if let Some(version) = &self.version {
1322+
if version.contains('+') {
1323+
cx.warnings.push(format!(
1324+
"version requirement `{}` for dependency `{}` \
1325+
includes semver metadata which will be ignored, removing the \
1326+
metadata is recommended to avoid confusion",
1327+
version, name_in_toml
1328+
));
1329+
}
1330+
}
1331+
13211332
if self.git.is_none() {
13221333
let git_only_keys = [
13231334
(&self.branch, "branch"),

tests/testsuite/bad_config.rs

+22
Original file line numberDiff line numberDiff line change
@@ -1280,3 +1280,25 @@ Caused by:
12801280
)
12811281
.run();
12821282
}
1283+
1284+
#[test]
1285+
fn warn_semver_metadata() {
1286+
Package::new("bar", "1.0.0").publish();
1287+
let p = project()
1288+
.file(
1289+
"Cargo.toml",
1290+
r#"
1291+
[package]
1292+
name = "foo"
1293+
version = "1.0.0"
1294+
1295+
[dependencies]
1296+
bar = "1.0.0+1234"
1297+
"#,
1298+
)
1299+
.file("src/lib.rs", "")
1300+
.build();
1301+
p.cargo("check")
1302+
.with_stderr_contains("[WARNING] version requirement `1.0.0+1234` for dependency `bar`[..]")
1303+
.run();
1304+
}

0 commit comments

Comments
 (0)