Skip to content

Commit

Permalink
Improve error messages for wrong target paths
Browse files Browse the repository at this point in the history
As it was stated in rust-lang#9014 it's not really useful the message
that you get when using `bench/your_bench.rs` instead of the
correct path `benches/your_bench.rs`.

Therefore, as @ehuss suggested, the error message has been improved
not only suggesting the correct path but also suggesting to
specify `bench.path` in `Cargo.toml` for non-default path usage.
And this has been exented to `test`, `example` and `bin`.
  • Loading branch information
CPerezz committed Jan 31, 2021
1 parent c3abcfe commit 9ae5239
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/cargo/util/toml/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,18 @@ fn target_path(
return Ok(path);
}
}
let target_folder_name = match target_kind {
"test" => "tests",
"bench" => "benches",
"example" => "examples",
"bins" => "bin",
_ => target_kind,
};
Err(format!(
"can't find `{name}` {target_kind}, specify {target_kind}.path",
"can't find `{name}` {target_kind} at `{target_folder_name}/{name}`, specify {target_kind}.path if you want to use a non-default path",
name = name,
target_kind = target_kind
target_kind = target_kind,
target_folder_name = target_folder_name,
))
}
(None, Some(_)) => unreachable!(),
Expand Down

0 comments on commit 9ae5239

Please sign in to comment.