mirror of
https://github.com/rust-lang/cargo
synced 2024-11-05 18:50:39 +00:00
Improve error message for wrong target names
This commit is contained in:
parent
0c57749ca3
commit
abb463a7aa
1 changed files with 35 additions and 13 deletions
|
@ -23,6 +23,7 @@
|
|||
//! repeats until the queue is empty.
|
||||
|
||||
use std::collections::{BTreeSet, HashMap, HashSet};
|
||||
use std::fmt::Write;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -1526,19 +1527,40 @@ fn find_named_targets<'a>(
|
|||
};
|
||||
|
||||
if proposals.is_empty() {
|
||||
let targets = packages.iter().flat_map(|pkg| {
|
||||
pkg.targets()
|
||||
.iter()
|
||||
.filter(|target| is_expected_kind(target))
|
||||
});
|
||||
let suggestion = closest_msg(target_name, targets, |t| t.name());
|
||||
anyhow::bail!(
|
||||
"no {} target {} `{}`{}",
|
||||
target_desc,
|
||||
if is_glob { "matches pattern" } else { "named" },
|
||||
target_name,
|
||||
suggestion
|
||||
);
|
||||
let targets = packages
|
||||
.iter()
|
||||
.flat_map(|pkg| {
|
||||
pkg.targets()
|
||||
.iter()
|
||||
.filter(|target| is_expected_kind(target))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let suggestion = closest_msg(target_name, targets.iter(), |t| t.name());
|
||||
if !suggestion.is_empty() {
|
||||
anyhow::bail!(
|
||||
"no {} target {} `{}`{}",
|
||||
target_desc,
|
||||
if is_glob { "matches pattern" } else { "named" },
|
||||
target_name,
|
||||
suggestion
|
||||
);
|
||||
} else {
|
||||
let mut msg = String::new();
|
||||
writeln!(
|
||||
msg,
|
||||
"no {} target {} `{}`.",
|
||||
target_desc,
|
||||
if is_glob { "matches pattern" } else { "named" },
|
||||
target_name,
|
||||
)?;
|
||||
if !targets.is_empty() {
|
||||
writeln!(msg, "Available {} targets:", target_desc)?;
|
||||
for target in targets {
|
||||
writeln!(msg, " {}", target.name())?;
|
||||
}
|
||||
}
|
||||
anyhow::bail!(msg);
|
||||
}
|
||||
}
|
||||
Ok(proposals)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue