Skip to content

unused-crate-dependencies conflicts in lib and bin crates #12854

Closed

Description

Problem

Cargo.toml

[package]
name = "hello"
version = "0.1.0"
edition = "2021"

[dependencies]
libc = "*"

src/lib.rs

#![deny(unused_crate_dependencies)]

src/main.rs

#![deny(unused_crate_dependencies)]

use hello as _;
use libc;

fn main() {
    let _: libc::size_t = 0;
}

In package hello, libc is needed by bin crate, not lib crate.

Steps

To reproduce, run cargo build. The build fails.

Possible Solution(s)

Because libc is needed by the bin crate, we have to list it as a package dependency. But then the lib crate complains.

One possible solution is to have each crate specify its own dependencies. The package-level dependencies would then be the union of all crate-level dependencies. But crate-level dependencies make more sense because users of a package may not want everything in the package. For example a user merely interested in using the library crate shouldn't be forced to pull dependencies required by binary crates.

Notes

No response

Version

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-cargo-targetsArea: selection and definition of targets (lib, bins, examples, tests, benches)Area: selection and definition of targets (lib, bins, examples, tests, benches)C-bugCategory: bugCategory: bugS-blocked-externalStatus: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fixStatus: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions