From eec0bde68d6a568e11d830812294ff1ddbebb9df Mon Sep 17 00:00:00 2001 From: Henri Sivonen Date: Fri, 25 Oct 2024 09:31:04 +0300 Subject: [PATCH] Make cargo check pass without warning on Rust 1.82.0 --- Cargo.toml | 3 +++ generate-encoding-data.py | 2 +- src/ascii.rs | 19 ++++++++----------- src/data.rs | 2 +- src/handles.rs | 4 ++-- src/iso_2022_jp.rs | 10 ++-------- src/lib.rs | 8 +++++--- src/macros.rs | 4 ++-- src/mem.rs | 10 +++++----- src/utf_8.rs | 4 ++-- 10 files changed, 31 insertions(+), 35 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0f7639d5..3cee8cee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,3 +43,6 @@ serde_json = "1.0" [profile.release] lto = true + +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fuzzing)'] } diff --git a/generate-encoding-data.py b/generate-encoding-data.py index c4e124d0..8fedda87 100644 --- a/generate-encoding-data.py +++ b/generate-encoding-data.py @@ -542,7 +542,7 @@ def null_to_zero(code_point): for j in xrange(32 - (len(astralness) % 32)): astralness.append(0) -data_file.write('''#[cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))] +data_file.write('''#[allow(clippy::unreadable_literal)] static BIG5_ASTRALNESS: [u32; %d] = [ ''' % (len(astralness) / 32)) diff --git a/src/ascii.rs b/src/ascii.rs index 80233f28..2f543608 100644 --- a/src/ascii.rs +++ b/src/ascii.rs @@ -102,7 +102,7 @@ macro_rules! ascii_alu { /// write /// Safety-usable invariant: will return Some() when it fails /// to convert. The first value will be a u8 that is > 127. - #[cfg_attr(feature = "cargo-clippy", allow(never_loop, cast_ptr_alignment))] + #[allow(clippy::never_loop, clippy::cast_ptr_alignment)] #[inline(always)] pub unsafe fn $name( src: *const $src_unit, @@ -223,10 +223,7 @@ macro_rules! basic_latin_alu { /// write /// Safety-usable invariant: will return Some() when it fails /// to convert. The first value will be a u8 that is > 127. - #[cfg_attr( - feature = "cargo-clippy", - allow(never_loop, cast_ptr_alignment, cast_lossless) - )] + #[allow(clippy::never_loop, clippy::cast_ptr_alignment)] #[inline(always)] pub unsafe fn $name( src: *const $src_unit, @@ -345,10 +342,7 @@ macro_rules! latin1_alu { ($name:ident, $src_unit:ty, $dst_unit:ty, $stride_fn:ident) => { /// Safety: src and dst must have len elements, src is valid for read, dst is valid for /// write - #[cfg_attr( - feature = "cargo-clippy", - allow(never_loop, cast_ptr_alignment, cast_lossless) - )] + #[allow(clippy::never_loop, clippy::cast_ptr_alignment)] #[inline(always)] pub unsafe fn $name(src: *const $src_unit, dst: *mut $dst_unit, len: usize) { let mut offset = 0usize; @@ -1505,6 +1499,7 @@ cfg_if! { } cfg_if! { +/* if #[cfg(all(feature = "simd-accel", target_endian = "little", target_arch = "disabled"))] { /// Safety-usable invariant: Will return the value and position of the first non-ASCII byte in the slice in a Some if found. /// In other words, the first element of the Some is always `> 127` @@ -1539,7 +1534,9 @@ cfg_if! { } None } - } else if #[cfg(all(feature = "simd-accel", target_feature = "sse2"))] { + } else +*/ + if #[cfg(all(feature = "simd-accel", target_feature = "sse2"))] { /// Safety-usable invariant: will return Some() when it encounters non-ASCII, with the first element in the Some being /// guaranteed to be non-ASCII (> 127), and the second being the offset where it is found #[inline(always)] @@ -1722,7 +1719,7 @@ cfg_if! { /// Safety-usable invariant: will return Some() when it encounters non-ASCII, with the first element in the Some being /// guaranteed to be non-ASCII (> 127), and the second being the offset where it is found - #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] + #[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 db4f07f5..e6278c97 100644 --- a/src/data.rs +++ b/src/data.rs @@ -453,7 +453,7 @@ pub static SINGLE_BYTE_DATA: SingleByteData = SingleByteData { ], }; -#[cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))] +#[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/handles.rs b/src/handles.rs index f44a8346..4558612b 100644 --- a/src/handles.rs +++ b/src/handles.rs @@ -1180,7 +1180,7 @@ impl<'a> Utf16Source<'a> { Space::Full(self.consumed()) } } - #[cfg_attr(feature = "cargo-clippy", allow(collapsible_if))] + #[allow(clippy::collapsible_if)] #[inline(always)] fn read(&mut self) -> char { self.old_pos = self.pos; @@ -1214,7 +1214,7 @@ impl<'a> Utf16Source<'a> { // Unpaired low surrogate '\u{FFFD}' } - #[cfg_attr(feature = "cargo-clippy", allow(collapsible_if))] + #[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..2fb9d4a8 100644 --- a/src/iso_2022_jp.rs +++ b/src/iso_2022_jp.rs @@ -373,10 +373,7 @@ 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(clippy::if_let_redundant_pattern_matching, clippy::if_same_then_else)] #[inline(always)] fn is_kanji_mapped(bmp: u16) -> bool { if 0x4EDD == bmp { @@ -394,10 +391,7 @@ fn is_kanji_mapped(bmp: u16) -> bool { } } -#[cfg_attr( - feature = "cargo-clippy", - allow(if_let_redundant_pattern_matching, if_same_then_else) -)] +#[allow(clippy::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 // keep the same structure as in EUC-JP. diff --git a/src/lib.rs b/src/lib.rs index 5c5313af..78e9849b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,9 +38,11 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#![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, + clippy::redundant_static_lifetimes )] //! encoding_rs is a Gecko-oriented Free Software / Open Source implementation diff --git a/src/macros.rs b/src/macros.rs index d3bb5e9e..663e0546 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))] + #[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))] + #[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 0f9f3c19..92941bb9 100644 --- a/src/mem.rs +++ b/src/mem.rs @@ -83,7 +83,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))] + #[allow(clippy::cast_ptr_alignment)] #[inline(always)] fn $name(buffer: &[$unit]) -> bool { let mut offset = 0usize; @@ -333,7 +333,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))] +#[allow(clippy::collapsible_if)] #[inline(always)] fn utf16_valid_up_to_alu(buffer: &[u16]) -> (usize, bool) { let len = buffer.len(); @@ -588,7 +588,7 @@ cfg_if! { } } } else { - #[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))] + #[allow(clippy::cast_ptr_alignment)] #[inline(always)] fn check_utf16_for_latin1_and_bidi_impl(buffer: &[u16]) -> Latin1Bidi { let mut offset = 0usize; @@ -707,7 +707,7 @@ 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))] +#[allow(clippy::collapsible_if, clippy::cognitive_complexity)] #[inline] pub fn is_utf8_bidi(buffer: &[u8]) -> bool { // As of rustc 1.25.0-nightly (73ac5d6a8 2018-01-11), this is faster @@ -1137,7 +1137,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))] +#[allow(clippy::collapsible_if)] #[inline] pub fn is_str_bidi(buffer: &str) -> bool { // U+058F: D6 8F diff --git a/src/utf_8.rs b/src/utf_8.rs index da9cfc28..05abcb17 100644 --- a/src/utf_8.rs +++ b/src/utf_8.rs @@ -226,7 +226,7 @@ pub fn utf8_valid_up_to(src: &[u8]) -> usize { read } -#[cfg_attr(feature = "cargo-clippy", allow(never_loop, cyclomatic_complexity))] +#[allow(clippy::never_loop, clippy::cognitive_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; @@ -603,7 +603,7 @@ impl Utf8Decoder { ); } -#[cfg_attr(feature = "cargo-clippy", allow(never_loop))] +#[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;