From 895472e994137c3731f872b4102dc763a93b4166 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 7 Oct 2024 07:12:16 +0700 Subject: [PATCH 01/16] Fix `clippy::needless_return` lint --- src/text/lang.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/text/lang.rs b/src/text/lang.rs index 30ab70a..4047511 100644 --- a/src/text/lang.rs +++ b/src/text/lang.rs @@ -152,7 +152,7 @@ impl Language { Ok(index) => index, _ => return None, }; - return Self::parse(LANG_ENTRIES.get(name_index)?.1); + Self::parse(LANG_ENTRIES.get(name_index)?.1) } /// Returns the language component. From 08596b4d5958c1f009533a46dc9b526d419461c0 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 7 Oct 2024 07:13:21 +0700 Subject: [PATCH 02/16] Fix `clippy::doc_lazy_continuation` lints --- src/shape/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shape/mod.rs b/src/shape/mod.rs index 56bd348..495c3a3 100644 --- a/src/shape/mod.rs +++ b/src/shape/mod.rs @@ -100,11 +100,11 @@ necessary glyphs. A small text label in a UI is a good example. For more complex scenarios, the shaper can be fed a single cluster at a time. This method allows you to provide: - accurate source ranges per character even if your runs -and items span multiple non-contiguous fragments + and items span multiple non-contiguous fragments - user data per character (a single `u32`) that can be used, for -example, to associate each resulting glyph with a style span + example, to associate each resulting glyph with a style span - boundary analysis per character, carrying word boundaries and -line break opportunities through the shaper. + line break opportunities through the shaper. This also provides a junction point for inserting a font fallback mechanism. From a1aca55bbc13fe92872af17a0dc3e8e6e6f28673 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 7 Oct 2024 07:14:48 +0700 Subject: [PATCH 03/16] Fix `clippy::legacy_numeric_constants` lints --- src/shape/at.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shape/at.rs b/src/shape/at.rs index 90e8b2f..5bfc5f0 100644 --- a/src/shape/at.rs +++ b/src/shape/at.rs @@ -399,7 +399,7 @@ impl FeatureStoreBuilder { lookup: &mut LookupData, ) -> Option { let start = cache.subtables.len(); - if start >= core::u16::MAX as usize { + if start >= u16::MAX as usize { return None; } lookup.subtables.0 = start as u16; @@ -420,7 +420,7 @@ impl FeatureStoreBuilder { } } let end = cache.subtables.len(); - if end >= core::u16::MAX as usize { + if end >= u16::MAX as usize { return None; } lookup.subtables.1 = end as u16; @@ -438,7 +438,7 @@ struct CoverageBuilder { impl CoverageBuilder { fn begin(&mut self) { self.coverage.clear(); - self.min = core::u16::MAX; + self.min = u16::MAX; self.max = 0; } From e44d9fc62daf760957d281239baa221c67bc7f33 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 7 Oct 2024 07:18:14 +0700 Subject: [PATCH 04/16] Fix `clippy::manual_clamp` lints --- src/attributes.rs | 6 +++--- src/scale/mod.rs | 2 +- src/shape/mod.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/attributes.rs b/src/attributes.rs index 7cf2bbb..a79b997 100644 --- a/src/attributes.rs +++ b/src/attributes.rs @@ -294,7 +294,7 @@ pub struct ObliqueAngle(pub(crate) u8); impl ObliqueAngle { /// Creates a new oblique angle from degrees. pub fn from_degrees(degrees: f32) -> Self { - let a = degrees.min(90.).max(-90.) + 90.; + let a = degrees.clamp(-90., 90.) + 90.; Self(a as u8) } @@ -455,7 +455,7 @@ impl Weight { Some(match s { "normal" => Self::NORMAL, "bold" => Self::BOLD, - _ => Self(s.parse::().ok()?.min(1000).max(1) as u16), + _ => Self(s.parse::().ok()?.clamp(1, 1000) as u16), }) } } @@ -508,7 +508,7 @@ impl Stretch { /// clamped at half percentage increments between 50% and 200%, /// inclusive. pub fn from_percentage(percentage: f32) -> Self { - let value = ((percentage.min(200.).max(50.) - 50.) * 2.) as u16; + let value = ((percentage.clamp(50., 200.) - 50.) * 2.) as u16; Self(value) } diff --git a/src/scale/mod.rs b/src/scale/mod.rs index e022ea6..8fc93b6 100644 --- a/src/scale/mod.rs +++ b/src/scale/mod.rs @@ -305,7 +305,7 @@ impl ScaleContext { /// Creates a new scaling context with the specified maximum number of /// cache entries. pub fn with_max_entries(max_entries: usize) -> Self { - let max_entries = max_entries.min(64).max(1); + let max_entries = max_entries.clamp(1, 64); Self { fonts: FontCache::new(max_entries), state: State { diff --git a/src/shape/mod.rs b/src/shape/mod.rs index 495c3a3..923fec9 100644 --- a/src/shape/mod.rs +++ b/src/shape/mod.rs @@ -298,7 +298,7 @@ impl ShapeContext { /// Creates a new shaping context with the specified maximum number of /// cache entries. pub fn with_max_entries(max_entries: usize) -> Self { - let max_entries = max_entries.min(64).max(1); + let max_entries = max_entries.clamp(1, 64); Self { font_cache: FontCache::new(max_entries), feature_cache: FeatureCache::new(max_entries), From 84b85d2d843bca98c28458bb047074f03cf4043a Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 7 Oct 2024 07:23:47 +0700 Subject: [PATCH 05/16] Fix `clippy::byte_char_slices` lint --- src/internal/head.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/internal/head.rs b/src/internal/head.rs index 5b92c8a..d6f0eb5 100644 --- a/src/internal/head.rs +++ b/src/internal/head.rs @@ -278,12 +278,7 @@ impl<'a> Os2<'a> { /// Returns a four character font vendor identifier. pub fn vendor_id(&self) -> &'a str { - core::str::from_utf8( - self.0 - .read_bytes(58, 4) - .unwrap_or(&[b'n', b'o', b'n', b'e']), - ) - .unwrap_or("none") + core::str::from_utf8(self.0.read_bytes(58, 4).unwrap_or(b"none")).unwrap_or("none") } /// Returns the font selection bit flags. From 31657e53c55f99939865fa1da77bc5b1d4beb520 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 7 Oct 2024 07:29:07 +0700 Subject: [PATCH 06/16] Fix `clippy::redundant_closure` lints --- src/scale/bitmap/mod.rs | 10 +++++----- src/scale/mod.rs | 4 +--- src/shape/mod.rs | 4 +--- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/scale/bitmap/mod.rs b/src/scale/bitmap/mod.rs index bcb7ea3..fba3306 100644 --- a/src/scale/bitmap/mod.rs +++ b/src/scale/bitmap/mod.rs @@ -125,7 +125,7 @@ pub fn resize( target_height, scratch, 0., - &|x| nearest(x), + &nearest, ), Bilinear => resample( image, @@ -137,7 +137,7 @@ pub fn resize( target_height, scratch, 1., - &|x| bilinear(x), + &bilinear, ), Bicubic => resample( image, @@ -149,7 +149,7 @@ pub fn resize( target_height, scratch, 2., - &|x| bicubic(x), + &bicubic, ), Mitchell => resample( image, @@ -161,7 +161,7 @@ pub fn resize( target_height, scratch, 2., - &|x| mitchell(x), + &mitchell, ), Lanczos3 => resample( image, @@ -173,7 +173,7 @@ pub fn resize( target_height, scratch, 3., - &|x| lanczos3(x), + &lanczos3, ), Gaussian => resample( image, diff --git a/src/scale/mod.rs b/src/scale/mod.rs index 8fc93b6..637b3f3 100644 --- a/src/scale/mod.rs +++ b/src/scale/mod.rs @@ -349,9 +349,7 @@ pub struct ScalerBuilder<'a> { impl<'a> ScalerBuilder<'a> { fn new(context: &'a mut ScaleContext, font: impl Into>) -> Self { let font = font.into(); - let (id, proxy) = context - .fonts - .get(&font, None, |font| ScalerProxy::from_font(font)); + let (id, proxy) = context.fonts.get(&font, None, ScalerProxy::from_font); let skrifa_font = if font.offset == 0 { skrifa::FontRef::new(font.data).ok() } else { diff --git a/src/shape/mod.rs b/src/shape/mod.rs index 923fec9..6ecb96b 100644 --- a/src/shape/mod.rs +++ b/src/shape/mod.rs @@ -396,9 +396,7 @@ impl<'a> ShaperBuilder<'a> { id: [u64; 2], ) -> Self { let font = font.into(); - let (font_id, font_entry) = context - .font_cache - .get(&font, Some(id), |font| FontEntry::new(font)); + let (font_id, font_entry) = context.font_cache.get(&font, Some(id), FontEntry::new); context.state.reset(); context.coords.clear(); Self { From ed0ce0bbd672026fc083cfbbaff4c3f4fbcfa242 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 7 Oct 2024 07:35:44 +0700 Subject: [PATCH 07/16] Fix `clippy::needless_borrow` lints --- src/scale/bitmap/png.rs | 8 ++++---- src/scale/mod.rs | 4 ++-- src/shape/at.rs | 8 ++++---- src/shape/partition.rs | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/scale/bitmap/png.rs b/src/scale/bitmap/png.rs index 44abce5..5923f40 100644 --- a/src/scale/bitmap/png.rs +++ b/src/scale/bitmap/png.rs @@ -323,10 +323,10 @@ fn decode_data( bwidth, )?; if depth == 8 { - E::emit(&state, line, target, start, y, w, inc, cols)?; + E::emit(state, line, target, start, y, w, inc, cols)?; } else { normalize(line, out_line, depth, has_palette, cols, trunc_16)?; - E::emit(&state, out_line, target, start, y, w, inc, cols)?; + E::emit(state, out_line, target, start, y, w, inc, cols)?; } std::mem::swap(&mut prev_line, &mut line); y += row_inc; @@ -347,7 +347,7 @@ fn decode_data( let source = decomp.get(offset..end)?; let ty = *source.get(0)?; defilter(ty, source.get(1..)?, line, prev_line, bwidth)?; - E::emit(&state, line, target, 0, y, w, 1, w)?; + E::emit(state, line, target, 0, y, w, 1, w)?; std::mem::swap(&mut prev_line, &mut line); } } else { @@ -358,7 +358,7 @@ fn decode_data( let ty = *source.get(0)?; defilter(ty, source.get(1..)?, line, prev_line, bwidth)?; normalize(line, out_line, depth, has_palette, w, trunc_16)?; - E::emit(&state, out_line, target, 0, y, w, 1, w)?; + E::emit(state, out_line, target, 0, y, w, 1, w)?; std::mem::swap(&mut prev_line, &mut line); } } diff --git a/src/scale/mod.rs b/src/scale/mod.rs index 637b3f3..f2ff2c0 100644 --- a/src/scale/mod.rs +++ b/src/scale/mod.rs @@ -439,7 +439,7 @@ impl<'a> ScalerBuilder<'a> { id: self.id, outlines, size: skrifa_size, - coords: &self.coords, + coords: self.coords, }; self.hinting_cache.get(&key) } @@ -554,7 +554,7 @@ impl<'a> Scaler<'a> { } else { ( self.skrifa_size, - skrifa::instance::LocationRef::new(&self.coords), + skrifa::instance::LocationRef::new(self.coords), ) .into() }; diff --git a/src/shape/at.rs b/src/shape/at.rs index 5bfc5f0..b459601 100644 --- a/src/shape/at.rs +++ b/src/shape/at.rs @@ -94,7 +94,7 @@ impl StageOffsets { script: RawTag, lang: Option, ) -> Option<(Self, [RawTag; 2])> { - let (lang, tags) = language_or_default_by_tags(&b, base, script, lang)?; + let (lang, tags) = language_or_default_by_tags(b, base, script, lang)?; let var = feature_var_offset(b, base); Some((Self { base, lang, var }, tags)) } @@ -1537,7 +1537,7 @@ impl<'a, 'b, 'c> ApplyContext<'a, 'b, 'c> { } let b = self.data; let list_base = self.gsubgpos + b.read::(self.gsubgpos as usize + 8)? as u32; - let lookup = lookup_data(&self.data, self.stage, list_base, index, 0, Some(self.defs))?; + let lookup = lookup_data(self.data, self.stage, list_base, index, 0, Some(self.defs))?; self.storage.stack[self.top as usize] = self.s; self.top += 1; let v = self.apply_uncached(&lookup, cur, end + 1, first); @@ -1621,12 +1621,12 @@ impl<'a, 'b, 'c> ApplyContext<'a, 'b, 'c> { #[inline(always)] fn coverage(&self, coverage_offset: usize, glyph_id: u16) -> Option { - coverage(&self.data, coverage_offset as u32, glyph_id) + coverage(self.data, coverage_offset as u32, glyph_id) } #[inline(always)] fn class(&self, classdef_offset: usize, glyph_id: u16) -> u16 { - classdef(&self.data, classdef_offset as u32, glyph_id) + classdef(self.data, classdef_offset as u32, glyph_id) } } diff --git a/src/shape/partition.rs b/src/shape/partition.rs index 462895d..1bedf48 100644 --- a/src/shape/partition.rs +++ b/src/shape/partition.rs @@ -237,12 +237,12 @@ where loop { shaper.add_cluster(cluster); if !parser.next(cluster) { - f(&font, shaper); + f(font, shaper); return false; } if let Some(next_font) = selector.select_font(cluster) { if next_font != *font { - f(&font, shaper); + f(font, shaper); *current_font = Some(next_font); return true; } From b74c93eb7c1b450f6509fd5e250aa4e06643015d Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 7 Oct 2024 07:38:59 +0700 Subject: [PATCH 08/16] Fix `clippy::unnecessary_cast` lints --- src/feature/util.rs | 2 +- src/font.rs | 4 ++-- src/internal/at.rs | 2 +- src/internal/cmap.rs | 2 +- src/palette.rs | 6 +++--- src/shape/at.rs | 4 ++-- src/shape/mod.rs | 2 +- src/strike.rs | 18 +++++++++--------- src/text/compose.rs | 2 +- src/text/unicode.rs | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/feature/util.rs b/src/feature/util.rs index 1ced2de..c918695 100644 --- a/src/feature/util.rs +++ b/src/feature/util.rs @@ -33,7 +33,7 @@ pub fn desc_from_at(tag: RawTag) -> Option<(usize, &'static str)> { /// Returns a feature tag and description from an AAT feature /// and selector. pub fn desc_from_aat(feature: u16, selector: u16) -> Option<(usize, RawTag, &'static str)> { - let key = ((feature << 8) | selector) as u16; + let key = (feature << 8) | selector; Some(match AAT_TO_AT.binary_search_by(|pair| pair.0.cmp(&key)) { Ok(index) => { let (tag, desc) = FEATURES[AAT_TO_AT[index].1 as usize]; diff --git a/src/font.rs b/src/font.rs index 7837952..76e34c0 100644 --- a/src/font.rs +++ b/src/font.rs @@ -209,7 +209,7 @@ impl<'a> Iterator for Fonts<'a> { type Item = FontRef<'a>; fn size_hint(&self) -> (usize, Option) { - let remaining = (self.data.len - self.pos) as usize; + let remaining = self.data.len - self.pos; (remaining, Some(remaining)) } @@ -232,7 +232,7 @@ impl<'a> Iterator for Fonts<'a> { impl<'a> ExactSizeIterator for Fonts<'a> { fn len(&self) -> usize { - (self.data.len - self.pos) as usize + self.data.len - self.pos } } diff --git a/src/internal/at.rs b/src/internal/at.rs index 5973226..e32f38c 100644 --- a/src/internal/at.rs +++ b/src/internal/at.rs @@ -603,7 +603,7 @@ pub fn lookup_data( _ => return None, } }; - let ignored = ((f as u8) & 0b1110) | 1 << 5; + let ignored = (f & 0b1110) | 1 << 5; Some(LookupData { index, stage, diff --git a/src/internal/cmap.rs b/src/internal/cmap.rs index f56aa44..81b84b6 100644 --- a/src/internal/cmap.rs +++ b/src/internal/cmap.rs @@ -74,7 +74,7 @@ pub fn map(data: &[u8], subtable: u32, format: u8, codepoint: u32) -> Option(range_base + diff).unwrap_or(0); return if id != 0 { - Some((id as i32 + delta as i32) as u16) + Some((id as i32 + delta) as u16) } else { Some(0) }; diff --git a/src/palette.rs b/src/palette.rs index cad6e9f..b129c88 100644 --- a/src/palette.rs +++ b/src/palette.rs @@ -49,7 +49,7 @@ impl<'a> ColorPalettes<'a> { let version = b.read::(0)?; let num_entries = b.read::(2)?; let offset = b.read::(8)? as usize; - let first = b.read::(12 + index as usize * 2)? as usize; + let first = b.read::(12 + index * 2)? as usize; let offset = offset + first * 4; Some(ColorPalette { font: self.font, @@ -94,7 +94,7 @@ impl<'a> ColorPalette<'a> { return None; } Some(StringId::Other( - d.read::(labels_offset + self.index as usize * 2)?, + d.read::(labels_offset + self.index * 2)?, )) } @@ -152,7 +152,7 @@ impl<'a> ColorPalette<'a> { if types_offset == 0 { return None; } - d.read::(types_offset + self.index as usize * 4) + d.read::(types_offset + self.index * 4) } } diff --git a/src/shape/at.rs b/src/shape/at.rs index b459601..91805dc 100644 --- a/src/shape/at.rs +++ b/src/shape/at.rs @@ -353,7 +353,7 @@ impl FeatureStoreBuilder { cache.features.push((ftag, fbit, stage)); let foffset = if let Some(v) = vars { if let Some(offset) = v.apply(b, findex as u16) { - offset as usize + offset } else { fbase + b.read::(rec + 4)? as usize } @@ -1232,7 +1232,7 @@ impl<'a, 'b, 'c> ApplyContext<'a, 'b, 'c> { let base_anchor = self.anchor(lig_attach + anchor_offset)?; let dx = base_anchor.0 - mark_anchor.0; let dy = base_anchor.1 - mark_anchor.1; - self.buf.position_mark(cur, prev, dx as f32, dy as f32); + self.buf.position_mark(cur, prev, dx, dy); return Some(true); } Context1 => { diff --git a/src/shape/mod.rs b/src/shape/mod.rs index 6ecb96b..f0a0fa3 100644 --- a/src/shape/mod.rs +++ b/src/shape/mod.rs @@ -736,7 +736,7 @@ impl<'a> Shaper<'a> { // Collect the range for the non-empty cluster. let end = g.cluster as usize; let start = last_cluster as usize; - let mut group_end = start as usize + 1; + let mut group_end = start + 1; while group_end < end && buf.infos[group_end].1 { group_end += 1; } diff --git a/src/strike.rs b/src/strike.rs index 59e3db7..de3acf6 100644 --- a/src/strike.rs +++ b/src/strike.rs @@ -137,9 +137,9 @@ impl<'a> BitmapStrikes<'a> { return None; } let offset = if self.is_sbix { - self.data.read::(8 + index as usize * 4)? as usize + self.data.read::(8 + index * 4)? as usize } else { - 8 + index as usize * 48 + 8 + index * 48 }; Some(BitmapStrike { data: self.data, @@ -417,17 +417,17 @@ impl<'a> Bitmap<'a> { match self.format { BitmapFormat::Packed(bits) => match bits { 1 => { - for x in 0..(w * h) as usize { + for x in 0..(w * h) { dst[x] = (src[x >> 3] >> (!x & 7) & 1) * 255; } } 2 => { - for x in 0..(w * h) as usize { + for x in 0..(w * h) { dst[x] = (src[x >> 2] >> (!(x * 2) & 2) & 3) * 85; } } 4 => { - for x in 0..(w * h) as usize { + for x in 0..(w * h) { dst[x] = (src[x >> 1] >> (!(x * 4) & 4) & 15) * 17; } } @@ -440,7 +440,7 @@ impl<'a> Bitmap<'a> { 1 => { let mut dst_idx = 0; for row in src.chunks(((w * bits as usize) + 7) / 8) { - for x in 0..w as usize { + for x in 0..w { dst[dst_idx] = (row[x >> 3] >> (!x & 7) & 1) * 255; dst_idx += 1; } @@ -449,7 +449,7 @@ impl<'a> Bitmap<'a> { 2 => { let mut dst_idx = 0; for row in src.chunks(((w * bits as usize) + 7) / 8) { - for x in 0..w as usize { + for x in 0..w { dst[dst_idx] = (row[x >> 2] >> (!(x * 2) & 2) & 3) * 85; dst_idx += 1; } @@ -458,7 +458,7 @@ impl<'a> Bitmap<'a> { 4 => { let mut dst_idx = 0; for row in src.chunks(((w * bits as usize) + 7) / 8) { - for x in 0..w as usize { + for x in 0..w { dst[dst_idx] = (row[x >> 1] >> (!(x * 4) & 4) & 15) * 17; dst_idx += 1; } @@ -588,7 +588,7 @@ fn get_location( let offset = array_offset + d.read::(offset + 4)? as usize; let index_format = d.read::(offset)?; let image_format = d.read::(offset + 2)? as u8; - let image_offset = d.read::(offset + 4)? as u32; + let image_offset = d.read::(offset + 4)?; let base = offset + 8; let mut loc = Location { ppem, diff --git a/src/text/compose.rs b/src/text/compose.rs index 8da89a5..c775805 100644 --- a/src/text/compose.rs +++ b/src/text/compose.rs @@ -82,7 +82,7 @@ fn pair_index(c: u32, table: &[(u32, u16, u16)]) -> Option { return None; } let end = start + entry.1 as usize; - if c as usize <= end { + if c <= end { return Some(entry.2 as usize + (c - start)); } } diff --git a/src/text/unicode.rs b/src/text/unicode.rs index 42354bc..713ce4f 100644 --- a/src/text/unicode.rs +++ b/src/text/unicode.rs @@ -167,7 +167,7 @@ impl From for Properties { impl From<&'_ u32> for Properties { fn from(ch: &'_ u32) -> Self { - Self::new(*ch as u32) + Self::new(*ch) } } From 7c08ceb940616b4fc1a709d589946a1fa5aea314 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 7 Oct 2024 07:40:38 +0700 Subject: [PATCH 09/16] Fix `clippy::explicit_auto_deref` lints --- src/text/lang.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/text/lang.rs b/src/text/lang.rs index 4047511..ff2cc27 100644 --- a/src/text/lang.rs +++ b/src/text/lang.rs @@ -65,7 +65,7 @@ impl Language { lang.lang_len = 2; let key = tag2(&[a, b]); if let Ok(index) = LANG_BY_TAG2.binary_search_by(|x| x.0.cmp(&key)) { - lang_index = (*LANG_BY_TAG2.get(index)?).1 + lang_index = LANG_BY_TAG2.get(index)?.1 } } 3 => { @@ -79,7 +79,7 @@ impl Language { lang.lang_len = 3; let key = tag3(&[a, b, c]); if let Ok(index) = LANG_BY_TAG3.binary_search_by(|x| x.0.cmp(&key)) { - lang_index = (*LANG_BY_TAG3.get(index)?).1 as u16 + lang_index = LANG_BY_TAG3.get(index)?.1 as u16 } } _ => return None, From 53e698f0db40392a657fc070e9edabb45cd39399 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 7 Oct 2024 07:42:39 +0700 Subject: [PATCH 10/16] Fix `clippy::partialeq_to_none` lints --- src/shape/buffer.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shape/buffer.rs b/src/shape/buffer.rs index 7ff7fc6..f23f358 100644 --- a/src/shape/buffer.rs +++ b/src/shape/buffer.rs @@ -564,7 +564,7 @@ pub fn reorder_complex(glyphs: &mut [GlyphData], buf: &mut Vec, order } match g.char_class { Base => { - if first_base == None { + if first_base.is_none() { first_base = Some(i); ignored[i] = true; } @@ -576,13 +576,13 @@ pub fn reorder_complex(glyphs: &mut [GlyphData], buf: &mut Vec, order last_halant = Some(i); } Reph => { - if reph == None { + if reph.is_none() { reph = Some(i); ignored[i] = true; } } Pref => { - if pref == None { + if pref.is_none() { pref = Some(i); ignored[i] = true; } From 78a1200523f1e9db4db8114ff78a19cb500c9319 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 7 Oct 2024 07:43:53 +0700 Subject: [PATCH 11/16] Fix `clippy::map_flatten` lints --- src/internal/var.rs | 3 +-- src/palette.rs | 3 +-- src/scale/mod.rs | 3 +-- src/shape/engine.rs | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/internal/var.rs b/src/internal/var.rs index c8dc0b0..0370e94 100644 --- a/src/internal/var.rs +++ b/src/internal/var.rs @@ -146,8 +146,7 @@ impl VarAxis { }; value = value.min(Fixed::ONE).max(-Fixed::ONE); value = avar - .map(|(data, avar)| adjust_axis(data, avar, self.index, value)) - .flatten() + .and_then(|(data, avar)| adjust_axis(data, avar, self.index, value)) .unwrap_or(value); value.to_f2dot14() } diff --git a/src/palette.rs b/src/palette.rs index b129c88..fe389cf 100644 --- a/src/palette.rs +++ b/src/palette.rs @@ -102,8 +102,7 @@ impl<'a> ColorPalette<'a> { /// language. pub fn name(&self, language: Option<&str>) -> Option> { self.name_id() - .map(|id| self.font.localized_strings().find_by_id(id, language)) - .flatten() + .and_then(|id| self.font.localized_strings().find_by_id(id, language)) } /// Returns the theme usability of the palette, if available. diff --git a/src/scale/mod.rs b/src/scale/mod.rs index f2ff2c0..ffb6ce7 100644 --- a/src/scale/mod.rs +++ b/src/scale/mod.rs @@ -917,8 +917,7 @@ impl<'a> Render<'a> { .render_into(&mut scratch[..], None); let color = layer .color_index() - .map(|i| palette.map(|p| p.get(i))) - .flatten() + .and_then(|i| palette.map(|p| p.get(i))) .unwrap_or(self.foreground); bitmap::blit( &scratch[..], diff --git a/src/shape/engine.rs b/src/shape/engine.rs index f1f614d..ce9d413 100644 --- a/src/shape/engine.rs +++ b/src/shape/engine.rs @@ -43,7 +43,7 @@ impl<'a> Engine<'a> { let data = Bytes::new(font_data); let gdef = Gdef::from_offset(font_data, metadata.gdef).unwrap_or_else(Gdef::empty); let script_tag = script.to_opentype(); - let lang_tag = lang.map(|l| l.to_opentype()).flatten(); + let lang_tag = lang.and_then(|l| l.to_opentype()); let (gsub, stags) = if metadata.sub_mode == SubMode::Gsub { at::StageOffsets::new(&data, metadata.gsub, script_tag, lang_tag).unwrap_or_default() } else { From 8db7c9a7a62192e08ed69e3729bcfb2aa807f3ab Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 7 Oct 2024 07:46:11 +0700 Subject: [PATCH 12/16] Fix `clippy::redundant_slicing` lint --- src/scale/outline.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scale/outline.rs b/src/scale/outline.rs index 055dd77..1ee7689 100644 --- a/src/scale/outline.rs +++ b/src/scale/outline.rs @@ -157,7 +157,7 @@ pub struct LayerMut<'a> { impl<'a> LayerMut<'a> { /// Returns the sequence of points for the layer. pub fn points(&'a self) -> &'a [Point] { - &self.points[..] + self.points } /// Returns a mutable reference the sequence of points for the layer. From d43f2a98c6eb7cf37d7e54998ee0896ac5a69564 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 7 Oct 2024 07:52:02 +0700 Subject: [PATCH 13/16] Fix `clippy::doc_markdown` lints --- .clippy.toml | 2 ++ src/internal/aat.rs | 2 +- src/internal/parse.rs | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 .clippy.toml diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 0000000..ece43c8 --- /dev/null +++ b/.clippy.toml @@ -0,0 +1,2 @@ +# Don't warn about these identifiers when using clippy::doc_markdown. +doc-valid-idents = ["ClearType", "HarfBuzz", "OpenType", "PostScript", ".."] diff --git a/src/internal/aat.rs b/src/internal/aat.rs index ba63ee4..9bc878d 100644 --- a/src/internal/aat.rs +++ b/src/internal/aat.rs @@ -8,7 +8,7 @@ pub const KERX: RawTag = raw_tag(b"kerx"); pub const ANKR: RawTag = raw_tag(b"ankr"); pub const KERN: RawTag = raw_tag(b"kern"); -/// Maximum number of times we allow consecutive DONT_ADVANCE states. +/// Maximum number of times we allow consecutive `DONT_ADVANCE` states. const MAX_CYCLES: u16 = 16; /// Gets a value from a lookup table. diff --git a/src/internal/parse.rs b/src/internal/parse.rs index ccede4d..93ddac2 100644 --- a/src/internal/parse.rs +++ b/src/internal/parse.rs @@ -274,7 +274,7 @@ impl<'a> Stream<'a> { } /// An array wrapping a byte buffer over a sequence of values that implement -/// FromBeData. +/// [`FromBeData`]. #[derive(Copy, Clone)] pub struct Array<'a, T: FromBeData> { data: &'a [u8], From 73aa8df3225c7aab424b4e94d863885a2130f46a Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 7 Oct 2024 07:54:05 +0700 Subject: [PATCH 14/16] Fix `clippy::semicolon_if_nothing_returned` lints --- src/internal/var.rs | 4 ++-- src/metrics.rs | 2 +- src/scale/outline.rs | 2 +- src/shape/at.rs | 2 +- src/shape/buffer.rs | 4 ++-- src/shape/engine.rs | 2 +- src/text/lang.rs | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/internal/var.rs b/src/internal/var.rs index 0370e94..73a8f59 100644 --- a/src/internal/var.rs +++ b/src/internal/var.rs @@ -312,9 +312,9 @@ pub fn item_delta( } else if coord == peak { continue; } else if coord < peak { - scalar = scalar * (coord - start) / (peak - start) + scalar = scalar * (coord - start) / (peak - start); } else { - scalar = scalar * (end - coord) / (end - peak) + scalar = scalar * (end - coord) / (end - peak); }; } let val = if idx >= short_count { diff --git a/src/metrics.rs b/src/metrics.rs index 1e0188d..c824024 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -389,7 +389,7 @@ impl<'a> GlyphMetrics<'a> { pub fn lsb(&self, glyph_id: GlyphId) -> f32 { let mut v = xmtx::sb(self.data, self.hmtx, self.hmtx_count, glyph_id) as f32; if self.hvar != 0 { - v += var::sb_delta(self.data, self.hvar, glyph_id, self.coords) + v += var::sb_delta(self.data, self.hvar, glyph_id, self.coords); } v * self.scale } diff --git a/src/scale/outline.rs b/src/scale/outline.rs index 1ee7689..eefe989 100644 --- a/src/scale/outline.rs +++ b/src/scale/outline.rs @@ -296,7 +296,7 @@ impl Outline { points: (0, points_end), verbs: (0, verbs_end), color_index: None, - }) + }); } } } diff --git a/src/shape/at.rs b/src/shape/at.rs index 91805dc..68eb0f5 100644 --- a/src/shape/at.rs +++ b/src/shape/at.rs @@ -167,7 +167,7 @@ impl FeatureStore { let mut sub = self.groups.basic; let mut pos = self.groups.position; if dir == Direction::RightToLeft { - sub |= self.groups.rtl + sub |= self.groups.rtl; } for feature in features { if let Ok(index) = self.features.binary_search_by(|x| x.0.cmp(&feature.0)) { diff --git a/src/shape/buffer.rs b/src/shape/buffer.rs index f23f358..79bc066 100644 --- a/src/shape/buffer.rs +++ b/src/shape/buffer.rs @@ -190,7 +190,7 @@ impl Buffer { component: !0, cluster, data: ch.data, - }) + }); } fn _push_hangul_char(&mut self, ch: &Char) { @@ -217,7 +217,7 @@ impl Buffer { component: !0, cluster, data: ch.data, - }) + }); } fn push_cluster(&mut self, cluster: &CharCluster) { diff --git a/src/shape/engine.rs b/src/shape/engine.rs index ce9d413..8980f8d 100644 --- a/src/shape/engine.rs +++ b/src/shape/engine.rs @@ -205,7 +205,7 @@ impl<'a> Engine<'a> { for (tag, value) in features { if let Some((selector, [on, off])) = feature_from_tag(*tag) { let setting = if *value == 0 { off } else { on }; - selectors.push((selector, setting)) + selectors.push((selector, setting)); } } selectors.sort_unstable(); diff --git a/src/text/lang.rs b/src/text/lang.rs index ff2cc27..dc84d61 100644 --- a/src/text/lang.rs +++ b/src/text/lang.rs @@ -65,7 +65,7 @@ impl Language { lang.lang_len = 2; let key = tag2(&[a, b]); if let Ok(index) = LANG_BY_TAG2.binary_search_by(|x| x.0.cmp(&key)) { - lang_index = LANG_BY_TAG2.get(index)?.1 + lang_index = LANG_BY_TAG2.get(index)?.1; } } 3 => { @@ -79,7 +79,7 @@ impl Language { lang.lang_len = 3; let key = tag3(&[a, b, c]); if let Ok(index) = LANG_BY_TAG3.binary_search_by(|x| x.0.cmp(&key)) { - lang_index = LANG_BY_TAG3.get(index)?.1 as u16 + lang_index = LANG_BY_TAG3.get(index)?.1 as u16; } } _ => return None, From 95ebf5893a4ff9b964ccbeaac296bee79edb229c Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 7 Oct 2024 07:55:39 +0700 Subject: [PATCH 15/16] Enable some clippy lints by default Enable `clippy::doc_markdown`, `clippy::semicolon_if_nothing_returned` --- Cargo.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 6a23af1..f98ee2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,10 @@ default = ["scale", "render"] scale = ["dep:yazi", "dep:zeno"] render = ["scale", "zeno/eval"] +[lints] +clippy.doc_markdown = "warn" +clippy.semicolon_if_nothing_returned = "warn" + [dependencies] yazi = { version = "0.1.6", optional = true } zeno = { version = "0.2.2", optional = true, default-features = false } From b6db71e9a3c209505967d3588e39a8eb257d2a48 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Mon, 7 Oct 2024 07:59:08 +0700 Subject: [PATCH 16/16] Fix `clippy::manual_find` lint --- src/shape/at.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/shape/at.rs b/src/shape/at.rs index 68eb0f5..c0cd974 100644 --- a/src/shape/at.rs +++ b/src/shape/at.rs @@ -715,12 +715,7 @@ impl<'a, 'b, 'c> ApplyContext<'a, 'b, 'c> { } fn next(&self, index: usize) -> Option { - for i in (index + 1)..self.s.end { - if !self.ignored(i) { - return Some(i); - } - } - None + ((index + 1)..self.s.end).find(|&i| !self.ignored(i)) } fn previous(&self, index: usize) -> Option {