Skip to content

Commit 962b67b

Browse files
authored
fix: correctly merge restrictions (#234)
Inner restrictions are not being merged correctly right now
1 parent 2ab992d commit 962b67b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

crates/compilers/src/compilers/restrictions.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use semver::VersionReq;
88
/// Abstraction over set of restrictions for given [`crate::Compiler::Settings`].
99
pub trait CompilerSettingsRestrictions: Copy + Debug + Sync + Send + Clone + Default {
1010
/// Combines this restriction with another one. Returns `None` if restrictions are incompatible.
11+
#[must_use]
1112
fn merge(self, other: Self) -> Option<Self>;
1213
}
1314

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

2223
impl<T: CompilerSettingsRestrictions> RestrictionsWithVersion<T> {
23-
pub fn merge(&mut self, other: Self) {
24+
/// Tries to merge the given restrictions with the other [`RestrictionsWithVersion`]. Returns
25+
/// `None` if restrictions are incompatible.
26+
pub fn merge(mut self, other: Self) -> Option<Self> {
2427
if let Some(version) = other.version {
2528
if let Some(self_version) = self.version.as_mut() {
2629
self_version.comparators.extend(version.comparators);
2730
} else {
2831
self.version = Some(version.clone());
2932
}
3033
}
31-
self.restrictions.merge(other.restrictions);
34+
self.restrictions = self.restrictions.merge(other.restrictions)?;
35+
Some(self)
3236
}
3337
}
3438

0 commit comments

Comments
 (0)