Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustfmt and clippy #585

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion font-codegen/src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) fn format(tables: proc_macro2::TokenStream) -> Result<String, syn::Er
// convert doc comment attributes into normal doc comments
let doc_comments = regex::Regex::new(r##"#\[doc = r?#?"(.*)"#?\]"##).unwrap();
let source_str = doc_comments.replace_all(&source_str, "///$1");
let newlines_before_docs = regex::Regex::new(r#"([;\}])\r?\n( *)(///|pub|impl|#)"#).unwrap();
let newlines_before_docs = regex::Regex::new(r"([;\}])\r?\n( *)(///|pub|impl|#)").unwrap();
let source_str = newlines_before_docs.replace_all(&source_str, "$1\n\n$2$3");

// add newlines after top-level items
Expand Down
2 changes: 1 addition & 1 deletion font-codegen/src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ impl Parse for InlineExpr {
let span = tokens.span();
let s = tokens.to_string();
let mut idents = Vec::new();
let find_dollar_idents = regex::Regex::new(r#"(\$) (\w+)"#).unwrap();
let find_dollar_idents = regex::Regex::new(r"(\$) (\w+)").unwrap();
for ident in find_dollar_idents.captures_iter(&s) {
let text = ident.get(2).unwrap().as_str();
let ident = syn::parse_str::<syn::Ident>(text).map_err(|_| {
Expand Down
12 changes: 2 additions & 10 deletions font-codegen/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,10 @@ pub(crate) fn generate(item: &Table) -> syn::Result<TokenStream> {
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
}
}

Expand Down Expand Up @@ -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! {
Expand Down
4 changes: 1 addition & 3 deletions read-fonts/generated/generated_gpos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3445,9 +3445,7 @@ impl<T> ExtensionPosFormat1Marker<T> {

impl<T> Clone for ExtensionPosFormat1Marker<T> {
fn clone(&self) -> Self {
Self {
offset_type: std::marker::PhantomData,
}
*self
}
}

Expand Down
4 changes: 1 addition & 3 deletions read-fonts/generated/generated_gsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,9 +1186,7 @@ impl<T> ExtensionSubstFormat1Marker<T> {

impl<T> Clone for ExtensionSubstFormat1Marker<T> {
fn clone(&self) -> Self {
Self {
offset_type: std::marker::PhantomData,
}
*self
}
}

Expand Down
10 changes: 2 additions & 8 deletions read-fonts/generated/generated_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,10 +655,7 @@ impl<T> LookupListMarker<T> {

impl<T> Clone for LookupListMarker<T> {
fn clone(&self) -> Self {
Self {
lookup_offsets_byte_len: self.lookup_offsets_byte_len,
offset_type: std::marker::PhantomData,
}
*self
}
}

Expand Down Expand Up @@ -786,10 +783,7 @@ impl<T> LookupMarker<T> {

impl<T> Clone for LookupMarker<T> {
fn clone(&self) -> Self {
Self {
subtable_offsets_byte_len: self.subtable_offsets_byte_len,
offset_type: std::marker::PhantomData,
}
*self
}
}

Expand Down
2 changes: 1 addition & 1 deletion read-fonts/src/offset_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ where
/// error variant.
pub fn get(&self, idx: usize) -> Option<Result<T, ReadError>> {
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)
}
Expand Down
2 changes: 1 addition & 1 deletion read-fonts/src/tables/postscript/fd_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 3 additions & 1 deletion read-fonts/src/tables/variations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions skrifa/src/charmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions skrifa/src/scale/scaler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions write-fonts/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion write-fonts/src/graph/splitting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _));
Expand Down
6 changes: 5 additions & 1 deletion write-fonts/src/tables/glyf/composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
18 changes: 15 additions & 3 deletions write-fonts/src/tables/glyf/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion write-fonts/src/tables/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
8 changes: 6 additions & 2 deletions write-fonts/src/tables/value_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading