Skip to content

Commit

Permalink
Auto merge of #14028 - epage:unused, r=ehuss
Browse files Browse the repository at this point in the history
test(lints): Ensure unused optional dep fires for shadowed dep

This is a way to have an unused optional dependency before 2024 edition.
In prior editions, it is currently a hard error.
I'm tempted to switch that hard error to this lint in prior editions but at minimum, we need to make sure we don't make changes that cause this to revert back to a hard error on 2024+
  • Loading branch information
bors committed Jun 7, 2024
2 parents fb123c6 + a47d41e commit 3e89630
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/testsuite/lints/unused_optional_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,45 @@ warning: unused optional dependency
)
.run();
}

#[cargo_test(nightly, reason = "edition2024 is not stable")]
fn shadowed_optional_dep_is_unused_in_2024() {
Package::new("optional-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]
optional-dep = { version = "0.1.0", optional = true }
[features]
optional-dep = []
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("check -Zcargo-lints")
.masquerade_as_nightly_cargo(&["cargo-lints", "edition2024"])
.with_stderr(
"\
warning: unused optional dependency
--> Cargo.toml:9:1
|
9 | optional-dep = { version = \"0.1.0\", optional = true }
| ------------
|
= note: `cargo::unused_optional_dependency` is set to `warn` by default
= help: remove the dependency or activate it in a feature with `dep:optional-dep`
[CHECKING] foo v0.1.0 ([CWD])
[FINISHED] [..]
",
)
.run();
}

0 comments on commit 3e89630

Please sign in to comment.