Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow depending on self #244

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}