From f1caef11c4f0b740fdedbae4ef3db0c88074bbc7 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 18 Apr 2024 13:39:29 -0500 Subject: [PATCH 01/10] test: Move off of deprecated manifest fields --- tests/testsuite/bench.rs | 4 ++-- tests/testsuite/build.rs | 10 +++++----- tests/testsuite/cross_compile.rs | 4 ++-- tests/testsuite/proc_macro.rs | 2 +- tests/testsuite/profiles.rs | 2 +- tests/testsuite/run.rs | 4 ++-- tests/testsuite/test.rs | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/testsuite/bench.rs b/tests/testsuite/bench.rs index ea646b398d8..eb9c92c1edd 100644 --- a/tests/testsuite/bench.rs +++ b/tests/testsuite/bench.rs @@ -853,7 +853,7 @@ fn bench_dylib() { [lib] name = "foo" - crate_type = ["dylib"] + crate-type = ["dylib"] [dependencies.bar] path = "bar" @@ -895,7 +895,7 @@ fn bench_dylib() { [lib] name = "bar" - crate_type = ["dylib"] + crate-type = ["dylib"] "#, ) .file("bar/src/lib.rs", "pub fn baz() {}") diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index daa605fdfd4..c1fb8cd040c 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -1496,7 +1496,7 @@ fn cargo_default_env_metadata_env_var() { [lib] name = "bar" - crate_type = ["dylib"] + crate-type = ["dylib"] "#, ) .file("bar/src/lib.rs", "// hello") @@ -2089,7 +2089,7 @@ fn many_crate_types_old_style_lib_location() { [lib] name = "foo" - crate_type = ["rlib", "dylib"] + crate-type = ["rlib", "dylib"] "#, ) .file("src/foo.rs", "pub fn foo() {}") @@ -2123,7 +2123,7 @@ fn many_crate_types_correct() { [lib] name = "foo" - crate_type = ["rlib", "dylib"] + crate-type = ["rlib", "dylib"] "#, ) .file("src/lib.rs", "pub fn foo() {}") @@ -2151,7 +2151,7 @@ fn set_both_dylib_and_cdylib_crate_types() { [lib] name = "foo" - crate_type = ["cdylib", "dylib"] + crate-type = ["cdylib", "dylib"] "#, ) .file("src/lib.rs", "pub fn foo() {}") @@ -2521,7 +2521,7 @@ fn verbose_release_build_deps() { [lib] name = "foo" - crate_type = ["dylib", "rlib"] + crate-type = ["dylib", "rlib"] "#, ) .file("foo/src/lib.rs", "") diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs index f55e5992024..bcb0a419017 100644 --- a/tests/testsuite/cross_compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -1175,7 +1175,7 @@ fn cross_test_dylib() { [lib] name = "foo" - crate_type = ["dylib"] + crate-type = ["dylib"] [dependencies.bar] path = "bar" @@ -1212,7 +1212,7 @@ fn cross_test_dylib() { [lib] name = "bar" - crate_type = ["dylib"] + crate-type = ["dylib"] "#, ) .file( diff --git a/tests/testsuite/proc_macro.rs b/tests/testsuite/proc_macro.rs index 1f6a378c11d..a4d04f78481 100644 --- a/tests/testsuite/proc_macro.rs +++ b/tests/testsuite/proc_macro.rs @@ -509,7 +509,7 @@ fn proc_macro_built_once() { edition = "2015" [lib] - proc_macro = true + proc-macro = true [features] a = [] diff --git a/tests/testsuite/profiles.rs b/tests/testsuite/profiles.rs index d04cdacd5b2..8348ffd034c 100644 --- a/tests/testsuite/profiles.rs +++ b/tests/testsuite/profiles.rs @@ -203,7 +203,7 @@ fn top_level_overrides_deps() { [lib] name = "foo" - crate_type = ["dylib", "rlib"] + crate-type = ["dylib", "rlib"] "#, ) .file("foo/src/lib.rs", "") diff --git a/tests/testsuite/run.rs b/tests/testsuite/run.rs index ac7707985ea..15ca5591ca2 100644 --- a/tests/testsuite/run.rs +++ b/tests/testsuite/run.rs @@ -443,7 +443,7 @@ fn run_library_example() { authors = [] [[example]] name = "bar" - crate_type = ["lib"] + crate-type = ["lib"] "#, ) .file("src/lib.rs", "") @@ -468,7 +468,7 @@ fn run_bin_example() { edition = "2015" [[example]] name = "bar" - crate_type = ["bin"] + crate-type = ["bin"] "#, ) .file("src/lib.rs", "") diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index b0ca38670fc..a32cb6d0eba 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -1330,7 +1330,7 @@ fn test_dylib() { [lib] name = "foo" - crate_type = ["dylib"] + crate-type = ["dylib"] [dependencies.bar] path = "bar" @@ -1367,7 +1367,7 @@ fn test_dylib() { [lib] name = "bar" - crate_type = ["dylib"] + crate-type = ["dylib"] "#, ) .file("bar/src/lib.rs", "pub fn baz() {}") From 3fc52d53b1b172d7b6d19c7fa74f83c3c0d6941e Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 18 Apr 2024 14:35:39 -0500 Subject: [PATCH 02/10] test(toml): Make test names scale to more scenarios --- tests/testsuite/build.rs | 12 ++++++------ tests/testsuite/features.rs | 2 +- tests/testsuite/proc_macro.rs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index c1fb8cd040c..59a0220c3f8 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -2170,7 +2170,7 @@ Caused by: } #[cargo_test] -fn dev_dependencies_conflicting_warning() { +fn dev_dependencies2_conflict() { let p = project() .file( "Cargo.toml", @@ -2207,7 +2207,7 @@ fn dev_dependencies_conflicting_warning() { } #[cargo_test] -fn build_dependencies_conflicting_warning() { +fn build_dependencies2_conflict() { let p = project() .file( "Cargo.toml", @@ -2244,7 +2244,7 @@ fn build_dependencies_conflicting_warning() { } #[cargo_test] -fn lib_crate_types_conflicting_warning() { +fn lib_crate_type2_conflict() { let p = project() .file( "Cargo.toml", @@ -2272,7 +2272,7 @@ fn lib_crate_types_conflicting_warning() { } #[cargo_test] -fn examples_crate_types_conflicting_warning() { +fn examples_crate_type2_conflict() { let p = project() .file( "Cargo.toml", @@ -3507,7 +3507,7 @@ fn cargo_platform_specific_dependency() { } #[cargo_test] -fn cargo_platform_specific_dependency_build_dependencies_conflicting_warning() { +fn cargo_platform_build_dependencies2_conflict() { let host = rustc_host(); let p = project() .file( @@ -3549,7 +3549,7 @@ fn cargo_platform_specific_dependency_build_dependencies_conflicting_warning() { } #[cargo_test] -fn cargo_platform_specific_dependency_dev_dependencies_conflicting_warning() { +fn cargo_platform_dev_dependencies2_conflict() { let host = rustc_host(); let p = project() .file( diff --git a/tests/testsuite/features.rs b/tests/testsuite/features.rs index 72957b0771c..08395bc5945 100644 --- a/tests/testsuite/features.rs +++ b/tests/testsuite/features.rs @@ -2206,7 +2206,7 @@ fn invalid_feature_name_slash_error() { } #[cargo_test] -fn default_features_conflicting_warning() { +fn default_features2_conflict() { let p = project() .file( "Cargo.toml", diff --git a/tests/testsuite/proc_macro.rs b/tests/testsuite/proc_macro.rs index a4d04f78481..f4e93df2596 100644 --- a/tests/testsuite/proc_macro.rs +++ b/tests/testsuite/proc_macro.rs @@ -346,7 +346,7 @@ fn proc_macro_crate_type_warning() { } #[cargo_test] -fn proc_macro_conflicting_warning() { +fn proc_macro2_conflict() { let foo = project() .file( "Cargo.toml", From 8520ec63b6887dd38c437339cbfd12b746aa4aac Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 18 Apr 2024 14:38:05 -0500 Subject: [PATCH 03/10] test(toml): Centralize underscore field tests --- tests/testsuite/bad_config.rs | 303 ++++++++++++++++++++++++++++++++++ tests/testsuite/build.rs | 235 -------------------------- tests/testsuite/features.rs | 42 ----- tests/testsuite/proc_macro.rs | 26 --- 4 files changed, 303 insertions(+), 303 deletions(-) diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index cbd216491e7..a34673e1a82 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -804,6 +804,309 @@ Caused by: .run(); } +#[cargo_test] +fn dev_dependencies2_conflict() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2018" + + [dev-dependencies] + a = {path = "a"} + [dev_dependencies] + a = {path = "a"} + "#, + ) + .file("src/lib.rs", "") + .file( + "a/Cargo.toml", + r#" + [package] + name = "a" + version = "0.0.1" + edition = "2015" + "#, + ) + .file("a/src/lib.rs", "") + .build(); + p.cargo("build") + .with_stderr_contains( +"[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `foo` package.\n + `dev_dependencies` is ignored and not recommended for use in the future" + ) + .run(); +} + +#[cargo_test] +fn build_dependencies2_conflict() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2018" + + [build-dependencies] + a = {path = "a"} + [build_dependencies] + a = {path = "a"} + "#, + ) + .file("src/lib.rs", "") + .file( + "a/Cargo.toml", + r#" + [package] + name = "a" + version = "0.0.1" + edition = "2015" + "#, + ) + .file("a/src/lib.rs", "") + .build(); + p.cargo("build") + .with_stderr_contains( +"[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `foo` package.\n + `build_dependencies` is ignored and not recommended for use in the future" + ) + .run(); +} + +#[cargo_test] +fn lib_crate_type2_conflict() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.5.0" + edition = "2015" + 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] conflicting between `crate-type` and `crate_type` in the `foo` library target.\n + `crate_type` is ignored and not recommended for use in the future", + ) + .run(); +} + +#[cargo_test] +fn examples_crate_type2_conflict() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.5.0" + edition = "2015" + 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] conflicting between `crate-type` and `crate_type` in the `ex` example target.\n + `crate_type` is ignored and not recommended for use in the future +[WARNING] conflicting between `crate-type` and `crate_type` in the `goodbye` example target.\n + `crate_type` is ignored and not recommended for use in the future", + ) + .run(); +} + +#[cargo_test] +fn cargo_platform_build_dependencies2_conflict() { + let host = rustc_host(); + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.5.0" + edition = "2015" + authors = ["wycats@example.com"] + build = "build.rs" + + [target.{host}.build-dependencies] + build = {{ path = "build" }} + [target.{host}.build_dependencies] + build = {{ path = "build" }} + "#, + host = host + ), + ) + .file("src/main.rs", "fn main() { }") + .file( + "build.rs", + "extern crate build; fn main() { build::build(); }", + ) + .file("build/Cargo.toml", &basic_manifest("build", "0.5.0")) + .file("build/src/lib.rs", "pub fn build() {}") + .build(); + + p.cargo("build") + .with_stderr_contains( + format!("[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `{}` platform target.\n + `build_dependencies` is ignored and not recommended for use in the future", host) + ) + .run(); + + assert!(p.bin("foo").is_file()); +} + +#[cargo_test] +fn cargo_platform_dev_dependencies2_conflict() { + let host = rustc_host(); + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.5.0" + edition = "2015" + authors = ["wycats@example.com"] + + [target.{host}.dev-dependencies] + dev = {{ path = "dev" }} + [target.{host}.dev_dependencies] + dev = {{ path = "dev" }} + "#, + host = host + ), + ) + .file("src/main.rs", "fn main() { }") + .file( + "tests/foo.rs", + "extern crate dev; #[test] fn foo() { dev::dev() }", + ) + .file("dev/Cargo.toml", &basic_manifest("dev", "0.5.0")) + .file("dev/src/lib.rs", "pub fn dev() {}") + .build(); + + p.cargo("build") + .with_stderr_contains( + format!("[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `{}` platform target.\n + `dev_dependencies` is ignored and not recommended for use in the future", host) + ) + .run(); + + assert!(p.bin("foo").is_file()); + p.cargo("test").run(); +} + +#[cargo_test] +fn default_features2_conflict() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2015" + authors = [] + + [dependencies] + a = { path = "a", features = ["f1"], default-features = false, default_features = false } + "#, + ) + .file("src/lib.rs", "") + .file( + "a/Cargo.toml", + r#" + [package] + name = "a" + version = "0.1.0" + edition = "2015" + authors = [] + + [features] + default = ["f1"] + f1 = [] + "#, + ) + .file("a/src/lib.rs", "") + .build(); + + p.cargo("check") + .with_stderr_contains( +"[WARNING] conflicting between `default-features` and `default_features` in the `a` dependency.\n + `default_features` is ignored and not recommended for use in the future" + ) + .run(); +} + +#[cargo_test] +fn proc_macro2_conflict() { + let foo = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2015" + [lib] + proc-macro = false + proc_macro = true + "#, + ) + .file("src/lib.rs", "") + .build(); + + foo.cargo("check") + .with_stderr_contains( +"[WARNING] conflicting between `proc-macro` and `proc_macro` in the `foo` library target.\n + `proc_macro` is ignored and not recommended for use in the future", + ) + .run(); +} + #[cargo_test] fn invalid_toml_historically_allowed_fails() { let p = project() diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index 59a0220c3f8..7da48de80cf 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -2169,157 +2169,6 @@ Caused by: .run(); } -#[cargo_test] -fn dev_dependencies2_conflict() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - edition = "2018" - - [dev-dependencies] - a = {path = "a"} - [dev_dependencies] - a = {path = "a"} - "#, - ) - .file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - edition = "2015" - "#, - ) - .file("a/src/lib.rs", "") - .build(); - p.cargo("build") - .with_stderr_contains( -"[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `foo` package.\n - `dev_dependencies` is ignored and not recommended for use in the future" - ) - .run(); -} - -#[cargo_test] -fn build_dependencies2_conflict() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - edition = "2018" - - [build-dependencies] - a = {path = "a"} - [build_dependencies] - a = {path = "a"} - "#, - ) - .file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.0.1" - edition = "2015" - "#, - ) - .file("a/src/lib.rs", "") - .build(); - p.cargo("build") - .with_stderr_contains( -"[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `foo` package.\n - `build_dependencies` is ignored and not recommended for use in the future" - ) - .run(); -} - -#[cargo_test] -fn lib_crate_type2_conflict() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.5.0" - edition = "2015" - 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] conflicting between `crate-type` and `crate_type` in the `foo` library target.\n - `crate_type` is ignored and not recommended for use in the future", - ) - .run(); -} - -#[cargo_test] -fn examples_crate_type2_conflict() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.5.0" - edition = "2015" - 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] conflicting between `crate-type` and `crate_type` in the `ex` example target.\n - `crate_type` is ignored and not recommended for use in the future -[WARNING] conflicting between `crate-type` and `crate_type` in the `goodbye` example target.\n - `crate_type` is ignored and not recommended for use in the future", - ) - .run(); -} - #[cargo_test] fn self_dependency() { let p = project() @@ -3506,90 +3355,6 @@ fn cargo_platform_specific_dependency() { p.cargo("test").run(); } -#[cargo_test] -fn cargo_platform_build_dependencies2_conflict() { - let host = rustc_host(); - let p = project() - .file( - "Cargo.toml", - &format!( - r#" - [package] - name = "foo" - version = "0.5.0" - edition = "2015" - authors = ["wycats@example.com"] - build = "build.rs" - - [target.{host}.build-dependencies] - build = {{ path = "build" }} - [target.{host}.build_dependencies] - build = {{ path = "build" }} - "#, - host = host - ), - ) - .file("src/main.rs", "fn main() { }") - .file( - "build.rs", - "extern crate build; fn main() { build::build(); }", - ) - .file("build/Cargo.toml", &basic_manifest("build", "0.5.0")) - .file("build/src/lib.rs", "pub fn build() {}") - .build(); - - p.cargo("build") - .with_stderr_contains( - format!("[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `{}` platform target.\n - `build_dependencies` is ignored and not recommended for use in the future", host) - ) - .run(); - - assert!(p.bin("foo").is_file()); -} - -#[cargo_test] -fn cargo_platform_dev_dependencies2_conflict() { - let host = rustc_host(); - let p = project() - .file( - "Cargo.toml", - &format!( - r#" - [package] - name = "foo" - version = "0.5.0" - edition = "2015" - authors = ["wycats@example.com"] - - [target.{host}.dev-dependencies] - dev = {{ path = "dev" }} - [target.{host}.dev_dependencies] - dev = {{ path = "dev" }} - "#, - host = host - ), - ) - .file("src/main.rs", "fn main() { }") - .file( - "tests/foo.rs", - "extern crate dev; #[test] fn foo() { dev::dev() }", - ) - .file("dev/Cargo.toml", &basic_manifest("dev", "0.5.0")) - .file("dev/src/lib.rs", "pub fn dev() {}") - .build(); - - p.cargo("build") - .with_stderr_contains( - format!("[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `{}` platform target.\n - `dev_dependencies` is ignored and not recommended for use in the future", host) - ) - .run(); - - assert!(p.bin("foo").is_file()); - p.cargo("test").run(); -} - #[cargo_test] fn bad_platform_specific_dependency() { let p = project() diff --git a/tests/testsuite/features.rs b/tests/testsuite/features.rs index 08395bc5945..0b83f31af2e 100644 --- a/tests/testsuite/features.rs +++ b/tests/testsuite/features.rs @@ -2204,45 +2204,3 @@ fn invalid_feature_name_slash_error() { ) .run(); } - -#[cargo_test] -fn default_features2_conflict() { - let p = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - edition = "2015" - authors = [] - - [dependencies] - a = { path = "a", features = ["f1"], default-features = false, default_features = false } - "#, - ) - .file("src/lib.rs", "") - .file( - "a/Cargo.toml", - r#" - [package] - name = "a" - version = "0.1.0" - edition = "2015" - authors = [] - - [features] - default = ["f1"] - f1 = [] - "#, - ) - .file("a/src/lib.rs", "") - .build(); - - p.cargo("check") - .with_stderr_contains( -"[WARNING] conflicting between `default-features` and `default_features` in the `a` dependency.\n - `default_features` is ignored and not recommended for use in the future" - ) - .run(); -} diff --git a/tests/testsuite/proc_macro.rs b/tests/testsuite/proc_macro.rs index f4e93df2596..86bfe086c99 100644 --- a/tests/testsuite/proc_macro.rs +++ b/tests/testsuite/proc_macro.rs @@ -345,32 +345,6 @@ fn proc_macro_crate_type_warning() { .run(); } -#[cargo_test] -fn proc_macro2_conflict() { - let foo = project() - .file( - "Cargo.toml", - r#" - [package] - name = "foo" - version = "0.1.0" - edition = "2015" - [lib] - proc-macro = false - proc_macro = true - "#, - ) - .file("src/lib.rs", "") - .build(); - - foo.cargo("check") - .with_stderr_contains( -"[WARNING] conflicting between `proc-macro` and `proc_macro` in the `foo` library target.\n - `proc_macro` is ignored and not recommended for use in the future", - ) - .run(); -} - #[cargo_test] fn proc_macro_crate_type_warning_plugin() { let foo = project() From d210644a1b056f24fc1613c4deaf941c962f61a6 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 18 Apr 2024 14:40:04 -0500 Subject: [PATCH 04/10] test(toml): Switch from build to check for these bad_config --- tests/testsuite/bad_config.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index a34673e1a82..3123c862009 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -833,7 +833,7 @@ fn dev_dependencies2_conflict() { ) .file("a/src/lib.rs", "") .build(); - p.cargo("build") + p.cargo("check") .with_stderr_contains( "[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `foo` package.\n `dev_dependencies` is ignored and not recommended for use in the future" @@ -870,7 +870,7 @@ fn build_dependencies2_conflict() { ) .file("a/src/lib.rs", "") .build(); - p.cargo("build") + p.cargo("check") .with_stderr_contains( "[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `foo` package.\n `build_dependencies` is ignored and not recommended for use in the future" @@ -898,7 +898,7 @@ fn lib_crate_type2_conflict() { ) .file("src/lib.rs", "pub fn foo() {}") .build(); - p.cargo("build") + p.cargo("check") .with_stderr_contains( "[WARNING] conflicting between `crate-type` and `crate_type` in the `foo` library target.\n `crate_type` is ignored and not recommended for use in the future", @@ -944,7 +944,7 @@ fn examples_crate_type2_conflict() { "#, ) .build(); - p.cargo("build") + p.cargo("check") .with_stderr_contains( "\ [WARNING] conflicting between `crate-type` and `crate_type` in the `ex` example target.\n @@ -987,14 +987,12 @@ fn cargo_platform_build_dependencies2_conflict() { .file("build/src/lib.rs", "pub fn build() {}") .build(); - p.cargo("build") + p.cargo("check") .with_stderr_contains( format!("[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `{}` platform target.\n `build_dependencies` is ignored and not recommended for use in the future", host) ) .run(); - - assert!(p.bin("foo").is_file()); } #[cargo_test] @@ -1028,15 +1026,12 @@ fn cargo_platform_dev_dependencies2_conflict() { .file("dev/src/lib.rs", "pub fn dev() {}") .build(); - p.cargo("build") + p.cargo("check") .with_stderr_contains( format!("[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `{}` platform target.\n `dev_dependencies` is ignored and not recommended for use in the future", host) ) .run(); - - assert!(p.bin("foo").is_file()); - p.cargo("test").run(); } #[cargo_test] From 265f93e913171861c43c81751f54e989cdf4825a Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 18 Apr 2024 14:45:27 -0500 Subject: [PATCH 05/10] test(toml): Be consistent on expected output formatting --- tests/testsuite/bad_config.rs | 55 +++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index 3123c862009..a949440a580 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -835,8 +835,11 @@ fn dev_dependencies2_conflict() { .build(); p.cargo("check") .with_stderr_contains( -"[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `foo` package.\n - `dev_dependencies` is ignored and not recommended for use in the future" + "\ +[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `foo` package. + + `dev_dependencies` is ignored and not recommended for use in the future +", ) .run(); } @@ -872,8 +875,11 @@ fn build_dependencies2_conflict() { .build(); p.cargo("check") .with_stderr_contains( -"[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `foo` package.\n - `build_dependencies` is ignored and not recommended for use in the future" + "\ +[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `foo` package. + + `build_dependencies` is ignored and not recommended for use in the future +", ) .run(); } @@ -900,8 +906,11 @@ fn lib_crate_type2_conflict() { .build(); p.cargo("check") .with_stderr_contains( -"[WARNING] conflicting between `crate-type` and `crate_type` in the `foo` library target.\n - `crate_type` is ignored and not recommended for use in the future", + "\ +[WARNING] conflicting between `crate-type` and `crate_type` in the `foo` library target. + + `crate_type` is ignored and not recommended for use in the future +", ) .run(); } @@ -947,9 +956,11 @@ fn examples_crate_type2_conflict() { p.cargo("check") .with_stderr_contains( "\ -[WARNING] conflicting between `crate-type` and `crate_type` in the `ex` example target.\n +[WARNING] conflicting between `crate-type` and `crate_type` in the `ex` example target. + `crate_type` is ignored and not recommended for use in the future -[WARNING] conflicting between `crate-type` and `crate_type` in the `goodbye` example target.\n +[WARNING] conflicting between `crate-type` and `crate_type` in the `goodbye` example target. + `crate_type` is ignored and not recommended for use in the future", ) .run(); @@ -989,8 +1000,11 @@ fn cargo_platform_build_dependencies2_conflict() { p.cargo("check") .with_stderr_contains( - format!("[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `{}` platform target.\n - `build_dependencies` is ignored and not recommended for use in the future", host) + format!("\ +[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `{host}` platform target. + + `build_dependencies` is ignored and not recommended for use in the future +") ) .run(); } @@ -1028,8 +1042,11 @@ fn cargo_platform_dev_dependencies2_conflict() { p.cargo("check") .with_stderr_contains( - format!("[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `{}` platform target.\n - `dev_dependencies` is ignored and not recommended for use in the future", host) + format!("\ +[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `{host}` platform target. + + `dev_dependencies` is ignored and not recommended for use in the future +") ) .run(); } @@ -1070,8 +1087,11 @@ fn default_features2_conflict() { p.cargo("check") .with_stderr_contains( -"[WARNING] conflicting between `default-features` and `default_features` in the `a` dependency.\n - `default_features` is ignored and not recommended for use in the future" + "\ +[WARNING] conflicting between `default-features` and `default_features` in the `a` dependency. + + `default_features` is ignored and not recommended for use in the future +", ) .run(); } @@ -1096,8 +1116,11 @@ fn proc_macro2_conflict() { foo.cargo("check") .with_stderr_contains( -"[WARNING] conflicting between `proc-macro` and `proc_macro` in the `foo` library target.\n - `proc_macro` is ignored and not recommended for use in the future", + "\ +[WARNING] conflicting between `proc-macro` and `proc_macro` in the `foo` library target. + + `proc_macro` is ignored and not recommended for use in the future +", ) .run(); } From 42939d9eff8fb40158bc99f8b8e587a5b6db9c9e Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 17 Apr 2024 10:25:20 -0500 Subject: [PATCH 06/10] refactor(toml): Clarify function name --- src/cargo/util/toml/mod.rs | 14 +++++++------- src/cargo/util/toml/targets.rs | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 093f82638a1..c70cf19bbbc 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -905,7 +905,7 @@ fn inner_dependency_inherit_with<'a>( )) } if dependency.default_features.is_some() && dependency.default_features2.is_some() { - warn_on_deprecated("default-features", name, "dependency", warnings); + deprecated_underscore("default-features", name, "dependency", warnings); } inherit()?.get_dependency(name, package_root).map(|d| { match d { @@ -1158,7 +1158,7 @@ fn to_real_manifest( validate_dependencies(original_toml.dependencies.as_ref(), None, None, warnings)?; if original_toml.dev_dependencies.is_some() && original_toml.dev_dependencies2.is_some() { - warn_on_deprecated("dev-dependencies", package_name, "package", warnings); + deprecated_underscore("dev-dependencies", package_name, "package", warnings); } validate_dependencies( original_toml.dev_dependencies(), @@ -1167,7 +1167,7 @@ fn to_real_manifest( warnings, )?; if original_toml.build_dependencies.is_some() && original_toml.build_dependencies2.is_some() { - warn_on_deprecated("build-dependencies", package_name, "package", warnings); + deprecated_underscore("build-dependencies", package_name, "package", warnings); } validate_dependencies( original_toml.build_dependencies(), @@ -1186,7 +1186,7 @@ fn to_real_manifest( warnings, )?; if platform.build_dependencies.is_some() && platform.build_dependencies2.is_some() { - warn_on_deprecated("build-dependencies", name, "platform target", warnings); + deprecated_underscore("build-dependencies", name, "platform target", warnings); } validate_dependencies( platform.build_dependencies(), @@ -1195,7 +1195,7 @@ fn to_real_manifest( warnings, )?; if platform.dev_dependencies.is_some() && platform.dev_dependencies2.is_some() { - warn_on_deprecated("dev-dependencies", name, "platform target", warnings); + deprecated_underscore("dev-dependencies", name, "platform target", warnings); } validate_dependencies( platform.dev_dependencies(), @@ -1886,7 +1886,7 @@ fn detailed_dep_to_dependency( let version = orig.version.as_deref(); let mut dep = Dependency::parse(pkg_name, version, new_source_id)?; if orig.default_features.is_some() && orig.default_features2.is_some() { - warn_on_deprecated( + deprecated_underscore( "default-features", name_in_toml, "dependency", @@ -2304,7 +2304,7 @@ fn emit_diagnostic( } /// Warn about paths that have been deprecated and may conflict. -fn warn_on_deprecated(new_path: &str, name: &str, kind: &str, warnings: &mut Vec) { +fn deprecated_underscore(new_path: &str, name: &str, kind: &str, warnings: &mut Vec) { let old_path = new_path.replace("-", "_"); warnings.push(format!( "conflicting between `{new_path}` and `{old_path}` in the `{name}` {kind}.\n diff --git a/src/cargo/util/toml/targets.rs b/src/cargo/util/toml/targets.rs index 937177c9583..04debfd4b44 100644 --- a/src/cargo/util/toml/targets.rs +++ b/src/cargo/util/toml/targets.rs @@ -25,7 +25,7 @@ use crate::core::compiler::CrateType; use crate::core::{Edition, Feature, Features, Target}; use crate::util::errors::CargoResult; use crate::util::restricted_names; -use crate::util::toml::warn_on_deprecated; +use crate::util::toml::deprecated_underscore; const DEFAULT_TEST_DIR_NAME: &'static str = "tests"; const DEFAULT_BENCH_DIR_NAME: &'static str = "benches"; @@ -1103,7 +1103,7 @@ fn name_or_panic(target: &TomlTarget) -> &str { fn validate_proc_macro(target: &TomlTarget, kind: &str, warnings: &mut Vec) { if target.proc_macro.is_some() && target.proc_macro2.is_some() { - warn_on_deprecated( + deprecated_underscore( "proc-macro", name_or_panic(target), format!("{kind} target").as_str(), @@ -1114,7 +1114,7 @@ fn validate_proc_macro(target: &TomlTarget, kind: &str, warnings: &mut Vec) { if target.crate_type.is_some() && target.crate_type2.is_some() { - warn_on_deprecated( + deprecated_underscore( "crate-type", name_or_panic(target), format!("{kind} target").as_str(), From a4a3254bc341bdefd759b9daddc575ae5126dd53 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 18 Apr 2024 14:11:26 -0500 Subject: [PATCH 07/10] refactor(toml): Pull conditional into deprecation fn --- src/cargo/util/toml/mod.rs | 90 +++++++++++++++++++++++----------- src/cargo/util/toml/targets.rs | 32 ++++++------ 2 files changed, 78 insertions(+), 44 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index c70cf19bbbc..2f13199317a 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -904,9 +904,14 @@ fn inner_dependency_inherit_with<'a>( this could become a hard error in the future" )) } - if dependency.default_features.is_some() && dependency.default_features2.is_some() { - deprecated_underscore("default-features", name, "dependency", warnings); - } + deprecated_underscore( + &dependency.default_features2, + &dependency.default_features, + "default-features", + name, + "dependency", + warnings, + ); inherit()?.get_dependency(name, package_root).map(|d| { match d { manifest::TomlDependency::Simple(s) => { @@ -1157,18 +1162,28 @@ fn to_real_manifest( } validate_dependencies(original_toml.dependencies.as_ref(), None, None, warnings)?; - if original_toml.dev_dependencies.is_some() && original_toml.dev_dependencies2.is_some() { - deprecated_underscore("dev-dependencies", package_name, "package", warnings); - } + deprecated_underscore( + &original_toml.dev_dependencies2, + &original_toml.dev_dependencies, + "dev-dependencies", + package_name, + "package", + warnings, + ); validate_dependencies( original_toml.dev_dependencies(), None, Some(DepKind::Development), warnings, )?; - if original_toml.build_dependencies.is_some() && original_toml.build_dependencies2.is_some() { - deprecated_underscore("build-dependencies", package_name, "package", warnings); - } + deprecated_underscore( + &original_toml.build_dependencies2, + &original_toml.build_dependencies, + "build-dependencies", + package_name, + "package", + warnings, + ); validate_dependencies( original_toml.build_dependencies(), None, @@ -1185,18 +1200,28 @@ fn to_real_manifest( None, warnings, )?; - if platform.build_dependencies.is_some() && platform.build_dependencies2.is_some() { - deprecated_underscore("build-dependencies", name, "platform target", warnings); - } + deprecated_underscore( + &platform.build_dependencies2, + &platform.build_dependencies, + "build-dependencies", + name, + "platform target", + warnings, + ); validate_dependencies( platform.build_dependencies(), platform_kind.as_ref(), Some(DepKind::Build), warnings, )?; - if platform.dev_dependencies.is_some() && platform.dev_dependencies2.is_some() { - deprecated_underscore("dev-dependencies", name, "platform target", warnings); - } + deprecated_underscore( + &platform.dev_dependencies2, + &platform.dev_dependencies, + "dev-dependencies", + name, + "platform target", + warnings, + ); validate_dependencies( platform.dev_dependencies(), platform_kind.as_ref(), @@ -1885,14 +1910,14 @@ fn detailed_dep_to_dependency( let version = orig.version.as_deref(); let mut dep = Dependency::parse(pkg_name, version, new_source_id)?; - if orig.default_features.is_some() && orig.default_features2.is_some() { - deprecated_underscore( - "default-features", - name_in_toml, - "dependency", - manifest_ctx.warnings, - ); - } + deprecated_underscore( + &orig.default_features2, + &orig.default_features, + "default-features", + name_in_toml, + "dependency", + manifest_ctx.warnings, + ); dep.set_features(orig.features.iter().flatten()) .set_default_features(orig.default_features().unwrap_or(true)) .set_optional(orig.optional.unwrap_or(false)) @@ -2304,12 +2329,21 @@ fn emit_diagnostic( } /// Warn about paths that have been deprecated and may conflict. -fn deprecated_underscore(new_path: &str, name: &str, kind: &str, warnings: &mut Vec) { - let old_path = new_path.replace("-", "_"); - warnings.push(format!( - "conflicting between `{new_path}` and `{old_path}` in the `{name}` {kind}.\n +fn deprecated_underscore( + old: &Option, + new: &Option, + new_path: &str, + name: &str, + kind: &str, + warnings: &mut Vec, +) { + if old.is_some() && new.is_some() { + let old_path = new_path.replace("-", "_"); + warnings.push(format!( + "conflicting between `{new_path}` and `{old_path}` in the `{name}` {kind}.\n `{old_path}` is ignored and not recommended for use in the future" - )) + )) + } } fn warn_on_unused(unused: &BTreeSet, warnings: &mut Vec) { diff --git a/src/cargo/util/toml/targets.rs b/src/cargo/util/toml/targets.rs index 04debfd4b44..9c1268a39b8 100644 --- a/src/cargo/util/toml/targets.rs +++ b/src/cargo/util/toml/targets.rs @@ -1102,23 +1102,23 @@ fn name_or_panic(target: &TomlTarget) -> &str { } fn validate_proc_macro(target: &TomlTarget, kind: &str, warnings: &mut Vec) { - if target.proc_macro.is_some() && target.proc_macro2.is_some() { - deprecated_underscore( - "proc-macro", - name_or_panic(target), - format!("{kind} target").as_str(), - warnings, - ); - } + deprecated_underscore( + &target.proc_macro2, + &target.proc_macro, + "proc-macro", + name_or_panic(target), + format!("{kind} target").as_str(), + warnings, + ); } fn validate_crate_types(target: &TomlTarget, kind: &str, warnings: &mut Vec) { - if target.crate_type.is_some() && target.crate_type2.is_some() { - deprecated_underscore( - "crate-type", - name_or_panic(target), - format!("{kind} target").as_str(), - warnings, - ); - } + deprecated_underscore( + &target.crate_type2, + &target.crate_type, + "crate-type", + name_or_panic(target), + format!("{kind} target").as_str(), + warnings, + ); } From 208d10d06d306f76a74a3c192928b05244777522 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 18 Apr 2024 14:24:46 -0500 Subject: [PATCH 08/10] fix(toml): Switch the duplicate table warning to an unused key warning --- src/cargo/util/toml/mod.rs | 3 +- tests/testsuite/bad_config.rs | 53 ++++++++++++----------------------- 2 files changed, 19 insertions(+), 37 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 2f13199317a..075a46f37a8 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -2340,8 +2340,7 @@ fn deprecated_underscore( if old.is_some() && new.is_some() { let old_path = new_path.replace("-", "_"); warnings.push(format!( - "conflicting between `{new_path}` and `{old_path}` in the `{name}` {kind}.\n - `{old_path}` is ignored and not recommended for use in the future" + "unused manifest key `{old_path}` in the `{name}` {kind}" )) } } diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index a949440a580..8a4071b6588 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -836,9 +836,7 @@ fn dev_dependencies2_conflict() { p.cargo("check") .with_stderr_contains( "\ -[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `foo` package. - - `dev_dependencies` is ignored and not recommended for use in the future +[WARNING] unused manifest key `dev_dependencies` in the `foo` package ", ) .run(); @@ -876,9 +874,7 @@ fn build_dependencies2_conflict() { p.cargo("check") .with_stderr_contains( "\ -[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `foo` package. - - `build_dependencies` is ignored and not recommended for use in the future +[WARNING] unused manifest key `build_dependencies` in the `foo` package ", ) .run(); @@ -907,9 +903,7 @@ fn lib_crate_type2_conflict() { p.cargo("check") .with_stderr_contains( "\ -[WARNING] conflicting between `crate-type` and `crate_type` in the `foo` library target. - - `crate_type` is ignored and not recommended for use in the future +[WARNING] unused manifest key `crate_type` in the `foo` library target ", ) .run(); @@ -956,12 +950,9 @@ fn examples_crate_type2_conflict() { p.cargo("check") .with_stderr_contains( "\ -[WARNING] conflicting between `crate-type` and `crate_type` in the `ex` example target. - - `crate_type` is ignored and not recommended for use in the future -[WARNING] conflicting between `crate-type` and `crate_type` in the `goodbye` example target. - - `crate_type` is ignored and not recommended for use in the future", +[WARNING] unused manifest key `crate_type` in the `ex` example target +[WARNING] unused manifest key `crate_type` in the `goodbye` example target +", ) .run(); } @@ -999,13 +990,11 @@ fn cargo_platform_build_dependencies2_conflict() { .build(); p.cargo("check") - .with_stderr_contains( - format!("\ -[WARNING] conflicting between `build-dependencies` and `build_dependencies` in the `{host}` platform target. - - `build_dependencies` is ignored and not recommended for use in the future -") - ) + .with_stderr_contains(format!( + "\ +[WARNING] unused manifest key `build_dependencies` in the `{host}` platform target +" + )) .run(); } @@ -1041,13 +1030,11 @@ fn cargo_platform_dev_dependencies2_conflict() { .build(); p.cargo("check") - .with_stderr_contains( - format!("\ -[WARNING] conflicting between `dev-dependencies` and `dev_dependencies` in the `{host}` platform target. - - `dev_dependencies` is ignored and not recommended for use in the future -") - ) + .with_stderr_contains(format!( + "\ +[WARNING] unused manifest key `dev_dependencies` in the `{host}` platform target +" + )) .run(); } @@ -1088,9 +1075,7 @@ fn default_features2_conflict() { p.cargo("check") .with_stderr_contains( "\ -[WARNING] conflicting between `default-features` and `default_features` in the `a` dependency. - - `default_features` is ignored and not recommended for use in the future +[WARNING] unused manifest key `default_features` in the `a` dependency ", ) .run(); @@ -1117,9 +1102,7 @@ fn proc_macro2_conflict() { foo.cargo("check") .with_stderr_contains( "\ -[WARNING] conflicting between `proc-macro` and `proc_macro` in the `foo` library target. - - `proc_macro` is ignored and not recommended for use in the future +[WARNING] unused manifest key `proc_macro` in the `foo` library target ", ) .run(); From 868662c480c89a80e912fc65d633c5e6d924fc68 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 18 Apr 2024 14:57:12 -0500 Subject: [PATCH 09/10] test(toml): Show underscore field behavior --- tests/testsuite/bad_config.rs | 291 ++++++++++++++++++++++++++++++++++ 1 file changed, 291 insertions(+) diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index 8a4071b6588..a8e03d8b86d 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -804,6 +804,42 @@ Caused by: .run(); } +#[cargo_test] +fn dev_dependencies2() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2018" + + [dev_dependencies] + a = {path = "a"} + "#, + ) + .file("src/lib.rs", "") + .file( + "a/Cargo.toml", + r#" + [package] + name = "a" + version = "0.0.1" + edition = "2015" + "#, + ) + .file("a/src/lib.rs", "") + .build(); + p.cargo("check") + .with_stderr_does_not_contain( + "\ +[WARNING] [..] +", + ) + .run(); +} + #[cargo_test] fn dev_dependencies2_conflict() { let p = project() @@ -842,6 +878,42 @@ fn dev_dependencies2_conflict() { .run(); } +#[cargo_test] +fn build_dependencies2() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2018" + + [build_dependencies] + a = {path = "a"} + "#, + ) + .file("src/lib.rs", "") + .file( + "a/Cargo.toml", + r#" + [package] + name = "a" + version = "0.0.1" + edition = "2015" + "#, + ) + .file("a/src/lib.rs", "") + .build(); + p.cargo("check") + .with_stderr_does_not_contain( + "\ +[WARNING] [..] +", + ) + .run(); +} + #[cargo_test] fn build_dependencies2_conflict() { let p = project() @@ -880,6 +952,34 @@ fn build_dependencies2_conflict() { .run(); } +#[cargo_test] +fn lib_crate_type2() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.5.0" + edition = "2015" + authors = ["wycats@example.com"] + + [lib] + name = "foo" + crate_type = ["staticlib", "dylib"] + "#, + ) + .file("src/lib.rs", "pub fn foo() {}") + .build(); + p.cargo("check") + .with_stderr_does_not_contain( + "\ +[WARNING] [..] +", + ) + .run(); +} + #[cargo_test] fn lib_crate_type2_conflict() { let p = project() @@ -909,6 +1009,51 @@ fn lib_crate_type2_conflict() { .run(); } +#[cargo_test] +fn examples_crate_type2() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.5.0" + edition = "2015" + authors = ["wycats@example.com"] + + [[example]] + name = "ex" + path = "examples/ex.rs" + crate_type = ["proc_macro"] + [[example]] + name = "goodbye" + path = "examples/ex-goodbye.rs" + 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("check") + .with_stderr_does_not_contain( + "\ +[WARNING] [..] +", + ) + .run(); +} + #[cargo_test] fn examples_crate_type2_conflict() { let p = project() @@ -957,6 +1102,45 @@ fn examples_crate_type2_conflict() { .run(); } +#[cargo_test] +fn cargo_platform_build_dependencies2() { + let host = rustc_host(); + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.5.0" + edition = "2015" + authors = ["wycats@example.com"] + build = "build.rs" + + [target.{host}.build_dependencies] + build = {{ path = "build" }} + "#, + host = host + ), + ) + .file("src/main.rs", "fn main() { }") + .file( + "build.rs", + "extern crate build; fn main() { build::build(); }", + ) + .file("build/Cargo.toml", &basic_manifest("build", "0.5.0")) + .file("build/src/lib.rs", "pub fn build() {}") + .build(); + + p.cargo("check") + .with_stderr_does_not_contain( + "\ +[WARNING] [..] +", + ) + .run(); +} + #[cargo_test] fn cargo_platform_build_dependencies2_conflict() { let host = rustc_host(); @@ -998,6 +1182,44 @@ fn cargo_platform_build_dependencies2_conflict() { .run(); } +#[cargo_test] +fn cargo_platform_dev_dependencies2() { + let host = rustc_host(); + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.5.0" + edition = "2015" + authors = ["wycats@example.com"] + + [target.{host}.dev_dependencies] + dev = {{ path = "dev" }} + "#, + host = host + ), + ) + .file("src/main.rs", "fn main() { }") + .file( + "tests/foo.rs", + "extern crate dev; #[test] fn foo() { dev::dev() }", + ) + .file("dev/Cargo.toml", &basic_manifest("dev", "0.5.0")) + .file("dev/src/lib.rs", "pub fn dev() {}") + .build(); + + p.cargo("check") + .with_stderr_does_not_contain( + "\ +[WARNING] [..] +", + ) + .run(); +} + #[cargo_test] fn cargo_platform_dev_dependencies2_conflict() { let host = rustc_host(); @@ -1038,6 +1260,49 @@ fn cargo_platform_dev_dependencies2_conflict() { .run(); } +#[cargo_test] +fn default_features2() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2015" + authors = [] + + [dependencies] + a = { path = "a", features = ["f1"], default_features = false } + "#, + ) + .file("src/lib.rs", "") + .file( + "a/Cargo.toml", + r#" + [package] + name = "a" + version = "0.1.0" + edition = "2015" + authors = [] + + [features] + default = ["f1"] + f1 = [] + "#, + ) + .file("a/src/lib.rs", "") + .build(); + + p.cargo("check") + .with_stderr_does_not_contain( + "\ +[WARNING] [..] +", + ) + .run(); +} + #[cargo_test] fn default_features2_conflict() { let p = project() @@ -1081,6 +1346,32 @@ fn default_features2_conflict() { .run(); } +#[cargo_test] +fn proc_macro2() { + let foo = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2015" + [lib] + proc_macro = true + "#, + ) + .file("src/lib.rs", "") + .build(); + + foo.cargo("check") + .with_stderr_does_not_contain( + "\ +[WARNING] [..] +", + ) + .run(); +} + #[cargo_test] fn proc_macro2_conflict() { let foo = project() From d1f02476c20ad438af7fa6347cc49e70af232ad3 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 18 Apr 2024 16:15:34 -0500 Subject: [PATCH 10/10] fix(toml): Deprecate underscore fields --- src/cargo/util/toml/mod.rs | 5 ++++ tests/testsuite/bad_config.rs | 56 +++++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 075a46f37a8..16cba3cd3a2 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -2342,6 +2342,11 @@ fn deprecated_underscore( warnings.push(format!( "unused manifest key `{old_path}` in the `{name}` {kind}" )) + } else if old.is_some() { + let old_path = new_path.replace("-", "_"); + warnings.push(format!( + "`{old_path}` is deprecated in favor of `{new_path}` and will not work in the 2024 edition\n(in the `{name}` {kind})" + )) } } diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index a8e03d8b86d..e8fb1ad4065 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -832,10 +832,11 @@ fn dev_dependencies2() { .file("a/src/lib.rs", "") .build(); p.cargo("check") - .with_stderr_does_not_contain( + .with_stderr_contains( "\ -[WARNING] [..] -", +[WARNING] `dev_dependencies` is deprecated in favor of `dev-dependencies` and will not work in the 2024 edition +(in the `foo` package) +" ) .run(); } @@ -906,10 +907,11 @@ fn build_dependencies2() { .file("a/src/lib.rs", "") .build(); p.cargo("check") - .with_stderr_does_not_contain( + .with_stderr_contains( "\ -[WARNING] [..] -", +[WARNING] `build_dependencies` is deprecated in favor of `build-dependencies` and will not work in the 2024 edition +(in the `foo` package) +" ) .run(); } @@ -972,9 +974,10 @@ fn lib_crate_type2() { .file("src/lib.rs", "pub fn foo() {}") .build(); p.cargo("check") - .with_stderr_does_not_contain( + .with_stderr_contains( "\ -[WARNING] [..] +[WARNING] `crate_type` is deprecated in favor of `crate-type` and will not work in the 2024 edition +(in the `foo` library target) ", ) .run(); @@ -1046,9 +1049,12 @@ fn examples_crate_type2() { ) .build(); p.cargo("check") - .with_stderr_does_not_contain( + .with_stderr_contains( "\ -[WARNING] [..] +[WARNING] `crate_type` is deprecated in favor of `crate-type` and will not work in the 2024 edition +(in the `ex` example target) +[WARNING] `crate_type` is deprecated in favor of `crate-type` and will not work in the 2024 edition +(in the `goodbye` example target) ", ) .run(); @@ -1133,10 +1139,11 @@ fn cargo_platform_build_dependencies2() { .build(); p.cargo("check") - .with_stderr_does_not_contain( - "\ -[WARNING] [..] -", + .with_stderr_contains( + format!("\ +[WARNING] `build_dependencies` is deprecated in favor of `build-dependencies` and will not work in the 2024 edition +(in the `{host}` platform target) +") ) .run(); } @@ -1212,10 +1219,11 @@ fn cargo_platform_dev_dependencies2() { .build(); p.cargo("check") - .with_stderr_does_not_contain( - "\ -[WARNING] [..] -", + .with_stderr_contains( + format!("\ +[WARNING] `dev_dependencies` is deprecated in favor of `dev-dependencies` and will not work in the 2024 edition +(in the `{host}` platform target) +") ) .run(); } @@ -1295,10 +1303,11 @@ fn default_features2() { .build(); p.cargo("check") - .with_stderr_does_not_contain( + .with_stderr_contains( "\ -[WARNING] [..] -", +[WARNING] `default_features` is deprecated in favor of `default-features` and will not work in the 2024 edition +(in the `a` dependency) +" ) .run(); } @@ -1364,9 +1373,10 @@ fn proc_macro2() { .build(); foo.cargo("check") - .with_stderr_does_not_contain( + .with_stderr_contains( "\ -[WARNING] [..] +[WARNING] `proc_macro` is deprecated in favor of `proc-macro` and will not work in the 2024 edition +(in the `foo` library target) ", ) .run();