Skip to content

-Clink-dead-code causes extern crate failure_derive to not be found on Windows #90056

@KarelPeeters

Description

@KarelPeeters

For context, this issue comes up when trying to collect code coverage metrics for projects that depend on certain crates. It was previously reported about a year ago here intellij-rust/intellij-rust#6325 and here mozilla/grcov#502, but the root issue is in rustc. What follows is a minimal reproduction.

For some reason a crate that depends on failure fails to compile when -Clink-dead-code is set, but only on Windows. It works fine when RUSTFLAGS is empty, or on Linux.

To reproduce, run the following commands in Powershell on Windows, in an empty folder:

cargo init
echo 'failure="0.1.8"' >> Cargo.toml
$env:RUSTFLAGS="-Clink-dead-code"
cargo build

The error printed is:

error[E0463]: can't find crate for `failure_derive`
  --> C:\Users\Karel\.cargo\registry\src\github.com-1ecc6299db9ec823\failure-0.1.8\src\lib.rs:56:1
   |
56 | extern crate failure_derive;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

For more information about this error, try `rustc --explain E0463`.

Running cargo clean followed by cargo build -vv has this output: https://gist.githubusercontent.com/KarelPeeters/e5436e18e618dc23a55b9e77ed3c9279/raw/1f4bc3bc76a8e4e52175138a01ee51a1046c4387/gistfile1.txt

This doesn't happen for most crates, I have about 20 dependencies and this issue only comes up with failure/failure_derive for me. In the first issue someone else had the same problem with const_fn = "0.4.2", but I cannot reproduce that.

I tried my own issue on today's stable rustc 1.55.0 (c8dfcfe04 2021-09-06) and nightly rustc 1.58.0-nightly (bd41e09da 2021-10-18) and both Windows and Linux, and this happens for both versions on Windows and for neither version on Linux.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-windowsOperating system: Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions