Skip to content

cargo test incorrectly warns for dead code #46379

@jean553

Description

@jean553

Hi!

I got unexpected dead code warnings when executing cargo test with multiple test files. I use a very simple example below that reproduces the issue.

I have two files that contains tests, tests/test_one.rs and tests/test_two.rs. Both contains exactly the same content (except for the unique test function name they contain):

mod routines;

#[test]
fn test_one() {
    routines::my_routine();
}

And another file called tests/routines.rs that simply contains:

pub fn my_routine() {
}

When I execute cargo test, the two tests are executed successfully and there is no raised warning. But if I remove the my_routine() call from one of the two tests, cargo test stills end up successfully but raises a warning on pub fn routine() saying function is never used. However, one test still calls the function, so there is no dead code as stated.

I got the same issue with both rust stable (1.22.1) and rust nightly (1.24.0).

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-cargoRelevant to the cargo team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions