Skip to content

Commit 577968e

Browse files
committed
cargo fmt
1 parent 1e9bd72 commit 577968e

File tree

1 file changed

+98
-96
lines changed

1 file changed

+98
-96
lines changed

src/cargo/core/resolver/errors.rs

Lines changed: 98 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -203,113 +203,115 @@ pub(super) fn activation_error(
203203
};
204204
candidates.sort_unstable_by(|a, b| b.version().cmp(a.version()));
205205

206-
let mut msg = if !candidates.is_empty() {
207-
let versions = {
208-
let mut versions = candidates
209-
.iter()
210-
.take(3)
211-
.map(|cand| cand.version().to_string())
212-
.collect::<Vec<_>>();
213-
214-
if candidates.len() > 3 {
215-
versions.push("...".into());
216-
}
217-
218-
versions.join(", ")
219-
};
220-
221-
let mut msg = format!(
222-
"failed to select a version for the requirement `{} = \"{}\"`\n \
223-
candidate versions found which didn't match: {}\n \
224-
location searched: {}\n",
225-
dep.package_name(),
226-
dep.version_req(),
227-
versions,
228-
registry.describe_source(dep.source_id()),
229-
);
230-
msg.push_str("required by ");
231-
msg.push_str(&describe_path(
232-
&cx.parents.path_to_bottom(&parent.package_id()),
233-
));
234-
235-
// If we have a path dependency with a locked version, then this may
236-
// indicate that we updated a sub-package and forgot to run `cargo
237-
// update`. In this case try to print a helpful error!
238-
if dep.source_id().is_path() && dep.version_req().to_string().starts_with('=') {
239-
msg.push_str(
240-
"\nconsider running `cargo update` to update \
241-
a path dependency's locked version",
242-
);
243-
}
244-
245-
if registry.is_replaced(dep.source_id()) {
246-
msg.push_str("\nperhaps a crate was updated and forgotten to be re-vendored?");
247-
}
248-
249-
msg
250-
} else {
251-
// Maybe the user mistyped the name? Like `dep-thing` when `Dep_Thing`
252-
// was meant. So we try asking the registry for a `fuzzy` search for suggestions.
253-
let mut candidates = Vec::new();
254-
if let Err(e) = registry.query(&new_dep, &mut |s| candidates.push(s.clone()), true) {
255-
return to_resolve_err(e);
256-
};
257-
candidates.sort_unstable_by(|a, b| a.name().cmp(&b.name()));
258-
candidates.dedup_by(|a, b| a.name() == b.name());
259-
let mut candidates: Vec<_> = candidates
260-
.iter()
261-
.map(|n| (lev_distance(&*new_dep.package_name(), &*n.name()), n))
262-
.filter(|&(d, _)| d < 4)
263-
.collect();
264-
candidates.sort_by_key(|o| o.0);
265-
let mut msg = format!(
266-
"no matching package named `{}` found\n\
267-
location searched: {}\n",
268-
dep.package_name(),
269-
dep.source_id()
270-
);
206+
let mut msg =
271207
if !candidates.is_empty() {
272-
// If dependency package name is equal to the name of the candidate here
273-
// it may be a prerelease package which hasn't been speficied correctly
274-
if dep.package_name() == candidates[0].1.name() &&
275-
candidates[0].1.package_id().version().is_prerelease() {
276-
msg.push_str("prerelease package needs to be specified explicitly\n");
277-
msg.push_str(&format!(
278-
"{name} = {{ version = \"{version}\" }}",
279-
name = candidates[0].1.name(),
280-
version = candidates[0].1.package_id().version()
281-
));
282-
} else {
283-
let mut names = candidates
208+
let versions = {
209+
let mut versions = candidates
284210
.iter()
285211
.take(3)
286-
.map(|c| c.1.name().as_str())
212+
.map(|cand| cand.version().to_string())
287213
.collect::<Vec<_>>();
288214

289215
if candidates.len() > 3 {
290-
names.push("...");
216+
versions.push("...".into());
291217
}
292218

293-
msg.push_str("perhaps you meant: ");
294-
msg.push_str(&names.iter().enumerate().fold(
295-
String::default(),
296-
|acc, (i, el)| match i {
297-
0 => acc + el,
298-
i if names.len() - 1 == i && candidates.len() <= 3 => acc + " or " + el,
299-
_ => acc + ", " + el,
300-
},
301-
));
219+
versions.join(", ")
220+
};
221+
222+
let mut msg = format!(
223+
"failed to select a version for the requirement `{} = \"{}\"`\n \
224+
candidate versions found which didn't match: {}\n \
225+
location searched: {}\n",
226+
dep.package_name(),
227+
dep.version_req(),
228+
versions,
229+
registry.describe_source(dep.source_id()),
230+
);
231+
msg.push_str("required by ");
232+
msg.push_str(&describe_path(
233+
&cx.parents.path_to_bottom(&parent.package_id()),
234+
));
235+
236+
// If we have a path dependency with a locked version, then this may
237+
// indicate that we updated a sub-package and forgot to run `cargo
238+
// update`. In this case try to print a helpful error!
239+
if dep.source_id().is_path() && dep.version_req().to_string().starts_with('=') {
240+
msg.push_str(
241+
"\nconsider running `cargo update` to update \
242+
a path dependency's locked version",
243+
);
302244
}
303245

304-
msg.push_str("\n");
305-
}
306-
msg.push_str("required by ");
307-
msg.push_str(&describe_path(
308-
&cx.parents.path_to_bottom(&parent.package_id()),
309-
));
246+
if registry.is_replaced(dep.source_id()) {
247+
msg.push_str("\nperhaps a crate was updated and forgotten to be re-vendored?");
248+
}
310249

311-
msg
312-
};
250+
msg
251+
} else {
252+
// Maybe the user mistyped the name? Like `dep-thing` when `Dep_Thing`
253+
// was meant. So we try asking the registry for a `fuzzy` search for suggestions.
254+
let mut candidates = Vec::new();
255+
if let Err(e) = registry.query(&new_dep, &mut |s| candidates.push(s.clone()), true) {
256+
return to_resolve_err(e);
257+
};
258+
candidates.sort_unstable_by(|a, b| a.name().cmp(&b.name()));
259+
candidates.dedup_by(|a, b| a.name() == b.name());
260+
let mut candidates: Vec<_> = candidates
261+
.iter()
262+
.map(|n| (lev_distance(&*new_dep.package_name(), &*n.name()), n))
263+
.filter(|&(d, _)| d < 4)
264+
.collect();
265+
candidates.sort_by_key(|o| o.0);
266+
let mut msg = format!(
267+
"no matching package named `{}` found\n\
268+
location searched: {}\n",
269+
dep.package_name(),
270+
dep.source_id()
271+
);
272+
if !candidates.is_empty() {
273+
// If dependency package name is equal to the name of the candidate here
274+
// it may be a prerelease package which hasn't been speficied correctly
275+
if dep.package_name() == candidates[0].1.name()
276+
&& candidates[0].1.package_id().version().is_prerelease()
277+
{
278+
msg.push_str("prerelease package needs to be specified explicitly\n");
279+
msg.push_str(&format!(
280+
"{name} = {{ version = \"{version}\" }}",
281+
name = candidates[0].1.name(),
282+
version = candidates[0].1.package_id().version()
283+
));
284+
} else {
285+
let mut names = candidates
286+
.iter()
287+
.take(3)
288+
.map(|c| c.1.name().as_str())
289+
.collect::<Vec<_>>();
290+
291+
if candidates.len() > 3 {
292+
names.push("...");
293+
}
294+
295+
msg.push_str("perhaps you meant: ");
296+
msg.push_str(&names.iter().enumerate().fold(
297+
String::default(),
298+
|acc, (i, el)| match i {
299+
0 => acc + el,
300+
i if names.len() - 1 == i && candidates.len() <= 3 => acc + " or " + el,
301+
_ => acc + ", " + el,
302+
},
303+
));
304+
}
305+
306+
msg.push_str("\n");
307+
}
308+
msg.push_str("required by ");
309+
msg.push_str(&describe_path(
310+
&cx.parents.path_to_bottom(&parent.package_id()),
311+
));
312+
313+
msg
314+
};
313315

314316
if let Some(config) = config {
315317
if config.offline() {

0 commit comments

Comments
 (0)