Skip to content

Commit 0687a2c

Browse files
committed
Revert "feat(lints): Add unused deps ignore list"
This reverts commit b276acc. This is a follow up to rust-lang#16935 where we take a different direction for false positives. Instead of an allowlist, we will ignore unused direct deps that are also transitive deps (technically still used somewhere). This leaves workflows like `curl` where the `build.rs` dynamically decides what deps to use but that seems like enough of an exception case to not worry about direct integration for.
1 parent 32aa9b5 commit 0687a2c

5 files changed

Lines changed: 0 additions & 108 deletions

File tree

src/cargo/core/compiler/unused_deps.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -173,23 +173,6 @@ impl UnusedDepState {
173173
continue;
174174
}
175175

176-
let mut ignore = Vec::new();
177-
if let Some(unused_dependencies) = cargo_lints.get("unused_dependencies") {
178-
if let Some(config) = unused_dependencies.config() {
179-
if let Some(config_ignore) = config.get("ignore") {
180-
if let Ok(config_ignore) =
181-
toml::Value::try_into::<Vec<InternedString>>(config_ignore.clone())
182-
{
183-
ignore = config_ignore
184-
} else {
185-
anyhow::bail!(
186-
"`lints.cargo.unused_dependencies.ignore` must be a list of string"
187-
);
188-
}
189-
}
190-
}
191-
}
192-
193176
let manifest_path = rel_cwd_manifest_path(pkg.manifest_path(), build_runner.bcx.gctx);
194177
let mut lint_count = 0;
195178
for (dep_kind, state) in states.iter() {
@@ -249,15 +232,6 @@ impl UnusedDepState {
249232
continue;
250233
};
251234
for dependency in dependency {
252-
if ignore.contains(&dependency.name_in_toml()) {
253-
debug!(
254-
"pkg {} v{} ({dep_kind:?}): ignoring unused extern `{ext}`, requested in manifest",
255-
pkg_id.name(),
256-
pkg_id.version(),
257-
);
258-
continue;
259-
}
260-
261235
let manifest = pkg.manifest();
262236
let document = manifest.document();
263237
let contents = manifest.contents();

src/cargo/lints/rules/unused_dependencies.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ Should be written as:
7171
[package]
7272
name = "foo"
7373
```
74-
75-
### Configuration
76-
77-
- `ignore`: a list of dependency names to allow the lint on
7874
"#,
7975
),
8076
};
@@ -115,34 +111,13 @@ pub fn unused_build_dependencies_no_build_rs(
115111
let document = manifest.document();
116112
let contents = manifest.contents();
117113

118-
let mut ignore = Vec::new();
119-
if let Some(unused_dependencies) = cargo_lints.get("unused_dependencies") {
120-
if let Some(config) = unused_dependencies.config() {
121-
if let Some(config_ignore) = config.get("ignore") {
122-
if let Ok(config_ignore) =
123-
toml::Value::try_into::<Vec<String>>(config_ignore.clone())
124-
{
125-
ignore = config_ignore
126-
} else {
127-
anyhow::bail!(
128-
"`lints.cargo.unused_dependencies.ignore` must be a list of string"
129-
);
130-
}
131-
}
132-
}
133-
}
134-
135114
for (i, dep_name) in manifest
136115
.normalized_toml()
137116
.build_dependencies()
138117
.iter()
139118
.flat_map(|m| m.keys())
140119
.enumerate()
141120
{
142-
if ignore.contains(&dep_name) {
143-
continue;
144-
}
145-
146121
let level = lint_level.to_diagnostic_level();
147122
let emitted_source = LINT.emitted_source(lint_level, reason);
148123

src/cargo/util/toml/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2734,7 +2734,6 @@ supported tools: {}",
27342734
}
27352735

27362736
static EXPECTED_LINT_CONFIG: &[(&str, &str, &str)] = &[
2737-
("cargo", "unused_dependencies", "ignore"),
27382737
// forwarded to rustc/rustdoc
27392738
("rust", "unexpected_cfgs", "check-cfg"),
27402739
];

src/doc/src/reference/lints.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,6 @@ Should be written as:
470470
name = "foo"
471471
```
472472

473-
### Configuration
474-
475-
- `ignore`: a list of dependency names to allow the lint on
476-
477473

478474
## `unused_workspace_dependencies`
479475
Group: `suspicious`

tests/testsuite/lints/unused_dependencies.rs

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,58 +1328,6 @@ pub fn fun() -> &'static str {
13281328
.run();
13291329
}
13301330

1331-
#[cargo_test]
1332-
fn config_ignore() {
1333-
// The most basic case where there is an unused dependency
1334-
Package::new("unused_build", "0.1.0").publish();
1335-
Package::new("unused", "0.1.0").publish();
1336-
let p = project()
1337-
.file(
1338-
"Cargo.toml",
1339-
r#"
1340-
[package]
1341-
name = "foo"
1342-
version = "0.1.0"
1343-
authors = []
1344-
edition = "2018"
1345-
1346-
[build-dependencies]
1347-
unused_build = "0.1.0"
1348-
1349-
[dependencies]
1350-
unused_renamed = { package = "unused", version = "0.1.0" }
1351-
1352-
[lints.cargo]
1353-
unused_dependencies = { level = "warn", ignore = ["unused_build", "unused_renamed"] }
1354-
"#,
1355-
)
1356-
.file(
1357-
"src/main.rs",
1358-
r#"
1359-
fn main() {}
1360-
"#,
1361-
)
1362-
.build();
1363-
1364-
p.cargo("check -Zcargo-lints")
1365-
.masquerade_as_nightly_cargo(&["cargo-lints"])
1366-
.with_stderr_data(
1367-
str![[r#"
1368-
[UPDATING] `dummy-registry` index
1369-
[LOCKING] 2 packages to latest compatible versions
1370-
[DOWNLOADING] crates ...
1371-
[DOWNLOADED] unused_build v0.1.0 (registry `dummy-registry`)
1372-
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
1373-
[CHECKING] unused v0.1.0
1374-
[CHECKING] foo v0.1.0 ([ROOT]/foo)
1375-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1376-
1377-
"#]]
1378-
.unordered(),
1379-
)
1380-
.run();
1381-
}
1382-
13831331
#[cargo_test]
13841332
fn allow_rustflags() {
13851333
// The most basic case where there is an unused dependency

0 commit comments

Comments
 (0)