From 4dcb66c29e419a3a329c03f8758412a2bdd63d6b Mon Sep 17 00:00:00 2001 From: Colin Rofls Date: Thu, 24 Aug 2023 16:11:57 -0400 Subject: [PATCH 1/2] [rustfmt] Run new 1.72.0 rustfmt --- read-fonts/src/offset_array.rs | 2 +- read-fonts/src/tables/variations.rs | 4 +++- skrifa/src/charmap.rs | 12 +++++++++--- skrifa/src/scale/scaler.rs | 4 ++-- write-fonts/src/graph.rs | 8 ++++++-- write-fonts/src/tables/glyf/composite.rs | 6 +++++- write-fonts/src/tables/glyf/simple.rs | 18 +++++++++++++++--- write-fonts/src/tables/stat.rs | 4 +++- write-fonts/src/tables/value_record.rs | 8 ++++++-- 9 files changed, 50 insertions(+), 16 deletions(-) diff --git a/read-fonts/src/offset_array.rs b/read-fonts/src/offset_array.rs index 1e41ae874..bc6b7ba78 100644 --- a/read-fonts/src/offset_array.rs +++ b/read-fonts/src/offset_array.rs @@ -128,7 +128,7 @@ where /// error variant. pub fn get(&self, idx: usize) -> Option> { let Some(offset) = self.offsets.get(idx) else { - return Some(Err(ReadError::InvalidCollectionIndex(idx as _))) + return Some(Err(ReadError::InvalidCollectionIndex(idx as _))); }; offset.get().resolve_with_args(self.data, &self.args) } diff --git a/read-fonts/src/tables/variations.rs b/read-fonts/src/tables/variations.rs index 81e7bd27c..dc1a28a3d 100644 --- a/read-fonts/src/tables/variations.rs +++ b/read-fonts/src/tables/variations.rs @@ -273,7 +273,9 @@ impl<'a> PackedPointNumbers<'a> { let mut n_seen = 0; while n_seen < n_points { - let Some((count, two_bytes)) = read_control_byte(&mut cursor) else { return n_bytes }; + let Some((count, two_bytes)) = read_control_byte(&mut cursor) else { + return n_bytes; + }; let word_size = 1 + usize::from(two_bytes); let run_size = word_size * count as usize; n_bytes += run_size + 1; // plus the control byte; diff --git a/skrifa/src/charmap.rs b/skrifa/src/charmap.rs index 64589ec40..fa5dfa5d6 100644 --- a/skrifa/src/charmap.rs +++ b/skrifa/src/charmap.rs @@ -51,7 +51,9 @@ pub struct Charmap<'a> { impl<'a> Charmap<'a> { /// Creates a new character map from the given font. pub fn new(font: &impl TableProvider<'a>) -> Self { - let Ok(cmap) = font.cmap() else { return Default::default() }; + let Ok(cmap) = font.cmap() else { + return Default::default(); + }; let selection = MappingSelection::new(&cmap); Self { codepoint_subtable: selection @@ -138,7 +140,9 @@ impl MappingIndex { /// Finds the indices of the most suitable Unicode mapping tables in the /// given font. pub fn new<'a>(font: &impl TableProvider<'a>) -> Self { - let Ok(cmap) = font.cmap() else { return Default::default() }; + let Ok(cmap) = font.cmap() else { + return Default::default(); + }; MappingSelection::new(&cmap).mapping_index } @@ -147,7 +151,9 @@ impl MappingIndex { /// /// The font should be the same as the one used to construct this object. pub fn charmap<'a>(&self, font: &impl TableProvider<'a>) -> Charmap<'a> { - let Ok(cmap) = font.cmap() else { return Default::default() }; + let Ok(cmap) = font.cmap() else { + return Default::default(); + }; let records = cmap.encoding_records(); let data = cmap.offset_data(); Charmap { diff --git a/skrifa/src/scale/scaler.rs b/skrifa/src/scale/scaler.rs index e0f6bef5d..cda747671 100644 --- a/skrifa/src/scale/scaler.rs +++ b/skrifa/src/scale/scaler.rs @@ -162,10 +162,10 @@ impl<'a> ScalerBuilder<'a> { return; // nop } let Ok(fvar) = font.fvar() else { - return; // nop + return; // nop }; let Ok(axes) = fvar.axes() else { - return; // nop + return; // nop }; let avar_mappings = font.avar().ok().map(|avar| avar.axis_segment_maps()); let axis_count = fvar.axis_count() as usize; diff --git a/write-fonts/src/graph.rs b/write-fonts/src/graph.rs index 57c88b570..46a217524 100644 --- a/write-fonts/src/graph.rs +++ b/write-fonts/src/graph.rs @@ -755,7 +755,9 @@ impl Graph { // now everything but the links to the roots roots has been remapped; // remap those, if needed for root in roots.iter() { - let Some(new_id) = id_map.get(root) else { continue }; + let Some(new_id) = id_map.get(root) else { + continue; + }; self.parents_invalid = true; self.positions_invalid = true; for (parent_id, len) in &self.nodes[new_id].parents { @@ -842,7 +844,9 @@ impl Graph { } fn try_promoting_subtables(&mut self) { - let Some((can_promote, parent_id)) = self.get_promotable_subtables() else { return }; + let Some((can_promote, parent_id)) = self.get_promotable_subtables() else { + return; + }; let to_promote = self.select_promotions_hb(&can_promote, parent_id); log::info!( "promoting {} of {} eligible subtables", diff --git a/write-fonts/src/tables/glyf/composite.rs b/write-fonts/src/tables/glyf/composite.rs index 2f129b9c4..0ca6a3ba7 100644 --- a/write-fonts/src/tables/glyf/composite.rs +++ b/write-fonts/src/tables/glyf/composite.rs @@ -310,7 +310,11 @@ mod tests { let font = FontRef::new(font_test_data::VAZIRMATN_VAR).unwrap(); let loca = font.loca(None).unwrap(); let glyf = font.glyf().unwrap(); - let read_glyf::Glyph::Composite(orig) = loca.get_glyf(GlyphId::new(2), &glyf).unwrap().unwrap() else { panic!("not a composite glyph") }; + let read_glyf::Glyph::Composite(orig) = + loca.get_glyf(GlyphId::new(2), &glyf).unwrap().unwrap() + else { + panic!("not a composite glyph") + }; let bbox = Bbox { x_min: orig.x_min(), diff --git a/write-fonts/src/tables/glyf/simple.rs b/write-fonts/src/tables/glyf/simple.rs index 907d11c12..26114d8f7 100644 --- a/write-fonts/src/tables/glyf/simple.rs +++ b/write-fonts/src/tables/glyf/simple.rs @@ -668,7 +668,11 @@ mod tests { let font = FontRef::new(font_test_data::SIMPLE_GLYF).unwrap(); let loca = font.loca(None).unwrap(); let glyf = font.glyf().unwrap(); - let read_glyf::Glyph::Simple(orig) = loca.get_glyf(GlyphId::new(0), &glyf).unwrap().unwrap() else { panic!("not a simple glyph") }; + let read_glyf::Glyph::Simple(orig) = + loca.get_glyf(GlyphId::new(0), &glyf).unwrap().unwrap() + else { + panic!("not a simple glyph") + }; let orig_bytes = orig.offset_data(); let ours = SimpleGlyph::from_table_ref(&orig); @@ -688,7 +692,11 @@ mod tests { let font = FontRef::new(font_test_data::SIMPLE_GLYF).unwrap(); let loca = font.loca(None).unwrap(); let glyf = font.glyf().unwrap(); - let read_glyf::Glyph::Simple(orig) = loca.get_glyf(GlyphId::new(2), &glyf).unwrap().unwrap() else { panic!("not a simple glyph") }; + let read_glyf::Glyph::Simple(orig) = + loca.get_glyf(GlyphId::new(2), &glyf).unwrap().unwrap() + else { + panic!("not a simple glyph") + }; let orig_bytes = orig.offset_data(); let bezpath = simple_glyph_to_bezpath(&orig); @@ -710,7 +718,11 @@ mod tests { let font = FontRef::new(font_test_data::VAZIRMATN_VAR).unwrap(); let loca = font.loca(None).unwrap(); let glyf = font.glyf().unwrap(); - let read_glyf::Glyph::Simple(orig) = loca.get_glyf(GlyphId::new(1), &glyf).unwrap().unwrap() else { panic!("not a simple glyph") }; + let read_glyf::Glyph::Simple(orig) = + loca.get_glyf(GlyphId::new(1), &glyf).unwrap().unwrap() + else { + panic!("not a simple glyph") + }; let orig_bytes = orig.offset_data(); let bezpath = simple_glyph_to_bezpath(&orig); diff --git a/write-fonts/src/tables/stat.rs b/write-fonts/src/tables/stat.rs index fa50b2cd0..4a9db2617 100644 --- a/write-fonts/src/tables/stat.rs +++ b/write-fonts/src/tables/stat.rs @@ -67,7 +67,9 @@ mod tests { let axis_values = read.offset_to_axis_values().unwrap(); assert_eq!(axis_values.axis_value_offsets().len(), 2); let value2 = axis_values.axis_values().get(1).unwrap(); - let read_stat::AxisValue::Format1(value2) = value2 else { panic!("wrong format"); }; + let read_stat::AxisValue::Format1(value2) = value2 else { + panic!("wrong format"); + }; assert_eq!(value2.value_name_id(), NameId::new(261)); } } diff --git a/write-fonts/src/tables/value_record.rs b/write-fonts/src/tables/value_record.rs index 9b6f7f588..8dc83f8c8 100644 --- a/write-fonts/src/tables/value_record.rs +++ b/write-fonts/src/tables/value_record.rs @@ -280,11 +280,15 @@ mod tests { let bytes = crate::dump_table(&a_table).unwrap(); let read_back = PairPosFormat2::read(bytes.as_slice().into()).unwrap(); - let DeviceOrVariationIndex::VariationIndex(dev2) = read_back.class1_records[0].class2_records[0] + let DeviceOrVariationIndex::VariationIndex(dev2) = read_back.class1_records[0] + .class2_records[0] .value_record2 .x_advance_device .as_ref() - .unwrap() else { panic!("not a variation index") }; + .unwrap() + else { + panic!("not a variation index") + }; assert_eq!(dev2.delta_set_outer_index, 0xaa); } } From ee5da54f5a43a39edad365964080b612008d4f51 Mon Sep 17 00:00:00 2001 From: Colin Rofls Date: Thu, 24 Aug 2023 16:18:52 -0400 Subject: [PATCH 2/2] [clippy] Fixup for 1.72.0 One funny one here; clippy didn't like our Clone impls in some generated code, so I had to fixup the codegen tool to emit something clippy *did* like. This ended up being no problem though. --- font-codegen/src/formatting.rs | 2 +- font-codegen/src/parsing.rs | 2 +- font-codegen/src/table.rs | 12 ++---------- read-fonts/generated/generated_gpos.rs | 4 +--- read-fonts/generated/generated_gsub.rs | 4 +--- read-fonts/generated/generated_layout.rs | 10 ++-------- read-fonts/src/tables/postscript/fd_select.rs | 2 +- write-fonts/src/graph/splitting.rs | 2 +- 8 files changed, 10 insertions(+), 28 deletions(-) diff --git a/font-codegen/src/formatting.rs b/font-codegen/src/formatting.rs index 0975cbff1..6274a6758 100644 --- a/font-codegen/src/formatting.rs +++ b/font-codegen/src/formatting.rs @@ -11,7 +11,7 @@ pub(crate) fn format(tables: proc_macro2::TokenStream) -> Result(text).map_err(|_| { diff --git a/font-codegen/src/table.rs b/font-codegen/src/table.rs index 1aaaa30d3..5371accd3 100644 --- a/font-codegen/src/table.rs +++ b/font-codegen/src/table.rs @@ -22,16 +22,10 @@ pub(crate) fn generate(item: &Table) -> syn::Result { let shape_fields = item.iter_shape_fields(); let derive_clone_copy = generic.is_none().then(|| quote!(Clone, Copy)); let impl_clone_copy = generic.is_some().then(|| { - let clone_fields = item - .iter_shape_field_names() - .map(|name| quote!(#name: self.#name)); quote! { impl<#generic> Clone for #marker_name<#generic> { fn clone(&self) -> Self { - Self { - #( #clone_fields, )* - offset_type: std::marker::PhantomData, - } + *self } } @@ -327,9 +321,7 @@ fn generate_to_owned_impl(item: &Table, parse_module: &syn::Path) -> syn::Result let parse_generic = comp_generic .is_some() .then(|| syn::Ident::new("U", Span::call_site())); - let impl_generics = comp_generic - .into_iter() - .chain(parse_generic.as_ref().into_iter()); + let impl_generics = comp_generic.into_iter().chain(parse_generic.as_ref()); let impl_generics2 = impl_generics.clone(); let where_clause = comp_generic.map(|t| { quote! { diff --git a/read-fonts/generated/generated_gpos.rs b/read-fonts/generated/generated_gpos.rs index f48db6c36..462231cff 100644 --- a/read-fonts/generated/generated_gpos.rs +++ b/read-fonts/generated/generated_gpos.rs @@ -3445,9 +3445,7 @@ impl ExtensionPosFormat1Marker { impl Clone for ExtensionPosFormat1Marker { fn clone(&self) -> Self { - Self { - offset_type: std::marker::PhantomData, - } + *self } } diff --git a/read-fonts/generated/generated_gsub.rs b/read-fonts/generated/generated_gsub.rs index ce2e3de49..b8d698fe7 100644 --- a/read-fonts/generated/generated_gsub.rs +++ b/read-fonts/generated/generated_gsub.rs @@ -1186,9 +1186,7 @@ impl ExtensionSubstFormat1Marker { impl Clone for ExtensionSubstFormat1Marker { fn clone(&self) -> Self { - Self { - offset_type: std::marker::PhantomData, - } + *self } } diff --git a/read-fonts/generated/generated_layout.rs b/read-fonts/generated/generated_layout.rs index 72c5ddbd8..65ca47af1 100644 --- a/read-fonts/generated/generated_layout.rs +++ b/read-fonts/generated/generated_layout.rs @@ -655,10 +655,7 @@ impl LookupListMarker { impl Clone for LookupListMarker { fn clone(&self) -> Self { - Self { - lookup_offsets_byte_len: self.lookup_offsets_byte_len, - offset_type: std::marker::PhantomData, - } + *self } } @@ -786,10 +783,7 @@ impl LookupMarker { impl Clone for LookupMarker { fn clone(&self) -> Self { - Self { - subtable_offsets_byte_len: self.subtable_offsets_byte_len, - offset_type: std::marker::PhantomData, - } + *self } } diff --git a/read-fonts/src/tables/postscript/fd_select.rs b/read-fonts/src/tables/postscript/fd_select.rs index f22d87fbf..c1ac5cb09 100644 --- a/read-fonts/src/tables/postscript/fd_select.rs +++ b/read-fonts/src/tables/postscript/fd_select.rs @@ -80,7 +80,7 @@ mod tests { fds[gid as usize] = *font_index; } } - buf = buf.extend(fds.into_iter()); + buf = buf.extend(fds); buf }; let format3 = { diff --git a/write-fonts/src/graph/splitting.rs b/write-fonts/src/graph/splitting.rs index 291da560e..0e3a83ed4 100644 --- a/write-fonts/src/graph/splitting.rs +++ b/write-fonts/src/graph/splitting.rs @@ -361,7 +361,7 @@ mod tests { const N_GLYPHS: u16 = 1500; // manually determined to cause overflow let mut pairs = Vec::new(); - for (advance, g1) in [0u16..N_GLYPHS].into_iter().flatten().enumerate() { + for (advance, g1) in (0u16..N_GLYPHS).enumerate() { pairs.push(KernPair(GlyphId::new(g1), GlyphId::new(5), advance as _)); pairs.push(KernPair(GlyphId::new(g1), GlyphId::new(6), advance as _)); pairs.push(KernPair(GlyphId::new(g1), GlyphId::new(7), advance as _));