Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
CPerezz opened this issue Jan 31, 2021 · 0 comments · Fixed by #10090
Closed

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

CPerezz opened this issue Jan 31, 2021 · 0 comments · Fixed by #10090
Labels
A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) A-diagnostics Area: Error and warning messages generated by Cargo itself. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@CPerezz
Copy link
Contributor

CPerezz commented Jan 31, 2021

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.

@CPerezz CPerezz added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Jan 31, 2021
@ehuss ehuss added A-diagnostics Area: Error and warning messages generated by Cargo itself. A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) labels Feb 13, 2021
@bors bors closed this as completed in aed9723 Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) A-diagnostics Area: Error and warning messages generated by Cargo itself. C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants