From 5233bf5d9aca2ac7160a75842e018004d562da82 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Thu, 12 Dec 2024 23:04:01 +0400 Subject: [PATCH] fix: correctly merge restrictions --- crates/compilers/src/compilers/restrictions.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/compilers/src/compilers/restrictions.rs b/crates/compilers/src/compilers/restrictions.rs index acfcf29b1..8d6ab3a12 100644 --- a/crates/compilers/src/compilers/restrictions.rs +++ b/crates/compilers/src/compilers/restrictions.rs @@ -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; } @@ -20,7 +21,9 @@ pub struct RestrictionsWithVersion { } impl RestrictionsWithVersion { - 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 { if let Some(version) = other.version { if let Some(self_version) = self.version.as_mut() { self_version.comparators.extend(version.comparators); @@ -28,7 +31,8 @@ impl RestrictionsWithVersion { self.version = Some(version.clone()); } } - self.restrictions.merge(other.restrictions); + self.restrictions = self.restrictions.merge(other.restrictions)?; + Some(self) } }