Simplify Result<Value, _> comparaison using matches!

This commit is contained in:
Arthur Targaryen 2021-10-09 01:31:18 +02:00
parent d3bc096d47
commit 7db6b876ab

View file

@ -1020,38 +1020,43 @@ impl Value {
match (self, rhs) { match (self, rhs) {
(lhs, Value::Range { val: rhs, .. }) => Ok(Value::Bool { (lhs, Value::Range { val: rhs, .. }) => Ok(Value::Bool {
val: if rhs val: if matches!(
.incr rhs.incr.gt(
.gt(
Span::unknown(), Span::unknown(),
&Value::Int { &Value::Int {
val: 0, val: 0,
span: Span::unknown(), span: Span::unknown()
},
)
.map_or(false, |v| v.is_true())
{
lhs.gte(Span::unknown(), &rhs.from)
.map_or(false, |v| v.is_true())
&& match rhs.inclusion {
RangeInclusion::Inclusive => lhs
.lte(Span::unknown(), &rhs.to)
.map_or(false, |v| v.is_true()),
RangeInclusion::RightExclusive => lhs
.lt(Span::unknown(), &rhs.to)
.map_or(false, |v| v.is_true()),
} }
),
Ok(Value::Bool { val: true, .. })
) {
matches!(
lhs.gte(Span::unknown(), &rhs.from),
Ok(Value::Bool { val: true, .. })
) && match rhs.inclusion {
RangeInclusion::Inclusive => matches!(
lhs.lte(Span::unknown(), &rhs.to),
Ok(Value::Bool { val: true, .. })
),
RangeInclusion::RightExclusive => matches!(
lhs.lt(Span::unknown(), &rhs.to),
Ok(Value::Bool { val: true, .. })
),
}
} else { } else {
lhs.lte(Span::unknown(), &rhs.from) matches!(
.map_or(false, |v| v.is_true()) lhs.lte(Span::unknown(), &rhs.from),
&& match rhs.inclusion { Ok(Value::Bool { val: true, .. })
RangeInclusion::Inclusive => lhs ) && match rhs.inclusion {
.gte(Span::unknown(), &rhs.to) RangeInclusion::Inclusive => matches!(
.map_or(false, |v| v.is_true()), lhs.gte(Span::unknown(), &rhs.to),
RangeInclusion::RightExclusive => lhs Ok(Value::Bool { val: true, .. })
.gt(Span::unknown(), &rhs.to) ),
.map_or(false, |v| v.is_true()), RangeInclusion::RightExclusive => matches!(
} lhs.gt(Span::unknown(), &rhs.to),
Ok(Value::Bool { val: true, .. })
),
}
}, },
span, span,