Skip to content

Seeing "warning: file found to be present in multiple build targets" when file is actually *not present* in multiple targets #11248

@nasadorian

Description

@nasadorian

Problem

I've seen numerous issues related to this warning, however I believe I've found a bug with it. I have two binaries listed in my [[bin]] table, each with a different main file. When one of the files is in the tests directory, the warning surfaces. However when both files are under src, there is no warning. Cargo seems to be complaining about a non-problematic usage of the binary table. Please see example in repro section.

Steps

Configuration 1: Warning occurs when test_server.rs lives in tests directory.

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

[[bin]]
name = "example"
path = "src/server.rs"

[[bin]]
name = "example-for-test"
path = "tests/test_server.rs"
├── Cargo.lock
├── Cargo.toml
├── src
 │  └── server.rs
└── tests
    └── test_server.rs
$ cargo check
warning: file found to be present in multiple build targets: /private/tmp/example/tests/test_server.rs
    Checking example v0.1.0 (/private/tmp/example)
    Finished dev [unoptimized + debuginfo] target(s) in 0.39s

Configuration 2: Warning not raised when test_server.rs is placed in src.

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

[[bin]]
name = "example"
path = "src/server.rs"

[[bin]]
name = "example-for-test"
path = "src/test_server.rs"

[dependencies]
.
├── Cargo.lock
├── Cargo.toml
├── src
 │  ├── server.rs
 │  └── test_server.rs
└── tests
$ cargo check
    Checking example v0.1.0 (/private/tmp/example)
    Finished dev [unoptimized + debuginfo] target(s) in 0.38s

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.63.0 (fd9c4297c 2022-07-01)

Metadata

Metadata

Assignees

Labels

A-cargo-targetsArea: selection and definition of targets (lib, bins, examples, tests, benches)A-diagnosticsArea: Error and warning messages generated by Cargo itself.C-enhancementCategory: enhancementE-easyExperience: Easy

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions