Skip to content

Fix clippy lints #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ macro_rules! ascii_alu {
$src_unit:ty,
$dst_unit:ty,
$stride_fn:ident) => {
#[cfg_attr(feature = "cargo-clippy", allow(never_loop, cast_ptr_alignment))]
#[cfg_attr(
feature = "cargo-clippy",
allow(clippy::never_loop, clippy::cast_ptr_alignment)
)]
#[inline(always)]
pub unsafe fn $name(
src: *const $src_unit,
Expand Down Expand Up @@ -183,7 +186,7 @@ macro_rules! basic_latin_alu {
$stride_fn:ident) => {
#[cfg_attr(
feature = "cargo-clippy",
allow(never_loop, cast_ptr_alignment, cast_lossless)
allow(clippy::never_loop, clippy::cast_ptr_alignment, clippy::cast_lossless)
)]
#[inline(always)]
pub unsafe fn $name(
Expand Down Expand Up @@ -282,7 +285,7 @@ macro_rules! latin1_alu {
($name:ident, $src_unit:ty, $dst_unit:ty, $stride_fn:ident) => {
#[cfg_attr(
feature = "cargo-clippy",
allow(never_loop, cast_ptr_alignment, cast_lossless)
allow(clippy::never_loop, clippy::cast_ptr_alignment, clippy::cast_lossless)
)]
#[inline(always)]
pub unsafe fn $name(src: *const $src_unit, dst: *mut $dst_unit, len: usize) {
Expand Down Expand Up @@ -1374,7 +1377,7 @@ cfg_if! {
find_non_ascii(word, second_word)
}

#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
#[cfg_attr(feature = "cargo-clippy", allow(clippy::cast_ptr_alignment))]
#[inline(always)]
pub fn validate_ascii(slice: &[u8]) -> Option<(u8, usize)> {
let src = slice.as_ptr();
Expand Down
2 changes: 1 addition & 1 deletion src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ pub static SINGLE_BYTE_DATA: SingleByteData = SingleByteData {
],
};

#[cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
#[cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal))]
static BIG5_ASTRALNESS: [u32; 589] = [
0x445F0520, 0xB882520F, 0x400000F8, 0x044EA920, 0x00000000, 0x00010B34, 0x00000000, 0x00000000,
0x00000000, 0x0C000000, 0x00000040, 0x00000000, 0x00580400, 0x0000003C, 0x5C800000, 0xBBF3DCAD,
Expand Down
5 changes: 1 addition & 4 deletions src/euc_jp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ enum EucJpPending {

impl EucJpPending {
fn is_none(&self) -> bool {
match *self {
EucJpPending::None => true,
_ => false,
}
matches!(*self, EucJpPending::None)
}

fn count(&self) -> usize {
Expand Down
7 changes: 2 additions & 5 deletions src/gb18030.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ enum Gb18030Pending {

impl Gb18030Pending {
fn is_none(&self) -> bool {
match *self {
Gb18030Pending::None => true,
_ => false,
}
matches!(*self, Gb18030Pending::None)
}

fn count(&self) -> usize {
Expand Down Expand Up @@ -269,7 +266,7 @@ impl Gb18030Decoder {
} else {
handle.write_bmp_excl_ascii(gb18030_range_decode(pointer as u16))
}
} else if pointer >= 189_000 && pointer <= 1_237_575 {
} else if (189_000..=1_237_575).contains(&pointer) {
// Astral
handle.write_astral((pointer - (189_000usize - 0x1_0000usize)) as u32)
} else {
Expand Down
13 changes: 5 additions & 8 deletions src/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,17 +298,14 @@ fn convert_unaligned_utf16_to_utf8<E: Endian>(
if non_ascii_minus_surrogate_start > (0xDFFF - 0xD800) {
if non_ascii < 0x800 {
dst[dst_pos] = ((non_ascii >> 6) | 0xC0) as u8;
dst_pos += 1;
dst[dst_pos] = ((non_ascii & 0x3F) | 0x80) as u8;
dst_pos += 1;
} else {
dst[dst_pos] = ((non_ascii >> 12) | 0xE0) as u8;
dst_pos += 1;
dst[dst_pos] = (((non_ascii & 0xFC0) >> 6) | 0x80) as u8;
dst_pos += 1;
dst[dst_pos] = ((non_ascii & 0x3F) | 0x80) as u8;
dst_pos += 1;
}
dst_pos += 1;
dst[dst_pos] = ((non_ascii & 0x3F) | 0x80) as u8;
dst_pos += 1;
} else if non_ascii_minus_surrogate_start <= (0xDBFF - 0xD800) {
// high surrogate
if src_pos < src_len {
Expand Down Expand Up @@ -1148,7 +1145,7 @@ impl<'a> Utf16Source<'a> {
Space::Full(self.consumed())
}
}
#[cfg_attr(feature = "cargo-clippy", allow(collapsible_if))]
#[cfg_attr(feature = "cargo-clippy", allow(clippy::collapsible_if))]
#[inline(always)]
fn read(&mut self) -> char {
self.old_pos = self.pos;
Expand Down Expand Up @@ -1182,7 +1179,7 @@ impl<'a> Utf16Source<'a> {
// Unpaired low surrogate
'\u{FFFD}'
}
#[cfg_attr(feature = "cargo-clippy", allow(collapsible_if))]
#[cfg_attr(feature = "cargo-clippy", allow(clippy::collapsible_if))]
#[inline(always)]
fn read_enum(&mut self) -> Unicode {
self.old_pos = self.pos;
Expand Down
56 changes: 19 additions & 37 deletions src/iso_2022_jp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl Iso2022JpDecoder {
continue;
}
self.output_flag = false;
if b >= 0x21u8 && b <= 0x5Fu8 {
if (0x21u8..=0x5Fu8).contains(&b) {
destination_handle.write_upper_bmp(u16::from(b) - 0x21u16 + 0xFF61u16);
continue;
}
Expand All @@ -206,7 +206,7 @@ impl Iso2022JpDecoder {
continue;
}
self.output_flag = false;
if b >= 0x21u8 && b <= 0x7Eu8 {
if (0x21u8..=0x7Eu8).contains(&b) {
self.lead = b;
self.decoder_state = Iso2022JpDecoderState::TrailByte;
continue;
Expand Down Expand Up @@ -375,28 +375,21 @@ fn is_kanji_mapped(bmp: u16) -> bool {
#[cfg(not(feature = "fast-kanji-encode"))]
#[cfg_attr(
feature = "cargo-clippy",
allow(if_let_redundant_pattern_matching, if_same_then_else)
allow(if_let_redundant_pattern_matching, clippy::if_same_then_else)
)]
#[inline(always)]
fn is_kanji_mapped(bmp: u16) -> bool {
if 0x4EDD == bmp {
true
} else if let Some(_) = jis0208_level1_kanji_shift_jis_encode(bmp) {
0x4EDD == bmp
|| matches!(jis0208_level1_kanji_shift_jis_encode(bmp), Some(_))
// Use the shift_jis variant, because we don't care about the
// byte values here.
true
} else if let Some(_) = jis0208_level2_and_additional_kanji_encode(bmp) {
true
} else if let Some(_) = position(&IBM_KANJI[..], bmp) {
true
} else {
false
}
|| matches!(jis0208_level2_and_additional_kanji_encode(bmp), Some(_))
|| matches!(position(&IBM_KANJI[..], bmp), Some(_))
}

#[cfg_attr(
feature = "cargo-clippy",
allow(if_let_redundant_pattern_matching, if_same_then_else)
allow(if_let_redundant_pattern_matching, clippy::if_same_then_else)
)]
fn is_mapped_for_two_byte_encode(bmp: u16) -> bool {
// The code below uses else after return to
Expand All @@ -413,24 +406,16 @@ fn is_mapped_for_two_byte_encode(bmp: u16) -> bool {
true
} else {
let bmp_minus_space = bmp.wrapping_sub(0x3000);
if bmp_minus_space < 3 {
// fast-track common punctuation
true
} else if in_inclusive_range16(bmp, 0xFF61, 0xFF9F) {
true
} else if bmp == 0x2212 {
true
} else if let Some(_) = jis0208_range_encode(bmp) {
true
} else if in_inclusive_range16(bmp, 0xFA0E, 0xFA2D) || bmp == 0xF929 || bmp == 0xF9DC {
true
} else if let Some(_) = ibm_symbol_encode(bmp) {
true
} else if let Some(_) = jis0208_symbol_encode(bmp) {
true
} else {
false
}
// fast-track common punctuation
bmp_minus_space < 3
|| in_inclusive_range16(bmp, 0xFF61, 0xFF9F)
|| bmp == 0x2212
|| jis0208_range_encode(bmp).is_some()
|| in_inclusive_range16(bmp, 0xFA0E, 0xFA2D)
|| bmp == 0xF929
|| bmp == 0xF9DC
|| ibm_symbol_encode(bmp).is_some()
|| jis0208_symbol_encode(bmp).is_some()
}
}
}
Expand Down Expand Up @@ -483,10 +468,7 @@ impl Iso2022JpEncoder {
}

pub fn has_pending_state(&self) -> bool {
match self.state {
Iso2022JpEncoderState::Ascii => false,
_ => true,
}
!matches!(self.state, Iso2022JpEncoderState::Ascii)
}

pub fn max_buffer_length_from_utf16_without_replacement(
Expand Down
Loading