Skip to content

Commit

Permalink
Fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
recmo committed Apr 19, 2023
1 parent 10b109b commit baa8d83
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
7 changes: 7 additions & 0 deletions proptest-regressions/support/serde.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc b34f1b17adb53173b16f69b09bdd23f9c774b910bce652327f58f8e45adb3253 # shrinks to value = 0x_U0
9 changes: 3 additions & 6 deletions ruint-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,16 @@ fn parse_suffix(source: &str) -> Option<(LiteralBaseType, usize, &str)> {
/// Transforms a [`Literal`] and returns the substitute [`TokenStream`].
fn transform_literal(source: &str) -> Result<Option<TokenStream>, String> {
// Check if literal has a suffix we accept
let (base_type, bits, value) = match parse_suffix(source) {
Some(x) => x,
None => return Ok(None),
let Some((base_type, bits, value)) = parse_suffix(source) else {
return Ok(None);
};

// Parse `value` into limbs.
// At this point we are confident the literal was for us, so we throw errors.
let limbs = parse_digits(value)?;

// Pad limbs to the correct length.
let limbs = if let Some(limbs) = pad_limbs(bits, limbs) {
limbs
} else {
let Some(limbs) = pad_limbs(bits, limbs) else {
let value = value.trim_end_matches('_');
return Err(format!("Value too large for {base_type}<{bits}>: {value}"));
};
Expand Down
4 changes: 2 additions & 2 deletions src/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
/// # use ruint::{Uint, uint, aliases::*};
/// # uint!{
/// assert_eq!(U8::saturating_from(300_u16), 255_U8);
/// assert_eq!(U8::saturating_from(-10_i16), 0_U8);
/// assert_eq!(U8::saturating_from(-10_i16), 0_U8);
/// assert_eq!(U32::saturating_from(0x7014b4c2d1f2_U256), U32::MAX);
/// # }
/// ```
Expand All @@ -147,7 +147,7 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
/// ```
/// # use ruint::{Uint, uint, aliases::*};
/// # uint!{
/// assert_eq!(U8::wrapping_from(300_u16), 44_U8);
/// assert_eq!(U8::wrapping_from(300_u16), 44_U8);
/// assert_eq!(U8::wrapping_from(-10_i16), 246_U8);
/// assert_eq!(U32::wrapping_from(0x7014b4c2d1f2_U256), 0xb4c2d1f2_U32);
/// # }
Expand Down
5 changes: 4 additions & 1 deletion src/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
/// # use ruint::{Uint, uint};
/// # uint!{
/// assert_eq!(1_U1.overflowing_mul(1_U1), (1_U1, false));
/// assert_eq!(0x010000000000000000_U65.overflowing_mul(0x010000000000000000_U65), (0x000000000000000000_U65, true));
/// assert_eq!(
/// 0x010000000000000000_U65.overflowing_mul(0x010000000000000000_U65),
/// (0x000000000000000000_U65, true)
/// );
/// # }
/// ```
#[must_use]
Expand Down
15 changes: 12 additions & 3 deletions src/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ impl<const BITS: usize, const LIMBS: usize> Uint<BITS, LIMBS> {
/// ```
/// # use ruint::{Uint, uint};
/// # uint!{
/// assert_eq!(36_U64.overflowing_pow(12_U64), (0x41c21cb8e1000000_U64, false));
/// assert_eq!(36_U64.overflowing_pow(13_U64), (0x3f4c09ffa4000000_U64, true));
/// assert_eq!(36_U68.overflowing_pow(13_U68), (0x093f4c09ffa4000000_U68, false));
/// assert_eq!(
/// 36_U64.overflowing_pow(12_U64),
/// (0x41c21cb8e1000000_U64, false)
/// );
/// assert_eq!(
/// 36_U64.overflowing_pow(13_U64),
/// (0x3f4c09ffa4000000_U64, true)
/// );
/// assert_eq!(
/// 36_U68.overflowing_pow(13_U68),
/// (0x093f4c09ffa4000000_U68, false)
/// );
/// assert_eq!(16_U65.overflowing_pow(32_U65), (0_U65, true));
/// # }
/// ```
Expand Down
8 changes: 4 additions & 4 deletions src/support/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ impl<'de, const BITS: usize, const LIMBS: usize> Visitor<'de> for StrVisitor<BIT
if BITS == 0 {
// special case, this class of ints has one member, zero.
// zero is represented as "0x0" only
if value == "0" {
return Ok(Uint::<BITS, LIMBS>::ZERO);
} else {
if value != "0" {
return Err(Error::invalid_value(Unexpected::Str(value), &self));
}
} else if nbytes(BITS) * 2 < value.len() {
return Ok(Uint::<BITS, LIMBS>::ZERO);
}
if nbytes(BITS) * 2 < value.len() {
return Err(Error::invalid_length(value.len(), &self));
}

Expand Down

0 comments on commit baa8d83

Please sign in to comment.