Skip to content

Lint for source files being in subpackage/ rather than subpackage/src/, when workspace includes subpackage/Cargo.toml #16789

@Pr0methean

Description

@Pr0methean

What it does

I finally discovered today, after extensive trial and error, and after consulting JetBrains Junie before finally noticing the answer in a Google Gemini response, that the reason RustRover was failing to load my benchmark package's dependencies from benches/Cargo.toml was that it was expecting their source code to be in benches/src/benchmarks.rs rather than benches/benchmarks.rs, which is where I had it.

Advantage

  • Make it much easier to use all kinds of tools in multi-Cargo.toml workspaces.
  • Eliminate guesswork about seemingly-likely solutions that don't work (e.g. moving the benchmarks' dependencies from [dependencies] to [dev-dependencies].

Drawbacks

May need some exclusion rules to deal with Cargo.toml's that are specifically adapted to being siblings of the *.rs files in the directory tree rather than uncles via ./src.

Example

$ ls -r
Cargo.toml
benches

benches/
Cargo.toml
benchmarks.rs

In Cargo.toml:

[workspace]
members = [
    ".",        # The main crate in the current directory
    "benches",  # The new benchmark-only crate
]

In benches/Cargo.toml:

[[bench]]
name = "benchmarks"
path = "benchmarks.rs"

Could be written as:

$ ls -r
Cargo.toml
benches

benches/
Cargo.toml
src

benches/src/
benchmarks.rs

In benches/Cargo.toml:

[[bench]]
name = "benchmarks"
path = "src/benchmarks.rs"

Comparison with existing lints

AFAICT no lints currently evaluate the directory structure of a workspace.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    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