Skip to content

Commit

Permalink
Merge pull request #140 from asibahi/main
Browse files Browse the repository at this point in the history
Clippy fixes
  • Loading branch information
khaledhosny authored Oct 25, 2024
2 parents 21f811e + 1d2fda6 commit 20c75ad
Show file tree
Hide file tree
Showing 25 changed files with 108 additions and 96 deletions.
8 changes: 4 additions & 4 deletions examples/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fn main() {

for text in lines {
let mut buffer = rustybuzz::UnicodeBuffer::new();
buffer.push_str(&text);
buffer.push_str(text);

if let Some(d) = args.direction {
buffer.set_direction(d);
Expand Down Expand Up @@ -250,7 +250,7 @@ fn parse_unicodes(s: &str) -> Result<String, String> {
fn parse_features(s: &str) -> Result<Vec<rustybuzz::Feature>, String> {
let mut features = Vec::new();
for f in s.split(',') {
features.push(rustybuzz::Feature::from_str(&f)?);
features.push(rustybuzz::Feature::from_str(f)?);
}

Ok(features)
Expand All @@ -259,7 +259,7 @@ fn parse_features(s: &str) -> Result<Vec<rustybuzz::Feature>, String> {
fn parse_variations(s: &str) -> Result<Vec<rustybuzz::Variation>, String> {
let mut variations = Vec::new();
for v in s.split(',') {
variations.push(rustybuzz::Variation::from_str(&v)?);
variations.push(rustybuzz::Variation::from_str(v)?);
}

Ok(variations)
Expand All @@ -270,7 +270,7 @@ fn parse_cluster(s: &str) -> Result<rustybuzz::BufferClusterLevel, String> {
"0" => Ok(rustybuzz::BufferClusterLevel::MonotoneGraphemes),
"1" => Ok(rustybuzz::BufferClusterLevel::MonotoneCharacters),
"2" => Ok(rustybuzz::BufferClusterLevel::Characters),
_ => Err(format!("invalid cluster level")),
_ => Err("invalid cluster level".to_string()),
}
}

Expand Down
2 changes: 2 additions & 0 deletions scripts/gen-vowel-constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def __str__(self, index=0, depth=4):

print('// WARNING: this file was generated by scripts/gen-vowel-constraints.py')
print()
print('#![allow(clippy::single_match)]')
print()
print('use super::buffer::hb_buffer_t;')
print('use super::ot_layout::*;')
print('use super::script;')
Expand Down
2 changes: 1 addition & 1 deletion src/hb/aat_layout_kerx_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ fn apply_state_machine_kerning<T, E>(
// go differently if we start from state 0 here.
if state != START_OF_TEXT && buffer.backtrack_len() != 0 && buffer.idx < buffer.len {
// If there's no value and we're just epsilon-transitioning to state 0, safe to break.
if entry.is_actionable() || !(entry.new_state == START_OF_TEXT && !entry.has_advance())
if entry.is_actionable() || entry.new_state != START_OF_TEXT || entry.has_advance()
{
buffer.unsafe_to_break_from_outbuffer(
Some(buffer.backtrack_len() - 1),
Expand Down
14 changes: 7 additions & 7 deletions src/hb/aat_layout_morx_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn compile_flags(
};

let chains = face.tables().morx.as_ref()?.chains;
let chain_len = chains.clone().into_iter().count();
let chain_len = chains.into_iter().count();
map.chain_flags.resize(chain_len, vec![]);

for (chain, chain_flags) in chains.into_iter().zip(map.chain_flags.iter_mut()) {
Expand Down Expand Up @@ -72,7 +72,7 @@ pub fn apply<'a>(c: &mut hb_aat_apply_context_t<'a>, map: &'a mut hb_aat_map_t)
c.buffer.unsafe_to_concat(None, None);

let chains = c.face.tables().morx.as_ref()?.chains;
let chain_len = chains.clone().into_iter().count();
let chain_len = chains.into_iter().count();
map.chain_flags.resize(chain_len, vec![]);

for (chain, chain_flags) in chains.into_iter().zip(map.chain_flags.iter_mut()) {
Expand Down Expand Up @@ -256,18 +256,18 @@ fn drive<T: FromData>(
};

// 2c'
if c.is_actionable(&wouldbe_entry, &ac.buffer) {
if c.is_actionable(&wouldbe_entry, ac.buffer) {
return false;
}

// 2c"
return next_state == wouldbe_entry.new_state
&& c.can_advance(&entry) == c.can_advance(&wouldbe_entry);
next_state == wouldbe_entry.new_state
&& c.can_advance(&entry) == c.can_advance(&wouldbe_entry)
};

let is_safe_to_break = || {
// 1
if c.is_actionable(&entry, &ac.buffer) {
if c.is_actionable(&entry, ac.buffer) {
return false;
}

Expand All @@ -285,7 +285,7 @@ fn drive<T: FromData>(
Some(v) => v,
None => return false,
};
return !c.is_actionable(&end_entry, &ac.buffer);
!c.is_actionable(&end_entry, ac.buffer)
};

if !is_safe_to_break() && ac.buffer.backtrack_len() > 0 && ac.buffer.idx < ac.buffer.len {
Expand Down
4 changes: 1 addition & 3 deletions src/hb/aat_layout_trak_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ impl TrackTableDataExt for ttf_parser::trak::TrackData<'_> {
.position(|s| s.0 >= ptem)
.unwrap_or(self.sizes.len() as usize - 1);

if idx > 0 {
idx -= 1;
}
idx = idx.saturating_sub(1);

self.interpolate_at(idx as u16, ptem, &track)
.map(|n| n.round() as i32)
Expand Down
8 changes: 4 additions & 4 deletions src/hb/aat_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl hb_aat_map_builder_t {
let exposes_feature = feat
.names
.find(HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_ALTERNATIVES as u16)
.map(|f| f.setting_names.len() != 0)
.map(|f| !f.setting_names.is_empty())
.unwrap_or(false);

if !exposes_feature {
Expand All @@ -128,7 +128,7 @@ impl hb_aat_map_builder_t {
let mut feature_name = feat.names.find(mapping.aat_feature_type as u16);

match feature_name {
Some(feature) if feature.setting_names.len() != 0 => {}
Some(feature) if !feature.setting_names.is_empty() => {}
_ => {
// Special case: Chain::compile_flags will fall back to the deprecated version of
// small-caps if necessary, so we need to check for that possibility.
Expand All @@ -145,7 +145,7 @@ impl hb_aat_map_builder_t {
}

match feature_name {
Some(feature_name) if feature_name.setting_names.len() != 0 => {
Some(feature_name) if !feature_name.setting_names.is_empty() => {
let setting = if feature.value != 0 {
mapping.selector_to_enable
} else {
Expand Down Expand Up @@ -210,7 +210,7 @@ impl hb_aat_map_builder_t {
self.range_first = last_index;
self.range_last = event.index.wrapping_sub(1);

if self.current_features.len() != 0 {
if !self.current_features.is_empty() {
self.current_features.sort();
let mut j = 0;
for i in 1..self.current_features.len() {
Expand Down
26 changes: 13 additions & 13 deletions src/hb/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ pub mod glyph_flag {
/// line-break position, in the following way:
///
/// 1. Iterate back from the line-break
/// position until the first cluster
/// start position that is NOT unsafe-to-concat,
/// position until the first cluster
/// start position that is NOT unsafe-to-concat,
/// 2. shape the segment from there till the
/// end of line, 3. check whether the resulting
/// glyph-run also is clear of the unsafe-to-concat
/// at its start-of-text position; if it is, just
/// splice it into place and the line is shaped;
/// If not, move on to a position further back that
/// is clear of unsafe-to-concat and retry from
/// there, and repeat.
/// end of line, 3. check whether the resulting
/// glyph-run also is clear of the unsafe-to-concat
/// at its start-of-text position; if it is, just
/// splice it into place and the line is shaped;
/// If not, move on to a position further back that
/// is clear of unsafe-to-concat and retry from
/// there, and repeat.
///
/// At the start of next line a similar
/// algorithm can be implemented.
Expand Down Expand Up @@ -87,7 +87,7 @@ pub mod glyph_flag {
///
/// The UNSAFE_TO_BREAK flag will always imply this flag.
/// To use this flag, you must enable the buffer flag
/// PRODUCE_UNSAFE_TO_CONCAT during shaping, otherwise
/// PRODUCE_UNSAFE_TO_CONCAT during shaping, otherwise
/// the buffer flag will not be reliably produced.
pub const UNSAFE_TO_CONCAT: u32 = 0x00000002;

Expand Down Expand Up @@ -845,7 +845,7 @@ impl hb_buffer_t {
let not_mask = !mask;
value &= mask;

if cluster_start == 0 && cluster_end == core::u32::MAX {
if cluster_start == 0 && cluster_end == u32::MAX {
for info in &mut self.info[..self.len] {
info.mask = (info.mask & not_mask) | value;
}
Expand Down Expand Up @@ -1103,7 +1103,7 @@ impl hb_buffer_t {
} else {
let mut cluster = self._infos_find_min_cluster(&self.info, self.idx, end, None);
cluster = self._infos_find_min_cluster(
&self.out_info(),
self.out_info(),
start,
self.out_len,
Some(cluster),
Expand Down Expand Up @@ -1325,7 +1325,7 @@ impl hb_buffer_t {
end: usize,
cluster: Option<u32>,
) -> u32 {
let mut cluster = cluster.unwrap_or(core::u32::MAX);
let mut cluster = cluster.unwrap_or(u32::MAX);

if start == end {
return cluster;
Expand Down
8 changes: 4 additions & 4 deletions src/hb/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,18 +579,18 @@ impl core::str::FromStr for Feature {
p.advance(1);
p.consume_i32().unwrap_or(-1) as u32 // negative value overflow is ok
} else {
if start_opt.is_some() && start != core::u32::MAX {
if start_opt.is_some() && start != u32::MAX {
start + 1
} else {
core::u32::MAX
u32::MAX
}
};

p.consume_byte(b']')?;

(start, end)
} else {
(0, core::u32::MAX)
(0, u32::MAX)
};

// Parse postfix.
Expand Down Expand Up @@ -657,7 +657,7 @@ mod tests_features {
test!(parse_13, "kern[3:5]=2", b"kern", 2, 3..=5);
test!(parse_14, "kern[3;5]=2", b"kern", 2, 3..=5);
test!(parse_15, "kern[:-1]", b"kern", 1, ..);
test!(parse_16, "kern[-1]", b"kern", 1, core::u32::MAX as usize..);
test!(parse_16, "kern[-1]", b"kern", 1, u32::MAX as usize..);
test!(parse_17, "kern=on", b"kern", 1, ..);
test!(parse_18, "kern=off", b"kern", 0, ..);
test!(parse_19, "kern=oN", b"kern", 1, ..);
Expand Down
13 changes: 5 additions & 8 deletions src/hb/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ impl<'a> hb_font_t<'a> {

if is_vertical {
if face.tables().vmtx.is_some() {
return face.glyph_ver_advance(glyph).unwrap_or(0) as u32;
face.glyph_ver_advance(glyph).unwrap_or(0) as u32
} else {
// TODO: Original code calls `h_extents_with_fallback`
return (face.ascender() - face.descender()) as u32;
(face.ascender() - face.descender()) as u32
}
} else if !is_vertical && face.tables().hmtx.is_some() {
face.glyph_hor_advance(glyph).unwrap_or(0) as u32
Expand All @@ -222,7 +222,7 @@ impl<'a> hb_font_t<'a> {
} else {
let advance = self.ttfp_face.ascender() - self.ttfp_face.descender();
let diff = advance as i32 - -extents.height;
return extents.y_bearing + (diff >> 1);
extents.y_bearing + (diff >> 1)
}
} else {
// TODO: Original code calls `h_extents_with_fallback`
Expand Down Expand Up @@ -253,10 +253,7 @@ impl<'a> hb_font_t<'a> {
glyph: GlyphId,
glyph_extents: &mut hb_glyph_extents_t,
) -> bool {
let pixels_per_em = match self.pixels_per_em {
Some(ppem) => ppem.0,
None => core::u16::MAX,
};
let pixels_per_em = self.pixels_per_em.map_or(u16::MAX, |ppem| ppem.0);

if let Some(img) = self.ttfp_face.glyph_raster_image(glyph, pixels_per_em) {
// HarfBuzz also supports only PNG.
Expand Down Expand Up @@ -334,7 +331,7 @@ impl<'a> hb_font_t<'a> {
glyph_extents.width = i32::from(bbox.width());
glyph_extents.height = i32::from(bbox.y_min - bbox.y_max);

return true;
true
}

pub(crate) fn glyph_name(&self, glyph: GlyphId) -> Option<&str> {
Expand Down
5 changes: 3 additions & 2 deletions src/hb/kerning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn apply_state_machine_kerning(
.class(buffer.info[buffer.idx].as_glyph())
.unwrap_or(1)
} else {
apple_layout::class::END_OF_TEXT as u8
apple_layout::class::END_OF_TEXT
};

let entry = match state_table.entry(state, class) {
Expand All @@ -191,7 +191,8 @@ fn apply_state_machine_kerning(
{
// If there's no value and we're just epsilon-transitioning to state 0, safe to break.
if entry.has_offset()
|| !(entry.new_state == apple_layout::state::START_OF_TEXT && !entry.has_advance())
|| entry.new_state != apple_layout::state::START_OF_TEXT
|| entry.has_advance()
{
buffer.unsafe_to_break_from_outbuffer(
Some(buffer.backtrack_len() - 1),
Expand Down
16 changes: 16 additions & 0 deletions src/hb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(clippy::collapsible_if)]
#![allow(clippy::collapsible_else_if)]
#![allow(clippy::comparison_chain)]
#![allow(clippy::needless_range_loop)]
#![allow(clippy::non_canonical_partial_ord_impl)]
#![allow(clippy::upper_case_acronyms)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::wildcard_in_or_patterns)]
#![allow(clippy::identity_op)]
#![allow(clippy::mut_range_bound)]
#![allow(clippy::enum_variant_names)]
#![allow(clippy::manual_range_patterns)]
#![allow(clippy::type_complexity)]
#![allow(clippy::wrong_self_convention)]
#![allow(clippy::match_like_matches_macro)]
#![allow(clippy::manual_range_contains)]

mod algs;
#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion src/hb/ot/layout/GPOS/mark_lig_pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Apply for MarkToLigatureAdjustment<'_> {
// can directly use the component index. If not, we attach the mark
// glyph to the last component of the ligature.
let lig_id = _hb_glyph_info_get_lig_id(&buffer.info[idx]);
let mark_id = _hb_glyph_info_get_lig_id(&buffer.cur(0));
let mark_id = _hb_glyph_info_get_lig_id(buffer.cur(0));
let mark_comp = u16::from(_hb_glyph_info_get_lig_comp(buffer.cur(0)));
let matches = lig_id != 0 && lig_id == mark_id && mark_comp > 0;
let comp_index = if matches {
Expand Down
2 changes: 1 addition & 1 deletion src/hb/ot/layout/GSUB/ligature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Apply for Ligature<'_> {
total_component_count,
self.glyph,
);
return Some(());
Some(())
}
}
}
2 changes: 1 addition & 1 deletion src/hb/ot/layout/GSUB/reverse_chain_single_subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ impl Apply for ReverseChainSingleSubstitution<'_> {

ctx.buffer
.unsafe_to_concat_from_outbuffer(Some(start_index), Some(end_index));
return None;
None
}
}
4 changes: 2 additions & 2 deletions src/hb/ot_layout_gpos_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ impl TryNumFrom<f32> 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 {
Expand Down
Loading

0 comments on commit 20c75ad

Please sign in to comment.