Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add flag to warn about unused dependencies #8437

Closed
wants to merge 4 commits into from

Commits on Apr 5, 2021

  1. Return (Result<(),E>,) in drain_the_queue

    This refactors the drain_the_queue function to return a
    tuple containing Result. That way, it's still not
    possible to use ? or try! to handle errors,
    but for readers of the function declaration it's
    clearer now that the error actually indicates one.
    
    Bonus: it makes the calling code of drain_the_queue simpler.
    est31 committed Apr 5, 2021
    Configuration menu
    Copy the full SHA
    30a6d21 View commit details
    Browse the repository at this point in the history

Commits on Apr 6, 2021

  1. Add flag to warn about unused dependencies

    This commit adds an experimental flag to cargo, -Zwarn-unused-deps,
    with the goal of getting it eventually stabilized and enabled by
    default.
    
    The lint builds upon the --json=unused-externs flag of rustc
    that is being proposed for this purpose.
    This commit makes cargo pass the flag if -Zwarn-unused-deps is enabled
    to compilations of units it prints warnings for.
    
    During compilation, code collects the unused dependencies
    from all units, converts them into used dependencies,
    continuously extending the record of used dependencies for
    any type of DepKind: [dependencies], [dev-dependencies] and
    [build-dependencies].
    
    Once the compilation has ended, this record is used to
    obtain those dependencies in a class that weren't used by any unit,
    and warn about them.
    
    The goal is to stabilize the flag and enable it by default
    once the lint has become robust and the robustness is proven.
    
    Then, cargo shall opportunistically warn about unused dependencies
    when it has compiled (or loaded the unused externs from cache of)
    all units that could possibly use dependencies of the kind.
    Roughly, it's like this:
      * cargo always compiles build.rs
      * cargo check compiles all units that would use [dependencies]
      * cargo test --no-run --all-targets compiles all units that can use
        [dev-dependencies]... except for the benches
      * cargo check --all-targets compiles all units that can use
        [dev-dependencies]... except for the doctests
    est31 committed Apr 6, 2021
    Configuration menu
    Copy the full SHA
    6a1697c View commit details
    Browse the repository at this point in the history
  2. Support doctests

    est31 committed Apr 6, 2021
    Configuration menu
    Copy the full SHA
    7bccfc3 View commit details
    Browse the repository at this point in the history
  3. Support specifying different lint levels

    Specifying via the command line is not possible for now because cargo
    currently has to pass -W via the command line, but once the lint
    is set to warn by default, this won't be needed :).
    est31 committed Apr 6, 2021
    Configuration menu
    Copy the full SHA
    c0e3e5a View commit details
    Browse the repository at this point in the history