Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
d0cd committed Apr 2, 2024
1 parent f6fde0d commit 26dba19
Show file tree
Hide file tree
Showing 4 changed files with 899 additions and 70 deletions.
18 changes: 5 additions & 13 deletions compiler/ast/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,20 +765,12 @@ impl TryFrom<&Value> for i128 {
fn try_from(value: &Value) -> Result<Self, Self::Error> {
use Value::*;
match value {
U8(val, span) => {
i128::try_from(*val).map_err(|_| FlattenError::loop_has_neg_value(Type::from(value), *span).into())
}
U16(val, span) => {
i128::try_from(*val).map_err(|_| FlattenError::loop_has_neg_value(Type::from(value), *span).into())
}
U32(val, span) => {
i128::try_from(*val).map_err(|_| FlattenError::loop_has_neg_value(Type::from(value), *span).into())
}
U64(val, span) => {
i128::try_from(*val).map_err(|_| FlattenError::loop_has_neg_value(Type::from(value), *span).into())
}
U8(val, _) => Ok(*val as i128),
U16(val, _) => Ok(*val as i128),
U32(val, _) => Ok(*val as i128),
U64(val, _) => Ok(*val as i128),
U128(val, span) => {
i128::try_from(*val).map_err(|_| FlattenError::loop_has_neg_value(Type::from(value), *span).into())
i128::try_from(*val).map_err(|_| FlattenError::u128_to_i128(Type::from(value), *span).into())
}
I8(val, _) => Ok(*val as i128),
I16(val, _) => Ok(*val as i128),
Expand Down
10 changes: 10 additions & 0 deletions errors/src/errors/flattener/flattener_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ create_messages!(
),
help: None,
}

/// For when a u128 value cannot be converted into an i128.
@formatted
u128_to_i128 {
args: (value: impl Display),
msg: format!(
"The value `{value}` cannot be converted into an i128.",
),
help: None,
}
);
Loading

0 comments on commit 26dba19

Please sign in to comment.