Skip to content

Improve error messages for commonly wrongly-defined target locations #9117

@CPerezz

Description

@CPerezz

The issue is that specifying a bench target like this in Cargo.toml:

[[bench]]
name = "mybench"

And you place the file in bench/mybench.rs, that it returns a confusing error message. The expected location is benches/mybench.rs.

I think there are two parts to improve the message here:

  1. If path is not specified, the error message could include the implicit path in the message, maybe something like this:
Caused by:
  can't find `mybench` bench at `benches/mybench.rs`, specify bench.path if you want to use a non-default path

2. If path is not specified, but there is a file found at a "commonly wrong location" like bench/<name>.rs, there could be a note attached suggesting renaming the directory as another option to fix it.

It would be nice if these better error messages worked for all of the target types (testtests and exampleexamples and maybe src/binssrc/bin).

Originally posted by @ehuss in #9014 (comment)

Point 1. and the final suggestion of extending the behavior to all the target types was addressed in #9116.

This issue is specifically focused in 2.s suggestion of checking "commonly wrong location" to improve the error output.

Metadata

Metadata

Assignees

No one assigned

    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-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions