Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions src/cargo/core/compiler/unused_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,6 @@ impl UnusedDepState {
continue;
}

let mut ignore = Vec::new();
if let Some(unused_dependencies) = cargo_lints.get("unused_dependencies") {
if let Some(config) = unused_dependencies.config() {
if let Some(config_ignore) = config.get("ignore") {
if let Ok(config_ignore) =
toml::Value::try_into::<Vec<InternedString>>(config_ignore.clone())
{
ignore = config_ignore
} else {
anyhow::bail!(
"`lints.cargo.unused_dependencies.ignore` must be a list of string"
);
}
}
}
}

let manifest_path = rel_cwd_manifest_path(pkg.manifest_path(), build_runner.bcx.gctx);
let mut lint_count = 0;
for (dep_kind, state) in states.iter() {
Expand Down Expand Up @@ -249,15 +232,6 @@ impl UnusedDepState {
continue;
};
for dependency in dependency {
if ignore.contains(&dependency.name_in_toml()) {
debug!(
"pkg {} v{} ({dep_kind:?}): ignoring unused extern `{ext}`, requested in manifest",
pkg_id.name(),
pkg_id.version(),
);
continue;
}

let manifest = pkg.manifest();
let document = manifest.document();
let contents = manifest.contents();
Expand Down
25 changes: 0 additions & 25 deletions src/cargo/lints/rules/unused_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ Should be written as:
[package]
name = "foo"
```

### Configuration

- `ignore`: a list of dependency names to allow the lint on
"#,
),
};
Expand Down Expand Up @@ -115,34 +111,13 @@ pub fn unused_build_dependencies_no_build_rs(
let document = manifest.document();
let contents = manifest.contents();

let mut ignore = Vec::new();
if let Some(unused_dependencies) = cargo_lints.get("unused_dependencies") {
if let Some(config) = unused_dependencies.config() {
if let Some(config_ignore) = config.get("ignore") {
if let Ok(config_ignore) =
toml::Value::try_into::<Vec<String>>(config_ignore.clone())
{
ignore = config_ignore
} else {
anyhow::bail!(
"`lints.cargo.unused_dependencies.ignore` must be a list of string"
);
}
}
}
}

for (i, dep_name) in manifest
.normalized_toml()
.build_dependencies()
.iter()
.flat_map(|m| m.keys())
.enumerate()
{
if ignore.contains(&dep_name) {
continue;
}

let level = lint_level.to_diagnostic_level();
let emitted_source = LINT.emitted_source(lint_level, reason);

Expand Down
1 change: 0 additions & 1 deletion src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2734,7 +2734,6 @@ supported tools: {}",
}

static EXPECTED_LINT_CONFIG: &[(&str, &str, &str)] = &[
("cargo", "unused_dependencies", "ignore"),
// forwarded to rustc/rustdoc
("rust", "unexpected_cfgs", "check-cfg"),
];
Expand Down
4 changes: 0 additions & 4 deletions src/doc/src/reference/lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,6 @@ Should be written as:
name = "foo"
```

### Configuration

- `ignore`: a list of dependency names to allow the lint on


## `unused_workspace_dependencies`
Group: `suspicious`
Expand Down
52 changes: 0 additions & 52 deletions tests/testsuite/lints/unused_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,58 +1328,6 @@ pub fn fun() -> &'static str {
.run();
}

#[cargo_test]
fn config_ignore() {
// The most basic case where there is an unused dependency
Package::new("unused_build", "0.1.0").publish();
Package::new("unused", "0.1.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
authors = []
edition = "2018"

[build-dependencies]
unused_build = "0.1.0"

[dependencies]
unused_renamed = { package = "unused", version = "0.1.0" }

[lints.cargo]
unused_dependencies = { level = "warn", ignore = ["unused_build", "unused_renamed"] }
"#,
)
.file(
"src/main.rs",
r#"
fn main() {}
"#,
)
.build();

p.cargo("check -Zcargo-lints")
.masquerade_as_nightly_cargo(&["cargo-lints"])
.with_stderr_data(
str![[r#"
[UPDATING] `dummy-registry` index
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] unused_build v0.1.0 (registry `dummy-registry`)
[DOWNLOADED] unused v0.1.0 (registry `dummy-registry`)
[CHECKING] unused v0.1.0
[CHECKING] foo v0.1.0 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]]
.unordered(),
)
.run();
}

#[cargo_test]
fn allow_rustflags() {
// The most basic case where there is an unused dependency
Expand Down