Skip to content

unused_dependencies can't be granularly disabled/expected #17510

Open

Description

@clarfonthey

Problem

So, the specific use case I'm running into here is allocator-api2 for the hashbrown crate, which is enabled by default for MSRV reasons: even though allocator_api was just stabilised on nightly, we still need it for most users.

However, with the nightly feature, we explicitly do not use this dependency at all, and thus it gets reported as unused. The only way to fix this would be to use --no-default-features alongside the nightly feature, plus every feature except allocator-api2, to avoid the unused dependency.

It would be nice if, in this case, we could simply mark this one case as being acceptable as an unused dependency, rather than completely disabling the lint. Or even expect(...) the lint somehow and acknowledge it.

Steps

No response

Possible Solution(s)

Since the resolver is additive, we should not have some way to disable certain feature combinations, but we could have a way to accept unused dependencies when certain features are enabled. For example, in this case, specifically configure the lint to state that, whenever the nightly feature is enabled, allocator-api2 will be unused. In this case, cargo should be able to determine that, since allocator-api2 is an optional dependency, it will only be unused if it's explicitly enabled.

Notes

No response

Version

cargo 1.100.0-nightly (98a09e7e7 2026-09-21)
release: 1.100.0-nightly
commit-hash: 98a09e7e7d62850f14e5b6132101fc1edd19a16f
commit-date: 2026-09-21
host: x86_64-unknown-linux-gnu
libgit2: 1.9.6 (sys:0.21.0 vendored)
libcurl: 8.21.0-DEV (sys:0.4.90+curl-8.21.0 vendored ssl:OpenSSL/3.6.3)
ssl: OpenSSL 3.6.3 9 Jun 2026
os: Arch Linux Rolling Release [64-bit]

Activity

  1. added
    C-bugCategory: bug
    S-triageStatus: This issue is waiting on initial triage.
    on Sep 24, 2026
  2. epage commented on Sep 24, 2026

    @epage
    Contributor

    rust-lang/rfcs#3920 explored ways to handle this. At the time, we deferred work on it because few use case seemed impacted that it wasn't worth blocking the lint on it.

  3. clarfonthey commented on Sep 24, 2026

    @clarfonthey
    Author

    Yeah, that makes a lot of sense. I mostly just wanted to file an issue for it to track it, since it appears that there weren't any issues in the repo for it.

  4. rktaxe commented on Sep 30, 2026

    @rktaxe

    Would adding use ::allocator_api2 as _; to the rust code do the trick? That hack seems to work for me in similar circumstances.

  5. joshtriplett commented on Sep 30, 2026

    @joshtriplett
    Member

    It seems like this isn't a false positive so much as an unused dependency that would be annoying to remove.

    Rather than figuring out how to disable the line, could we figure out how to simplify disabling the dependency?

  6. clarfonthey commented on Sep 30, 2026

    @clarfonthey
    Author

    That might be hard to do, honestly, since it would break the composability of features. The idea of disabling some dependencies if some features are enabled feels like it would be difficult to reason about.

  7. joshtriplett commented on Sep 30, 2026

    @joshtriplett
    Member

    @clarfonthey I wasn't suggesting we could fix it in the crate. I'm suggesting that we could make it easier to handle "not this default feature" in rust's dependency on it.

  8. added a commit that references this issue on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: rustc lint configurationC-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions