Skip to content

Commit

Permalink
fix: correctly merge restrictions (#234)
Browse files Browse the repository at this point in the history
Inner restrictions are not being merged correctly right now
  • Loading branch information
klkvr authored Dec 12, 2024
1 parent 2ab992d commit 962b67b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/compilers/src/compilers/restrictions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use semver::VersionReq;
/// Abstraction over set of restrictions for given [`crate::Compiler::Settings`].
pub trait CompilerSettingsRestrictions: Copy + Debug + Sync + Send + Clone + Default {
/// Combines this restriction with another one. Returns `None` if restrictions are incompatible.
#[must_use]
fn merge(self, other: Self) -> Option<Self>;
}

Expand All @@ -20,15 +21,18 @@ pub struct RestrictionsWithVersion<T> {
}

impl<T: CompilerSettingsRestrictions> RestrictionsWithVersion<T> {
pub fn merge(&mut self, other: Self) {
/// Tries to merge the given restrictions with the other [`RestrictionsWithVersion`]. Returns
/// `None` if restrictions are incompatible.
pub fn merge(mut self, other: Self) -> Option<Self> {
if let Some(version) = other.version {
if let Some(self_version) = self.version.as_mut() {
self_version.comparators.extend(version.comparators);
} else {
self.version = Some(version.clone());
}
}
self.restrictions.merge(other.restrictions);
self.restrictions = self.restrictions.merge(other.restrictions)?;
Some(self)
}
}

Expand Down

0 comments on commit 962b67b

Please sign in to comment.