Skip to content

Commit 12dbfa3

Browse files
committed
Reject manifest with duplicate dependencies in different targets
Closes #2023
1 parent 132b82d commit 12dbfa3

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/cargo/util/toml.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,18 @@ impl TomlManifest {
540540
}
541541
}
542542

543+
{
544+
let mut names_sources = HashMap::new();
545+
for dep in deps.iter() {
546+
let name = dep.name();
547+
let prev = names_sources.insert(name, dep.source_id());
548+
if prev.is_some() && prev != Some(dep.source_id()) {
549+
bail!("found duplicate dependency name {}, but all \
550+
dependencies must have a unique name", name);
551+
}
552+
}
553+
}
554+
543555
let exclude = project.exclude.clone().unwrap_or(Vec::new());
544556
let include = project.include.clone().unwrap_or(Vec::new());
545557

tests/test_bad_config.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,50 @@ Caused by:
383383
error = ERROR)));
384384
});
385385

386+
test!(duplicate_deps {
387+
let foo = project("foo")
388+
.file("shim-bar/Cargo.toml", r#"
389+
[package]
390+
name = "bar"
391+
version = "0.0.1"
392+
authors = []
393+
"#)
394+
.file("shim-bar/src/lib.rs", r#"
395+
pub fn a() {}
396+
"#)
397+
.file("linux-bar/Cargo.toml", r#"
398+
[package]
399+
name = "bar"
400+
version = "0.0.1"
401+
authors = []
402+
"#)
403+
.file("linux-bar/src/lib.rs", r#"
404+
pub fn a() {}
405+
"#)
406+
.file("Cargo.toml", r#"
407+
[package]
408+
name = "qqq"
409+
version = "0.0.1"
410+
authors = []
411+
412+
[dependencies]
413+
bar = { path = "shim-bar" }
414+
415+
[target.x86_64-unknown-linux-gnu.dependencies]
416+
bar = { path = "linux-bar" }
417+
"#)
418+
.file("src/main.rs", r#"fn main () {}"#);
419+
420+
assert_that(foo.cargo_process("build"),
421+
execs().with_status(101).with_stderr(&format!("\
422+
{error} failed to parse manifest at `[..]`
423+
424+
Caused by:
425+
found duplicate dependency name bar, but all dependencies must have a unique name
426+
",
427+
error = ERROR)));
428+
});
429+
386430
test!(unused_keys {
387431
let foo = project("foo")
388432
.file("Cargo.toml", r#"

0 commit comments

Comments
 (0)