Skip to content

Commit

Permalink
feat: allow depending on self
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Jul 31, 2024
1 parent 42ad7ea commit c32ba3e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 29 deletions.
18 changes: 0 additions & 18 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,6 @@ pub enum PubGrubError<DP: DependencyProvider> {
source: DP::Err,
},

/// Error arising when the implementer of
/// [DependencyProvider]
/// returned a dependency on the requested package.
/// This technically means that the package directly depends on itself,
/// and is clearly some kind of mistake.
#[error("{package} {version} depends on itself")]
SelfDependency {
/// Package whose dependencies we want.
package: DP::P,
/// Version of the package for which we want the dependencies.
version: DP::V,
},

/// Error arising when the implementer of [DependencyProvider] returned an error in the method
/// [choose_version](DependencyProvider::choose_version).
#[error("Decision making failed")]
Expand Down Expand Up @@ -84,11 +71,6 @@ where
.field("version", version)
.field("source", source)
.finish(),
Self::SelfDependency { package, version } => f
.debug_struct("SelfDependency")
.field("package", package)
.field("version", version)
.finish(),
Self::ErrorChoosingPackageVersion(arg0) => f
.debug_tuple("ErrorChoosingPackageVersion")
.field(arg0)
Expand Down
6 changes: 0 additions & 6 deletions src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,6 @@ pub fn resolve<DP: DependencyProvider>(
));
continue;
}
Dependencies::Available(x) if x.contains_key(p) => {
return Err(PubGrubError::SelfDependency {
package: p.clone(),
version: v,
});
}
Dependencies::Available(x) => x,
};

Expand Down
9 changes: 4 additions & 5 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ fn should_always_find_a_satisfier() {
}

#[test]
fn cannot_depend_on_self() {
fn depend_on_self() {
let mut dependency_provider = OfflineDependencyProvider::<_, NumVS>::new();
dependency_provider.add_dependencies("a", 0u32, [("a", Range::full())]);
assert!(matches!(
resolve(&dependency_provider, "a", 0u32),
Err(PubGrubError::SelfDependency { .. })
));
assert!(resolve(&dependency_provider, "a", 0u32).is_ok());
dependency_provider.add_dependencies("a", 66u32, [("a", Range::singleton(111u32))]);
assert!(resolve(&dependency_provider, "a", 66u32).is_err());
}

0 comments on commit c32ba3e

Please sign in to comment.