diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index fa0362843..22447668f 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -2061,7 +2061,7 @@ impl TomlTarget { if self.proc_macro_raw.is_some() && self.proc_macro_raw2.is_some() { warnings.push(format!( "found both `proc-macro` and `proc_macro` are set \ - in the `{}` library", + in the `{}` library target", self.name() )); } @@ -2078,6 +2078,17 @@ impl TomlTarget { }) } + fn validate_crate_types(&self, target_kind_human: &str, warnings: &mut Vec) { + if self.crate_type.is_some() && self.crate_type2.is_some() { + warnings.push(format!( + "found both `crate-type` and `crate_type` are set \ + in the `{}` {} target", + self.name(), + target_kind_human + )); + } + } + fn crate_types(&self) -> Option<&Vec> { self.crate_type .as_ref() diff --git a/src/cargo/util/toml/targets.rs b/src/cargo/util/toml/targets.rs index 08acb0286..ac9bf468a 100644 --- a/src/cargo/util/toml/targets.rs +++ b/src/cargo/util/toml/targets.rs @@ -175,6 +175,7 @@ fn clean_lib( None => return Ok(None), }; lib.validate_proc_macro(warnings); + lib.validate_crate_types("library", warnings); validate_target_name(lib, "library", "lib", warnings)?; @@ -399,6 +400,7 @@ fn clean_examples( let mut result = Vec::new(); for (path, toml) in targets { + toml.validate_crate_types("example", warnings); let crate_types = match toml.crate_types() { Some(kinds) => kinds.iter().map(|s| s.into()).collect(), None => Vec::new(), diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 70550431a..43eb3ec8e 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -1676,6 +1676,78 @@ Caused by: .run(); } +#[cargo_test] +fn lib_crate_types_conflicting_warning() { + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [lib] + name = "foo" + crate-type = ["rlib", "dylib"] + crate_type = ["staticlib", "dylib"] + "#, + ) + .file("src/lib.rs", "pub fn foo() {}") + .build(); + p.cargo("build") + .with_stderr_contains( + "[WARNING] found both `crate-type` and `crate_type` are set in the `foo` library target", + ) + .run(); +} + +#[cargo_test] +fn examples_crate_types_conflicting_warning() { + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [[example]] + name = "ex" + path = "examples/ex.rs" + crate-type = ["rlib", "dylib"] + crate_type = ["proc_macro"] + [[example]] + name = "goodbye" + path = "examples/ex-goodbye.rs" + crate-type = ["rlib", "dylib"] + crate_type = ["rlib", "staticlib"] + "#, + ) + .file("src/lib.rs", "") + .file( + "examples/ex.rs", + r#" + fn main() { println!("ex"); } + "#, + ) + .file( + "examples/ex-goodbye.rs", + r#" + fn main() { println!("goodbye"); } + "#, + ) + .build(); + p.cargo("build") + .with_stderr_contains( + "\ +[WARNING] found both `crate-type` and `crate_type` are set in the `ex` example target +[WARNING] found both `crate-type` and `crate_type` are set in the `goodbye` example target", + ) + .run(); +} + #[cargo_test] fn self_dependency() { let p = project() diff --git a/tests/testsuite/proc_macro.rs b/tests/testsuite/proc_macro.rs index 2d2f784c9..c40d6a153 100644 --- a/tests/testsuite/proc_macro.rs +++ b/tests/testsuite/proc_macro.rs @@ -406,7 +406,7 @@ fn proc_macro_conflicting_warning() { foo.cargo("build") .with_stderr_contains( - "[WARNING] found both `proc-macro` and `proc_macro` are set in the `foo` library", + "[WARNING] found both `proc-macro` and `proc_macro` are set in the `foo` library target", ) .run(); }