Skip to content

Commit 3e89630

Browse files
committed
Auto merge of #14028 - epage:unused, r=ehuss
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+
2 parents fb123c6 + a47d41e commit 3e89630

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/testsuite/lints/unused_optional_dependencies.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,45 @@ warning: unused optional dependency
157157
)
158158
.run();
159159
}
160+
161+
#[cargo_test(nightly, reason = "edition2024 is not stable")]
162+
fn shadowed_optional_dep_is_unused_in_2024() {
163+
Package::new("optional-dep", "0.1.0").publish();
164+
let p = project()
165+
.file(
166+
"Cargo.toml",
167+
r#"
168+
cargo-features = ["edition2024"]
169+
[package]
170+
name = "foo"
171+
version = "0.1.0"
172+
edition = "2024"
173+
174+
[dependencies]
175+
optional-dep = { version = "0.1.0", optional = true }
176+
177+
[features]
178+
optional-dep = []
179+
"#,
180+
)
181+
.file("src/lib.rs", "")
182+
.build();
183+
184+
p.cargo("check -Zcargo-lints")
185+
.masquerade_as_nightly_cargo(&["cargo-lints", "edition2024"])
186+
.with_stderr(
187+
"\
188+
warning: unused optional dependency
189+
--> Cargo.toml:9:1
190+
|
191+
9 | optional-dep = { version = \"0.1.0\", optional = true }
192+
| ------------
193+
|
194+
= note: `cargo::unused_optional_dependency` is set to `warn` by default
195+
= help: remove the dependency or activate it in a feature with `dep:optional-dep`
196+
[CHECKING] foo v0.1.0 ([CWD])
197+
[FINISHED] [..]
198+
",
199+
)
200+
.run();
201+
}

0 commit comments

Comments
 (0)