From b8849dcb749a8b0e3ae814b4ab45b5b771ee5395 Mon Sep 17 00:00:00 2001 From: Frank Wang <1454884738@qq.com> Date: Sat, 15 Mar 2025 17:51:18 -0500 Subject: [PATCH 1/2] add test for duplicate crate-type arg --- tests/testsuite/rustc.rs | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/testsuite/rustc.rs b/tests/testsuite/rustc.rs index 124877f5468..ea3828cb971 100644 --- a/tests/testsuite/rustc.rs +++ b/tests/testsuite/rustc.rs @@ -855,3 +855,53 @@ fn precedence() { "#]]) .run(); } + +#[cargo_test] +fn build_with_duplicate_crate_types() { + let p = project().file("src/lib.rs", "").build(); + + p + .cargo("rustc -v --crate-type staticlib --crate-type staticlib") + .with_stderr_data(str![[r#" +[WARNING] output filename collision. +The lib target `foo` in package `foo v0.0.1 ([ROOT]/foo)` has the same output filename as the lib target `foo` in package `foo v0.0.1 ([ROOT]/foo)`. +Colliding filename is: [ROOT]/foo/target/debug/deps/libfoo-[HASH].a +The targets should have unique names. +Consider changing their names to be unique or compiling them separately. +This may become a hard error in the future; see . +[WARNING] output filename collision. +The lib target `foo` in package `foo v0.0.1 ([ROOT]/foo)` has the same output filename as the lib target `foo` in package `foo v0.0.1 ([ROOT]/foo)`. +Colliding filename is: [ROOT]/foo/target/debug/libfoo.a +The targets should have unique names. +Consider changing their names to be unique or compiling them separately. +This may become a hard error in the future; see . +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[RUNNING] `rustc [..]future-incompat --crate-type staticlib --crate-type staticlib --emit[..] +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s + +"#]]) + .run(); + + p.cargo("rustc -v --crate-type staticlib --crate-type staticlib") + .with_status(101) + .with_stderr_data(str![[r#" +[WARNING] output filename collision. +The lib target `foo` in package `foo v0.0.1 ([ROOT]/foo)` has the same output filename as the lib target `foo` in package `foo v0.0.1 ([ROOT]/foo)`. +Colliding filename is: [ROOT]/foo/target/debug/deps/libfoo-[HASH].a +The targets should have unique names. +Consider changing their names to be unique or compiling them separately. +This may become a hard error in the future; see . +[WARNING] output filename collision. +The lib target `foo` in package `foo v0.0.1 ([ROOT]/foo)` has the same output filename as the lib target `foo` in package `foo v0.0.1 ([ROOT]/foo)`. +Colliding filename is: [ROOT]/foo/target/debug/libfoo.a +The targets should have unique names. +Consider changing their names to be unique or compiling them separately. +This may become a hard error in the future; see . + +thread 'main' panicked at src/cargo/core/compiler/fingerprint/mod.rs:1180:13: +assertion failed: mtimes.insert(output.clone(), mtime).is_none() +[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace + +"#]]) + .run(); +} From 36de02f4a6f261ad29ec61de5e2bafe9795da0e8 Mon Sep 17 00:00:00 2001 From: Frank Wang <1454884738@qq.com> Date: Sat, 15 Mar 2025 17:55:15 -0500 Subject: [PATCH 2/2] fix: deduplicate and update snapshot --- src/bin/cargo/commands/rustc.rs | 19 +++++++++------- tests/testsuite/rustc.rs | 40 +++++---------------------------- 2 files changed, 17 insertions(+), 42 deletions(-) diff --git a/src/bin/cargo/commands/rustc.rs b/src/bin/cargo/commands/rustc.rs index ff660a33518..3db62928f00 100644 --- a/src/bin/cargo/commands/rustc.rs +++ b/src/bin/cargo/commands/rustc.rs @@ -92,14 +92,17 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult { return Ok(()); } - let crate_types = args - .get_many::(CRATE_TYPE_ARG_NAME) - .into_iter() - .flatten() - .flat_map(|s| s.split(',')) - .filter(|s| !s.is_empty()) - .map(String::from) - .collect::>(); + let crate_types = { + let mut seen = std::collections::HashSet::new(); + args.get_many::(CRATE_TYPE_ARG_NAME) + .into_iter() + .flatten() + .flat_map(|s| s.split(',')) + .filter(|s| !s.is_empty()) + .map(String::from) + .filter(|s| seen.insert(s.clone())) + .collect::>() + }; compile_opts.target_rustc_crate_types = if crate_types.is_empty() { None diff --git a/tests/testsuite/rustc.rs b/tests/testsuite/rustc.rs index ea3828cb971..6e9b5b22844 100644 --- a/tests/testsuite/rustc.rs +++ b/tests/testsuite/rustc.rs @@ -860,48 +860,20 @@ fn precedence() { fn build_with_duplicate_crate_types() { let p = project().file("src/lib.rs", "").build(); - p - .cargo("rustc -v --crate-type staticlib --crate-type staticlib") + p.cargo("rustc -v --crate-type staticlib --crate-type staticlib") .with_stderr_data(str![[r#" -[WARNING] output filename collision. -The lib target `foo` in package `foo v0.0.1 ([ROOT]/foo)` has the same output filename as the lib target `foo` in package `foo v0.0.1 ([ROOT]/foo)`. -Colliding filename is: [ROOT]/foo/target/debug/deps/libfoo-[HASH].a -The targets should have unique names. -Consider changing their names to be unique or compiling them separately. -This may become a hard error in the future; see . -[WARNING] output filename collision. -The lib target `foo` in package `foo v0.0.1 ([ROOT]/foo)` has the same output filename as the lib target `foo` in package `foo v0.0.1 ([ROOT]/foo)`. -Colliding filename is: [ROOT]/foo/target/debug/libfoo.a -The targets should have unique names. -Consider changing their names to be unique or compiling them separately. -This may become a hard error in the future; see . [COMPILING] foo v0.0.1 ([ROOT]/foo) -[RUNNING] `rustc [..]future-incompat --crate-type staticlib --crate-type staticlib --emit[..] +[RUNNING] `rustc [..] --crate-type staticlib --emit[..] [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s "#]]) .run(); p.cargo("rustc -v --crate-type staticlib --crate-type staticlib") - .with_status(101) - .with_stderr_data(str![[r#" -[WARNING] output filename collision. -The lib target `foo` in package `foo v0.0.1 ([ROOT]/foo)` has the same output filename as the lib target `foo` in package `foo v0.0.1 ([ROOT]/foo)`. -Colliding filename is: [ROOT]/foo/target/debug/deps/libfoo-[HASH].a -The targets should have unique names. -Consider changing their names to be unique or compiling them separately. -This may become a hard error in the future; see . -[WARNING] output filename collision. -The lib target `foo` in package `foo v0.0.1 ([ROOT]/foo)` has the same output filename as the lib target `foo` in package `foo v0.0.1 ([ROOT]/foo)`. -Colliding filename is: [ROOT]/foo/target/debug/libfoo.a -The targets should have unique names. -Consider changing their names to be unique or compiling them separately. -This may become a hard error in the future; see . - -thread 'main' panicked at src/cargo/core/compiler/fingerprint/mod.rs:1180:13: -assertion failed: mtimes.insert(output.clone(), mtime).is_none() -[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace + .with_stderr_data(str![[r#" +[FRESH] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s "#]]) - .run(); + .run(); }