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) {
(lhs, Value::Range { val: rhs, .. }) => Ok(Value::Bool {
val: if rhs
.incr
.gt(
val: if matches!(
rhs.incr.gt(
Span::unknown(),
&Value::Int {
val: 0,
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()),
span: Span::unknown()
}
),
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 {
lhs.lte(Span::unknown(), &rhs.from)
.map_or(false, |v| v.is_true())
&& match rhs.inclusion {
RangeInclusion::Inclusive => lhs
.gte(Span::unknown(), &rhs.to)
.map_or(false, |v| v.is_true()),
RangeInclusion::RightExclusive => lhs
.gt(Span::unknown(), &rhs.to)
.map_or(false, |v| v.is_true()),
}
matches!(
lhs.lte(Span::unknown(), &rhs.from),
Ok(Value::Bool { val: true, .. })
) && match rhs.inclusion {
RangeInclusion::Inclusive => matches!(
lhs.gte(Span::unknown(), &rhs.to),
Ok(Value::Bool { val: true, .. })
),
RangeInclusion::RightExclusive => matches!(
lhs.gt(Span::unknown(), &rhs.to),
Ok(Value::Bool { val: true, .. })
),
}
},
span,