diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index dacfd7c8983b..e5d855c10aa8 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -193,18 +193,19 @@ impl<'a> DigitInfo<'a> { self.suffix.unwrap_or("") ) } else { - let mut hint = self.digits + let filtered_digits_vec = self.digits .chars() - .rev() .filter(|&c| c != '_') - .collect::>() + .rev() + .collect::>(); + let mut hint = filtered_digits_vec .chunks(group_size) .map(|chunk| chunk.into_iter().rev().collect()) .rev() .collect::>() .join("_"); // Forces hexadecimal values to be grouped by 4 being filled with zeroes (e.g 0x00ab_cdef) - let nb_digits_to_fill = self.digits.chars().filter(|&c| c != '_').collect::>().len() % 4; + let nb_digits_to_fill = filtered_digits_vec.len() % 4; if self.radix == Radix::Hexadecimal && nb_digits_to_fill != 0 { hint = format!("{:0>4}{}", &hint[..nb_digits_to_fill], &hint[nb_digits_to_fill..]); }