Skip to content

Commit b75b705

Browse files
committed
Add package_path to ResolveError
More useful than just the parent
1 parent 50cbb96 commit b75b705

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/cargo/core/resolver/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,9 +826,18 @@ fn activation_error(
826826
candidates: &[Candidate],
827827
config: Option<&Config>,
828828
) -> ResolveError {
829-
let to_resolve_err = |err| ResolveError::new(err, parent.package_id().clone());
830-
831829
let graph = cx.graph();
830+
let to_resolve_err = |err| {
831+
ResolveError::new(
832+
err,
833+
graph
834+
.path_to_top(parent.package_id())
835+
.into_iter()
836+
.cloned()
837+
.collect(),
838+
)
839+
};
840+
832841
if !candidates.is_empty() {
833842
let mut msg = format!("failed to select a version for `{}`.", dep.package_name());
834843
msg.push_str("\n ... required by ");

src/cargo/util/errors.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,26 +135,26 @@ impl<'a> Iterator for ManifestCauses<'a> {
135135

136136
impl<'a> ::std::iter::FusedIterator for ManifestCauses<'a> {}
137137

138-
/// Error during resolution providing the `PackageId` for the package
139-
/// whose requirements could not be resolved.
138+
/// Error during resolution providing a path of `PackageId`s.
140139
///
141140
/// This error adds no displayable info of it's own.
142141
pub struct ResolveError {
143142
cause: Error,
144-
parent_package: PackageId,
143+
package_path: Vec<PackageId>,
145144
}
146145

147146
impl ResolveError {
148-
pub fn new<E: Into<Error>>(cause: E, parent_package: PackageId) -> Self {
147+
pub fn new<E: Into<Error>>(cause: E, package_path: Vec<PackageId>) -> Self {
149148
Self {
150149
cause: cause.into(),
151-
parent_package,
150+
package_path,
152151
}
153152
}
154153

155-
/// Returns the id of the package whose requirements could not be resolved.
156-
pub fn parent_package_id(&self) -> &PackageId {
157-
&self.parent_package
154+
/// Returns a path of packages from the package whose requirements could not be resolved up to
155+
/// the root.
156+
pub fn package_path(&self) -> &[PackageId] {
157+
&self.package_path
158158
}
159159
}
160160

tests/testsuite/member_errors.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,7 @@ fn member_manifest_version_error() {
150150
eprintln!("{:?}", error);
151151

152152
let resolve_err: &ResolveError = error.downcast_ref().expect("Not a ResolveError");
153-
assert_eq!(resolve_err.parent_package_id(), member_bar.package_id());
153+
let package_path = resolve_err.package_path();
154+
assert_eq!(package_path.len(), 1, "package_path: {:?}", package_path);
155+
assert_eq!(&package_path[0], member_bar.package_id());
154156
}

0 commit comments

Comments
 (0)