diff --git a/examples/font2svg.rs b/examples/font2svg.rs index be6403a0..ef66d949 100644 --- a/examples/font2svg.rs +++ b/examples/font2svg.rs @@ -1,3 +1,5 @@ +#![allow(clippy::too_many_arguments)] + use base64::engine::general_purpose::STANDARD; use std::io::Write; @@ -167,7 +169,7 @@ fn process(args: Args) -> Result<(), Box> { &mut svg, &mut path_buf, ); - } else if let Some(img) = face.glyph_raster_image(gid, std::u16::MAX) { + } else if let Some(img) = face.glyph_raster_image(gid, u16::MAX) { svg.start_element("image"); svg.write_attribute("x", &(x + 2.0 + img.x as f64)); svg.write_attribute("y", &(y - img.y as f64)); @@ -208,7 +210,7 @@ fn process(args: Args) -> Result<(), Box> { println!("Elapsed: {}ms", now.elapsed().as_micros() as f64 / 1000.0); - std::fs::write(&args.svg_path, &svg.end_document())?; + std::fs::write(&args.svg_path, svg.end_document())?; Ok(()) } diff --git a/src/aat.rs b/src/aat.rs index 123f0e2f..30dddbb9 100644 --- a/src/aat.rs +++ b/src/aat.rs @@ -174,7 +174,7 @@ impl<'a> StateTable<'a> { #[inline] pub fn class(&self, glyph_id: GlyphId) -> Option { if glyph_id.0 == 0xFFFF { - return Some(class::DELETED_GLYPH as u8); + return Some(class::DELETED_GLYPH); } let idx = glyph_id.0.checked_sub(self.first_glyph.0)?; @@ -185,7 +185,7 @@ impl<'a> StateTable<'a> { #[inline] pub fn entry(&self, state: u16, mut class: u8) -> Option { if u16::from(class) >= self.number_of_classes { - class = class::OUT_OF_BOUNDS as u8; + class = class::OUT_OF_BOUNDS; } let entry_idx = self diff --git a/src/delta_set.rs b/src/delta_set.rs index d7a40b19..c63cb899 100644 --- a/src/delta_set.rs +++ b/src/delta_set.rs @@ -36,7 +36,7 @@ impl<'a> DeltaSetIndexMap<'a> { let entry_size = ((entry_format >> 4) & 3) + 1; let inner_index_bit_count = u32::from((entry_format & 0xF) + 1); - s.advance(usize::try_from(entry_size).ok()? * usize::try_from(index).ok()?); + s.advance(usize::from(entry_size) * usize::try_from(index).ok()?); let mut n = 0u32; for b in s.read_bytes(usize::from(entry_size))? { diff --git a/src/lib.rs b/src/lib.rs index c7ce7ad2..2826bb57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,6 +43,7 @@ Font parsing starts with a [`Face`]. #![allow(clippy::collapsible_else_if)] #![allow(clippy::field_reassign_with_default)] #![allow(clippy::upper_case_acronyms)] +#![allow(clippy::bool_assert_comparison)] #[cfg(feature = "std")] #[macro_use] @@ -368,19 +369,19 @@ impl RectF { #[inline] fn new() -> Self { RectF { - x_min: core::f32::MAX, - y_min: core::f32::MAX, - x_max: core::f32::MIN, - y_max: core::f32::MIN, + x_min: f32::MAX, + y_min: f32::MAX, + x_max: f32::MIN, + y_max: f32::MIN, } } #[inline] fn is_default(&self) -> bool { - self.x_min == core::f32::MAX - && self.y_min == core::f32::MAX - && self.x_max == core::f32::MIN - && self.y_max == core::f32::MIN + self.x_min == f32::MAX + && self.y_min == f32::MAX + && self.x_max == f32::MIN + && self.y_max == f32::MIN } #[inline] diff --git a/src/parser.rs b/src/parser.rs index d6526f0a..3852a64a 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -238,10 +238,10 @@ impl TryNumFrom for i32 { // We can't represent `MIN-1` exactly, but there's no fractional part // at this magnitude, so we can just use a `MIN` inclusive boundary. - const MIN: f32 = core::i32::MIN as f32; + const MIN: f32 = i32::MIN as f32; // We can't represent `MAX` exactly, but it will round up to exactly // `MAX+1` (a power of two) when we cast it. - const MAX_P1: f32 = core::i32::MAX as f32; + const MAX_P1: f32 = i32::MAX as f32; if v >= MIN && v < MAX_P1 { Some(v as i32) } else { @@ -372,7 +372,7 @@ impl<'a, T: FromData> LazyArray16<'a, T> { impl<'a, T: FromData + core::fmt::Debug + Copy> core::fmt::Debug for LazyArray16<'a, T> { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - f.debug_list().entries(self.into_iter()).finish() + f.debug_list().entries(*self).finish() } } @@ -522,7 +522,7 @@ impl<'a, T: FromData> LazyArray32<'a, T> { impl<'a, T: FromData + core::fmt::Debug + Copy> core::fmt::Debug for LazyArray32<'a, T> { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - f.debug_list().entries(self.into_iter()).finish() + f.debug_list().entries(*self).finish() } } @@ -622,7 +622,7 @@ impl<'a, T: FromSlice<'a>> LazyOffsetArray16<'a, T> { impl<'a, T: FromSlice<'a> + core::fmt::Debug + Copy> core::fmt::Debug for LazyOffsetArray16<'a, T> { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - f.debug_list().entries(self.into_iter()).finish() + f.debug_list().entries(*self).finish() } } diff --git a/src/tables/cff/index.rs b/src/tables/cff/index.rs index d320eca0..67a8bf2b 100644 --- a/src/tables/cff/index.rs +++ b/src/tables/cff/index.rs @@ -24,7 +24,7 @@ pub fn parse_index<'a, T: IndexSize>(s: &mut Stream<'a>) -> Option> { #[inline(never)] fn parse_index_impl<'a>(count: u32, s: &mut Stream<'a>) -> Option> { - if count == 0 || count == core::u32::MAX { + if count == 0 || count == u32::MAX { return Some(Index::default()); } @@ -53,7 +53,7 @@ pub fn skip_index(s: &mut Stream) -> Option<()> { #[inline(never)] fn skip_index_impl(count: u32, s: &mut Stream) -> Option<()> { - if count == 0 || count == core::u32::MAX { + if count == 0 || count == u32::MAX { return Some(()); } diff --git a/src/tables/cmap/format2.rs b/src/tables/cmap/format2.rs index b4979571..7225ed2d 100644 --- a/src/tables/cmap/format2.rs +++ b/src/tables/cmap/format2.rs @@ -72,8 +72,6 @@ impl<'a> Subtable2<'a> { pub fn glyph_index(&self, code_point: u32) -> Option { // This subtable supports code points only in a u16 range. let code_point = u16::try_from(code_point).ok()?; - - let code_point = code_point; let high_byte = code_point >> 8; let low_byte = code_point & 0x00FF; diff --git a/src/tables/colr.rs b/src/tables/colr.rs index b07e68d6..83b4e532 100644 --- a/src/tables/colr.rs +++ b/src/tables/colr.rs @@ -1897,8 +1897,8 @@ impl VariationData<'_> { let variation_store = self.variation_store.as_ref().unwrap(); - for i in 0..N { - deltas[i] = self + for (i, delta) in deltas.iter_mut().enumerate() { + *delta = self .delta_map .and_then(|d| d.map(var_index_base + i as u32)) .and_then(|d| variation_store.parse_delta(d.0, d.1, coordinates)) diff --git a/src/tables/cpal.rs b/src/tables/cpal.rs index bed754dd..308c9695 100644 --- a/src/tables/cpal.rs +++ b/src/tables/cpal.rs @@ -47,7 +47,7 @@ impl<'a> Table<'a> { /// Returns the number of palettes. pub fn palettes(&self) -> NonZeroU16 { // Already checked during parsing. - NonZeroU16::new(self.color_indices.len() as u16).unwrap() + NonZeroU16::new(self.color_indices.len()).unwrap() } /// Returns the color at the given index into the given palette. diff --git a/src/tables/feat.rs b/src/tables/feat.rs index a16c98c1..879c83b9 100644 --- a/src/tables/feat.rs +++ b/src/tables/feat.rs @@ -117,7 +117,7 @@ impl<'a> FeatureNames<'a> { impl<'a> core::fmt::Debug for FeatureNames<'a> { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - f.debug_list().entries(self.into_iter()).finish() + f.debug_list().entries(*self).finish() } } diff --git a/src/tables/gvar.rs b/src/tables/gvar.rs index 7c0fde23..d0a17f54 100644 --- a/src/tables/gvar.rs +++ b/src/tables/gvar.rs @@ -11,8 +11,8 @@ use core::cmp; use core::convert::TryFrom; use core::num::NonZeroU16; -use crate::{glyf, PhantomPoints, PointF}; use crate::parser::{LazyArray16, Offset, Offset16, Offset32, Stream, F2DOT14}; +use crate::{glyf, PhantomPoints, PointF}; use crate::{GlyphId, NormalizedCoordinate, OutlineBuilder, Rect, RectF, Transform}; /// 'The TrueType rasterizer dynamically generates 'phantom' points for each glyph @@ -525,7 +525,7 @@ mod packed_points { // Check that points data size is smaller than the storage type // used by the iterator. let data_len = s.offset() - start; - if data_len > usize::from(core::u16::MAX) { + if data_len > usize::from(u16::MAX) { return None; } @@ -802,7 +802,6 @@ mod packed_points { for _ in 0..50 { data.push(2); } - let points_iter = PackedPointsIter::new(&mut Stream::new(&data)) .unwrap() .unwrap(); diff --git a/src/tables/kerx.rs b/src/tables/kerx.rs index 86e1fd52..93d84258 100644 --- a/src/tables/kerx.rs +++ b/src/tables/kerx.rs @@ -290,7 +290,7 @@ impl<'a> Subtable6<'a> { .value(right) .unwrap_or(0); - let array_offset = usize::try_from(l + r).ok()?.checked_mul(i16::SIZE)?; + let array_offset = usize::from(l + r).checked_mul(i16::SIZE)?; let vector_offset: u16 = Stream::read_at(kerning_array_data, array_offset)?; Stream::read_at(kerning_vector_data, usize::from(vector_offset)) diff --git a/src/tables/loca.rs b/src/tables/loca.rs index 41af44f1..e3393558 100644 --- a/src/tables/loca.rs +++ b/src/tables/loca.rs @@ -30,7 +30,7 @@ impl<'a> Table<'a> { // The number of ranges is `maxp.numGlyphs + 1`. // // Check for overflow first. - let mut total = if number_of_glyphs.get() == core::u16::MAX { + let mut total = if number_of_glyphs.get() == u16::MAX { number_of_glyphs.get() } else { number_of_glyphs.get() + 1 @@ -75,7 +75,7 @@ impl<'a> Table<'a> { #[inline] pub fn glyph_range(&self, glyph_id: GlyphId) -> Option> { let glyph_id = glyph_id.0; - if glyph_id == core::u16::MAX { + if glyph_id == u16::MAX { return None; } diff --git a/src/var_store.rs b/src/var_store.rs index cbdccbc2..9a0d9707 100644 --- a/src/var_store.rs +++ b/src/var_store.rs @@ -96,7 +96,7 @@ impl<'a> ItemVariationStore<'a> { // if the LONG_WORDS flag is not set, or 2 x that amount if the flag is set. let mut delta_set_len = word_delta_count + region_index_count; if has_long_words { - delta_set_len = delta_set_len * 2; + delta_set_len *= 2; } s.advance(usize::from(inner_index).checked_mul(usize::from(delta_set_len))?); diff --git a/tests/tables/feat.rs b/tests/tables/feat.rs index 961c40fd..03010b79 100644 --- a/tests/tables/feat.rs +++ b/tests/tables/feat.rs @@ -1,3 +1,5 @@ +#![allow(clippy::bool_assert_comparison)] + use ttf_parser::feat::Table; use crate::{convert, Unit::*}; diff --git a/tests/tables/main.rs b/tests/tables/main.rs index 0789e68a..c25e1dab 100644 --- a/tests/tables/main.rs +++ b/tests/tables/main.rs @@ -93,7 +93,7 @@ fn tables_count_overflow() { use Unit::*; let data = convert(&[ Raw(&[0x00, 0x01, 0x00, 0x00]), // magic - UInt16(std::u16::MAX), // numTables + UInt16(u16::MAX), // numTables UInt16(0), // searchRange UInt16(0), // entrySelector UInt16(0), // rangeShift @@ -129,10 +129,10 @@ fn font_collection_num_fonts_overflow() { Raw(&[0x74, 0x74, 0x63, 0x66]), // magic UInt16(0), // majorVersion UInt16(0), // minorVersion - UInt32(std::u32::MAX), // numFonts + UInt32(u32::MAX), // numFonts ]); - assert_eq!(fonts_in_collection(&data), Some(std::u32::MAX)); + assert_eq!(fonts_in_collection(&data), Some(u32::MAX)); assert_eq!( Face::parse(&data, 0).unwrap_err(), FaceParsingError::MalformedFont @@ -152,7 +152,7 @@ fn font_index_overflow() { assert_eq!(fonts_in_collection(&data), Some(1)); assert_eq!( - Face::parse(&data, std::u32::MAX).unwrap_err(), + Face::parse(&data, u32::MAX).unwrap_err(), FaceParsingError::FaceIndexOutOfBounds ); }