diff --git a/src/cargo/core/summary.rs b/src/cargo/core/summary.rs index ec0197cf40d..efc3cf8ad31 100644 --- a/src/cargo/core/summary.rs +++ b/src/cargo/core/summary.rs @@ -304,6 +304,13 @@ fn build_feature_map( // Validation of the feature name will be performed in the resolver. if !is_any_dep { + // editon2024 stops expose implicit features, which will strip weak optional dependencies from `dependencies` + if *weak { + bail!( + "feature `{feature}` includes `{fv}`, activate it in a feature with `dep:{dep_name}` if `{dep_name}` is an enabled dependency" + ); + } + bail!( "feature `{}` includes `{}`, but `{}` is not a dependency", feature, diff --git a/tests/testsuite/lints/unused_optional_dependencies.rs b/tests/testsuite/lints/unused_optional_dependencies.rs index 5a60855220b..609e5685701 100644 --- a/tests/testsuite/lints/unused_optional_dependencies.rs +++ b/tests/testsuite/lints/unused_optional_dependencies.rs @@ -157,3 +157,72 @@ warning: unused optional dependency ) .run(); } + +#[cargo_test(nightly, reason = "edition2024 is not stable")] +fn inactive_weak_optional_dep() { + Package::new("dep", "0.1.0").publish(); + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["edition2024"] + [package] + name = "foo" + version = "0.1.0" + edition = "2024" + + [dependencies] + + [features] + feat = ["dep?/feat"] + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check -Zcargo-lints") + .masquerade_as_nightly_cargo(&["cargo-lints", "edition2024"]) + .with_status(101) + .with_stderr( + "\ +error: failed to parse manifest at `[ROOT]/foo/Cargo.toml` + +Caused by: + feature `feat` includes `dep?/feat`, activate it in a feature with `dep:dep` if `dep` is an enabled dependency +", + ) + .run(); + + let p = project() + .file( + "Cargo.toml", + r#" + cargo-features = ["edition2024"] + [package] + name = "foo" + version = "0.1.0" + edition = "2024" + + [dependencies] + dep = { version = "0.1.0", optional = true } + + [features] + feat = ["dep?/feat"] + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check -Zcargo-lints") + .masquerade_as_nightly_cargo(&["cargo-lints", "edition2024"]) + .with_status(101) + .with_stderr( + "\ +error: failed to parse manifest at `[ROOT]/foo/Cargo.toml` + +Caused by: + feature `feat` includes `dep?/feat`, activate it in a feature with `dep:dep` if `dep` is an enabled dependency +", + ) + .run(); +}