diff --git a/src/ascii.rs b/src/ascii.rs index b8fb250c..1d40f05e 100644 --- a/src/ascii.rs +++ b/src/ascii.rs @@ -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, @@ -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( @@ -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) { @@ -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(); diff --git a/src/data.rs b/src/data.rs index c1ae89e1..c19cafb7 100644 --- a/src/data.rs +++ b/src/data.rs @@ -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, diff --git a/src/euc_jp.rs b/src/euc_jp.rs index 18d1e11a..1d8c3f15 100644 --- a/src/euc_jp.rs +++ b/src/euc_jp.rs @@ -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 { diff --git a/src/gb18030.rs b/src/gb18030.rs index a0b3bd7f..eb6d04b8 100644 --- a/src/gb18030.rs +++ b/src/gb18030.rs @@ -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 { @@ -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 { diff --git a/src/handles.rs b/src/handles.rs index b5404c01..40aad569 100644 --- a/src/handles.rs +++ b/src/handles.rs @@ -298,17 +298,14 @@ fn convert_unaligned_utf16_to_utf8( 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 { @@ -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; @@ -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; diff --git a/src/iso_2022_jp.rs b/src/iso_2022_jp.rs index d71111a6..4c1d80c6 100644 --- a/src/iso_2022_jp.rs +++ b/src/iso_2022_jp.rs @@ -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; } @@ -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; @@ -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 @@ -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() } } } @@ -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( diff --git a/src/lib.rs b/src/lib.rs index bce2738a..11d7f64a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ #![cfg_attr( feature = "cargo-clippy", - allow(doc_markdown, inline_always, new_ret_no_self) + allow(clippy::doc_markdown, clippy::inline_always, clippy::new_ret_no_self) )] //! encoding_rs is a Gecko-oriented Free Software / Open Source implementation @@ -821,7 +821,7 @@ pub static BIG5_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static BIG5: &'static Encoding = &BIG5_INIT; +pub static BIG5: &Encoding = &BIG5_INIT; /// The initializer for the [EUC-JP](static.EUC_JP.html) encoding. /// @@ -859,7 +859,7 @@ pub static EUC_JP_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static EUC_JP: &'static Encoding = &EUC_JP_INIT; +pub static EUC_JP: &Encoding = &EUC_JP_INIT; /// The initializer for the [EUC-KR](static.EUC_KR.html) encoding. /// @@ -895,7 +895,7 @@ pub static EUC_KR_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static EUC_KR: &'static Encoding = &EUC_KR_INIT; +pub static EUC_KR: &Encoding = &EUC_KR_INIT; /// The initializer for the [GBK](static.GBK.html) encoding. /// @@ -937,7 +937,7 @@ pub static GBK_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static GBK: &'static Encoding = &GBK_INIT; +pub static GBK: &Encoding = &GBK_INIT; /// The initializer for the [IBM866](static.IBM866.html) encoding. /// @@ -971,7 +971,7 @@ pub static IBM866_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static IBM866: &'static Encoding = &IBM866_INIT; +pub static IBM866: &Encoding = &IBM866_INIT; /// The initializer for the [ISO-2022-JP](static.ISO_2022_JP.html) encoding. /// @@ -1007,7 +1007,7 @@ pub static ISO_2022_JP_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static ISO_2022_JP: &'static Encoding = &ISO_2022_JP_INIT; +pub static ISO_2022_JP: &Encoding = &ISO_2022_JP_INIT; /// The initializer for the [ISO-8859-10](static.ISO_8859_10.html) encoding. /// @@ -1041,7 +1041,7 @@ pub static ISO_8859_10_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static ISO_8859_10: &'static Encoding = &ISO_8859_10_INIT; +pub static ISO_8859_10: &Encoding = &ISO_8859_10_INIT; /// The initializer for the [ISO-8859-13](static.ISO_8859_13.html) encoding. /// @@ -1075,7 +1075,7 @@ pub static ISO_8859_13_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static ISO_8859_13: &'static Encoding = &ISO_8859_13_INIT; +pub static ISO_8859_13: &Encoding = &ISO_8859_13_INIT; /// The initializer for the [ISO-8859-14](static.ISO_8859_14.html) encoding. /// @@ -1109,7 +1109,7 @@ pub static ISO_8859_14_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static ISO_8859_14: &'static Encoding = &ISO_8859_14_INIT; +pub static ISO_8859_14: &Encoding = &ISO_8859_14_INIT; /// The initializer for the [ISO-8859-15](static.ISO_8859_15.html) encoding. /// @@ -1142,7 +1142,7 @@ pub static ISO_8859_15_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static ISO_8859_15: &'static Encoding = &ISO_8859_15_INIT; +pub static ISO_8859_15: &Encoding = &ISO_8859_15_INIT; /// The initializer for the [ISO-8859-16](static.ISO_8859_16.html) encoding. /// @@ -1176,7 +1176,7 @@ pub static ISO_8859_16_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static ISO_8859_16: &'static Encoding = &ISO_8859_16_INIT; +pub static ISO_8859_16: &Encoding = &ISO_8859_16_INIT; /// The initializer for the [ISO-8859-2](static.ISO_8859_2.html) encoding. /// @@ -1208,7 +1208,7 @@ pub static ISO_8859_2_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static ISO_8859_2: &'static Encoding = &ISO_8859_2_INIT; +pub static ISO_8859_2: &Encoding = &ISO_8859_2_INIT; /// The initializer for the [ISO-8859-3](static.ISO_8859_3.html) encoding. /// @@ -1240,7 +1240,7 @@ pub static ISO_8859_3_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static ISO_8859_3: &'static Encoding = &ISO_8859_3_INIT; +pub static ISO_8859_3: &Encoding = &ISO_8859_3_INIT; /// The initializer for the [ISO-8859-4](static.ISO_8859_4.html) encoding. /// @@ -1272,7 +1272,7 @@ pub static ISO_8859_4_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static ISO_8859_4: &'static Encoding = &ISO_8859_4_INIT; +pub static ISO_8859_4: &Encoding = &ISO_8859_4_INIT; /// The initializer for the [ISO-8859-5](static.ISO_8859_5.html) encoding. /// @@ -1304,7 +1304,7 @@ pub static ISO_8859_5_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static ISO_8859_5: &'static Encoding = &ISO_8859_5_INIT; +pub static ISO_8859_5: &Encoding = &ISO_8859_5_INIT; /// The initializer for the [ISO-8859-6](static.ISO_8859_6.html) encoding. /// @@ -1337,7 +1337,7 @@ pub static ISO_8859_6_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static ISO_8859_6: &'static Encoding = &ISO_8859_6_INIT; +pub static ISO_8859_6: &Encoding = &ISO_8859_6_INIT; /// The initializer for the [ISO-8859-7](static.ISO_8859_7.html) encoding. /// @@ -1374,7 +1374,7 @@ pub static ISO_8859_7_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static ISO_8859_7: &'static Encoding = &ISO_8859_7_INIT; +pub static ISO_8859_7: &Encoding = &ISO_8859_7_INIT; /// The initializer for the [ISO-8859-8](static.ISO_8859_8.html) encoding. /// @@ -1409,7 +1409,7 @@ pub static ISO_8859_8_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static ISO_8859_8: &'static Encoding = &ISO_8859_8_INIT; +pub static ISO_8859_8: &Encoding = &ISO_8859_8_INIT; /// The initializer for the [ISO-8859-8-I](static.ISO_8859_8_I.html) encoding. /// @@ -1444,7 +1444,7 @@ pub static ISO_8859_8_I_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static ISO_8859_8_I: &'static Encoding = &ISO_8859_8_I_INIT; +pub static ISO_8859_8_I: &Encoding = &ISO_8859_8_I_INIT; /// The initializer for the [KOI8-R](static.KOI8_R.html) encoding. /// @@ -1476,7 +1476,7 @@ pub static KOI8_R_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static KOI8_R: &'static Encoding = &KOI8_R_INIT; +pub static KOI8_R: &Encoding = &KOI8_R_INIT; /// The initializer for the [KOI8-U](static.KOI8_U.html) encoding. /// @@ -1508,7 +1508,7 @@ pub static KOI8_U_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static KOI8_U: &'static Encoding = &KOI8_U_INIT; +pub static KOI8_U: &Encoding = &KOI8_U_INIT; /// The initializer for the [Shift_JIS](static.SHIFT_JIS.html) encoding. /// @@ -1542,7 +1542,7 @@ pub static SHIFT_JIS_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static SHIFT_JIS: &'static Encoding = &SHIFT_JIS_INIT; +pub static SHIFT_JIS: &Encoding = &SHIFT_JIS_INIT; /// The initializer for the [UTF-16BE](static.UTF_16BE.html) encoding. /// @@ -1576,7 +1576,7 @@ pub static UTF_16BE_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static UTF_16BE: &'static Encoding = &UTF_16BE_INIT; +pub static UTF_16BE: &Encoding = &UTF_16BE_INIT; /// The initializer for the [UTF-16LE](static.UTF_16LE.html) encoding. /// @@ -1610,7 +1610,7 @@ pub static UTF_16LE_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static UTF_16LE: &'static Encoding = &UTF_16LE_INIT; +pub static UTF_16LE: &Encoding = &UTF_16LE_INIT; /// The initializer for the [UTF-8](static.UTF_8.html) encoding. /// @@ -1641,7 +1641,7 @@ pub static UTF_8_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static UTF_8: &'static Encoding = &UTF_8_INIT; +pub static UTF_8: &Encoding = &UTF_8_INIT; /// The initializer for the [gb18030](static.GB18030.html) encoding. /// @@ -1676,7 +1676,7 @@ pub static GB18030_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static GB18030: &'static Encoding = &GB18030_INIT; +pub static GB18030: &Encoding = &GB18030_INIT; /// The initializer for the [macintosh](static.MACINTOSH.html) encoding. /// @@ -1709,7 +1709,7 @@ pub static MACINTOSH_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static MACINTOSH: &'static Encoding = &MACINTOSH_INIT; +pub static MACINTOSH: &Encoding = &MACINTOSH_INIT; /// The initializer for the [replacement](static.REPLACEMENT.html) encoding. /// @@ -1745,7 +1745,7 @@ pub static REPLACEMENT_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static REPLACEMENT: &'static Encoding = &REPLACEMENT_INIT; +pub static REPLACEMENT: &Encoding = &REPLACEMENT_INIT; /// The initializer for the [windows-1250](static.WINDOWS_1250.html) encoding. /// @@ -1777,7 +1777,7 @@ pub static WINDOWS_1250_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static WINDOWS_1250: &'static Encoding = &WINDOWS_1250_INIT; +pub static WINDOWS_1250: &Encoding = &WINDOWS_1250_INIT; /// The initializer for the [windows-1251](static.WINDOWS_1251.html) encoding. /// @@ -1809,7 +1809,7 @@ pub static WINDOWS_1251_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static WINDOWS_1251: &'static Encoding = &WINDOWS_1251_INIT; +pub static WINDOWS_1251: &Encoding = &WINDOWS_1251_INIT; /// The initializer for the [windows-1252](static.WINDOWS_1252.html) encoding. /// @@ -1842,7 +1842,7 @@ pub static WINDOWS_1252_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static WINDOWS_1252: &'static Encoding = &WINDOWS_1252_INIT; +pub static WINDOWS_1252: &Encoding = &WINDOWS_1252_INIT; /// The initializer for the [windows-1253](static.WINDOWS_1253.html) encoding. /// @@ -1876,7 +1876,7 @@ pub static WINDOWS_1253_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static WINDOWS_1253: &'static Encoding = &WINDOWS_1253_INIT; +pub static WINDOWS_1253: &Encoding = &WINDOWS_1253_INIT; /// The initializer for the [windows-1254](static.WINDOWS_1254.html) encoding. /// @@ -1909,7 +1909,7 @@ pub static WINDOWS_1254_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static WINDOWS_1254: &'static Encoding = &WINDOWS_1254_INIT; +pub static WINDOWS_1254: &Encoding = &WINDOWS_1254_INIT; /// The initializer for the [windows-1255](static.WINDOWS_1255.html) encoding. /// @@ -1943,7 +1943,7 @@ pub static WINDOWS_1255_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static WINDOWS_1255: &'static Encoding = &WINDOWS_1255_INIT; +pub static WINDOWS_1255: &Encoding = &WINDOWS_1255_INIT; /// The initializer for the [windows-1256](static.WINDOWS_1256.html) encoding. /// @@ -1975,7 +1975,7 @@ pub static WINDOWS_1256_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static WINDOWS_1256: &'static Encoding = &WINDOWS_1256_INIT; +pub static WINDOWS_1256: &Encoding = &WINDOWS_1256_INIT; /// The initializer for the [windows-1257](static.WINDOWS_1257.html) encoding. /// @@ -2008,7 +2008,7 @@ pub static WINDOWS_1257_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static WINDOWS_1257: &'static Encoding = &WINDOWS_1257_INIT; +pub static WINDOWS_1257: &Encoding = &WINDOWS_1257_INIT; /// The initializer for the [windows-1258](static.WINDOWS_1258.html) encoding. /// @@ -2045,7 +2045,7 @@ pub static WINDOWS_1258_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static WINDOWS_1258: &'static Encoding = &WINDOWS_1258_INIT; +pub static WINDOWS_1258: &Encoding = &WINDOWS_1258_INIT; /// The initializer for the [windows-874](static.WINDOWS_874.html) encoding. /// @@ -2078,7 +2078,7 @@ pub static WINDOWS_874_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static WINDOWS_874: &'static Encoding = &WINDOWS_874_INIT; +pub static WINDOWS_874: &Encoding = &WINDOWS_874_INIT; /// The initializer for the [x-mac-cyrillic](static.X_MAC_CYRILLIC.html) encoding. /// @@ -2110,7 +2110,7 @@ pub static X_MAC_CYRILLIC_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static X_MAC_CYRILLIC: &'static Encoding = &X_MAC_CYRILLIC_INIT; +pub static X_MAC_CYRILLIC: &Encoding = &X_MAC_CYRILLIC_INIT; /// The initializer for the [x-user-defined](static.X_USER_DEFINED.html) encoding. /// @@ -2142,9 +2142,9 @@ pub static X_USER_DEFINED_INIT: Encoding = Encoding { /// to make the referent of `pub const FOO: &'static Encoding` /// unique cross-crate, so don't take the address of this /// `static`. -pub static X_USER_DEFINED: &'static Encoding = &X_USER_DEFINED_INIT; +pub static X_USER_DEFINED: &Encoding = &X_USER_DEFINED_INIT; -static LABELS_SORTED: [&'static str; 228] = [ +static LABELS_SORTED: [&str; 228] = [ "l1", "l2", "l3", @@ -2375,7 +2375,7 @@ static LABELS_SORTED: [&'static str; 228] = [ "cseucpkdfmtjapanese", ]; -static ENCODINGS_IN_LABEL_SORT: [&'static Encoding; 228] = [ +static ENCODINGS_IN_LABEL_SORT: [&Encoding; 228] = [ &WINDOWS_1252_INIT, &ISO_8859_2_INIT, &ISO_8859_3_INIT, @@ -2714,7 +2714,7 @@ impl Encoding { pub fn for_label(label: &[u8]) -> Option<&'static Encoding> { let mut trimmed = [0u8; LONGEST_LABEL_LENGTH]; let mut trimmed_pos = 0usize; - let mut iter = label.into_iter(); + let mut iter = label.iter(); // before loop { match iter.next() { @@ -3407,7 +3407,7 @@ impl Encoding { impl PartialEq for Encoding { #[inline] fn eq(&self, other: &Encoding) -> bool { - (self as *const Encoding) == (other as *const Encoding) + core::ptr::eq(self, other) } } @@ -4307,9 +4307,7 @@ impl Decoder { /// Available via the C wrapper. pub fn latin1_byte_compatible_up_to(&self, bytes: &[u8]) -> Option { match self.life_cycle { - DecoderLifeCycle::Converting => { - return self.variant.latin1_byte_compatible_up_to(bytes); - } + DecoderLifeCycle::Converting => self.variant.latin1_byte_compatible_up_to(bytes), DecoderLifeCycle::Finished => panic!("Must not use a decoder that has finished."), _ => None, } diff --git a/src/macros.rs b/src/macros.rs index d3bb5e9e..3a365206 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -361,7 +361,7 @@ macro_rules! gb18030_decoder_function { $name:ident, $code_unit:ty, $dest_struct:ident) => ( - #[cfg_attr(feature = "cargo-clippy", allow(never_loop))] + #[cfg_attr(feature = "cargo-clippy", allow(clippy::never_loop))] pub fn $name(&mut $slf, src: &[u8], dst: &mut [$code_unit], @@ -686,7 +686,7 @@ macro_rules! euc_jp_decoder_function { $name:ident, $code_unit:ty, $dest_struct:ident) => ( - #[cfg_attr(feature = "cargo-clippy", allow(never_loop))] + #[cfg_attr(feature = "cargo-clippy", allow(clippy::never_loop))] pub fn $name(&mut $slf, src: &[u8], dst: &mut [$code_unit], diff --git a/src/mem.rs b/src/mem.rs index 33306193..ee6a2cc7 100644 --- a/src/mem.rs +++ b/src/mem.rs @@ -85,7 +85,7 @@ const LATIN1_MASK: usize = 0xFF00_FF00_FF00_FF00u64 as usize; #[allow(unused_macros)] macro_rules! by_unit_check_alu { ($name:ident, $unit:ty, $bound:expr, $mask:ident) => { - #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] + #[cfg_attr(feature = "cargo-clippy", allow(clippy::cast_ptr_alignment))] #[inline(always)] fn $name(buffer: &[$unit]) -> bool { let mut offset = 0usize; @@ -321,7 +321,7 @@ cfg_if! { /// The second return value is true iff the last code unit of the slice was /// reached and turned out to be a low surrogate that is part of a valid pair. -#[cfg_attr(feature = "cargo-clippy", allow(collapsible_if))] +#[cfg_attr(feature = "cargo-clippy", allow(clippy::collapsible_if))] #[inline(always)] fn utf16_valid_up_to_alu(buffer: &[u16]) -> (usize, bool) { let len = buffer.len(); @@ -576,7 +576,7 @@ cfg_if! { } } } else { - #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] + #[cfg_attr(feature = "cargo-clippy", allow(clippy::cast_ptr_alignment))] #[inline(always)] fn check_utf16_for_latin1_and_bidi_impl(buffer: &[u16]) -> Latin1Bidi { let mut offset = 0usize; @@ -695,7 +695,10 @@ pub fn is_utf16_latin1(buffer: &[u16]) -> bool { /// Returns `true` if the input is invalid UTF-8 or the input contains an /// RTL character. Returns `false` if the input is valid UTF-8 and contains /// no RTL characters. -#[cfg_attr(feature = "cargo-clippy", allow(collapsible_if, cyclomatic_complexity))] +#[cfg_attr( + feature = "cargo-clippy", + allow(clippy::collapsible_if, cyclomatic_complexity) +)] #[inline] pub fn is_utf8_bidi(buffer: &[u8]) -> bool { // As of rustc 1.25.0-nightly (73ac5d6a8 2018-01-11), this is faster @@ -1106,10 +1109,8 @@ pub fn is_utf8_bidi(buffer: &[u8]) -> bool { return true; } } - return false; - } else { - return false; } + return false; } } @@ -1125,7 +1126,7 @@ pub fn is_utf8_bidi(buffer: &[u8]) -> bool { /// cause right-to-left behavior without the presence of right-to-left /// characters or right-to-left controls are not checked for. As a special /// case, U+FEFF is excluded from Arabic Presentation Forms-B. -#[cfg_attr(feature = "cargo-clippy", allow(collapsible_if))] +#[cfg_attr(feature = "cargo-clippy", allow(clippy::collapsible_if))] #[inline] pub fn is_str_bidi(buffer: &str) -> bool { // U+058F: D6 8F @@ -1994,7 +1995,7 @@ pub fn convert_utf16_to_latin1_lossy(src: &[u16], dst: &mut [u8]) { /// /// Only available if the `alloc` feature is enabled (enabled by default). #[cfg(feature = "alloc")] -pub fn decode_latin1<'a>(bytes: &'a [u8]) -> Cow<'a, str> { +pub fn decode_latin1(bytes: &[u8]) -> Cow<'_, str> { let up_to = ascii_valid_up_to(bytes); // >= makes later things optimize better than == if up_to >= bytes.len() { @@ -2031,7 +2032,7 @@ pub fn decode_latin1<'a>(bytes: &'a [u8]) -> Cow<'a, str> { /// /// Only available if the `alloc` feature is enabled (enabled by default). #[cfg(feature = "alloc")] -pub fn encode_latin1_lossy<'a>(string: &'a str) -> Cow<'a, [u8]> { +pub fn encode_latin1_lossy(string: &str) -> Cow<'_, [u8]> { let bytes = string.as_bytes(); let up_to = ascii_valid_up_to(bytes); // >= makes later things optimize better than == diff --git a/src/utf_8.rs b/src/utf_8.rs index 2f72cc09..b5c715ae 100644 --- a/src/utf_8.rs +++ b/src/utf_8.rs @@ -228,7 +228,10 @@ pub fn utf8_valid_up_to(src: &[u8]) -> usize { read } -#[cfg_attr(feature = "cargo-clippy", allow(never_loop, cyclomatic_complexity))] +#[cfg_attr( + feature = "cargo-clippy", + allow(clippy::never_loop, cyclomatic_complexity) +)] pub fn convert_utf8_to_utf16_up_to_invalid(src: &[u8], dst: &mut [u16]) -> (usize, usize) { let mut read = 0; let mut written = 0; @@ -605,7 +608,7 @@ impl Utf8Decoder { ); } -#[cfg_attr(feature = "cargo-clippy", allow(never_loop))] +#[cfg_attr(feature = "cargo-clippy", allow(clippy::never_loop))] #[inline(never)] pub fn convert_utf16_to_utf8_partial_inner(src: &[u16], dst: &mut [u8]) -> (usize, usize) { let mut read = 0; @@ -794,6 +797,7 @@ pub fn convert_utf16_to_utf8_partial_tail(src: &[u16], dst: &mut [u8]) -> (usize // Got surrogate if unit_minus_surrogate_start <= (0xDBFF - 0xD800) { // Got high surrogate + #[allow(clippy::branches_sharing_code)] if read >= src.len() { // Unpaired high surrogate unit = 0xFFFD; diff --git a/src/variant.rs b/src/variant.rs index dffaf053..4fef928f 100644 --- a/src/variant.rs +++ b/src/variant.rs @@ -392,9 +392,9 @@ impl VariantEncoding { } pub fn is_single_byte(&self) -> bool { - match *self { - VariantEncoding::SingleByte(_, _, _, _) | VariantEncoding::UserDefined => true, - _ => false, - } + matches!( + *self, + VariantEncoding::SingleByte(_, _, _, _) | VariantEncoding::UserDefined + ) } } diff --git a/src/x_user_defined.rs b/src/x_user_defined.rs index 103c9afb..65089ca0 100644 --- a/src/x_user_defined.rs +++ b/src/x_user_defined.rs @@ -172,7 +172,7 @@ impl UserDefinedEncoder { destination_handle.write_one(c as u8); continue; } - if c < '\u{F780}' || c > '\u{F7FF}' { + if !('\u{F780}'..='\u{F7FF}').contains(&c) { return ( EncoderResult::Unmappable(c), unread_handle.consumed(),