Skip to content

Commit

Permalink
[clippy] Push the rock back up the hill (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmyr authored Feb 8, 2024
1 parent 9521536 commit 48c167c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 7 deletions.
3 changes: 3 additions & 0 deletions font-codegen/src/flags_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,17 @@ pub(crate) fn generate_raw_enum(raw: &RawEnum) -> TokenStream {
quote!(#value => Self::#name,)
});

let docstring = " If font data is malformed we will map unknown values to this variant";
quote! {
#( #docs )*
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(#typ)]
#[allow(clippy::manual_non_exhaustive)]
pub enum #name {
#( #variants )*
#[doc(hidden)]
#[doc = #docstring]
Unknown,
}

Expand Down
2 changes: 2 additions & 0 deletions read-fonts/generated/generated_cmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ impl<'a> SomeRecord<'a> for EncodingRecord {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u16)]
#[allow(clippy::manual_non_exhaustive)]
pub enum PlatformId {
#[default]
Unicode = 0,
Expand All @@ -180,6 +181,7 @@ pub enum PlatformId {
Windows = 3,
Custom = 4,
#[doc(hidden)]
/// If font data is malformed we will map unknown values to this variant
Unknown,
}

Expand Down
4 changes: 4 additions & 0 deletions read-fonts/generated/generated_colr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1489,12 +1489,14 @@ impl<'a> std::fmt::Debug for VarColorLine<'a> {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u8)]
#[allow(clippy::manual_non_exhaustive)]
pub enum Extend {
#[default]
Pad = 0,
Repeat = 1,
Reflect = 2,
#[doc(hidden)]
/// If font data is malformed we will map unknown values to this variant
Unknown,
}

Expand Down Expand Up @@ -5603,6 +5605,7 @@ impl<'a> std::fmt::Debug for PaintComposite<'a> {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u8)]
#[allow(clippy::manual_non_exhaustive)]
pub enum CompositeMode {
Clear = 0,
Src = 1,
Expand Down Expand Up @@ -5634,6 +5637,7 @@ pub enum CompositeMode {
HslColor = 26,
HslLuminosity = 27,
#[doc(hidden)]
/// If font data is malformed we will map unknown values to this variant
Unknown,
}

Expand Down
2 changes: 2 additions & 0 deletions read-fonts/generated/generated_gdef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,15 @@ impl<'a> std::fmt::Debug for Gdef<'a> {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u16)]
#[allow(clippy::manual_non_exhaustive)]
pub enum GlyphClassDef {
#[default]
Base = 1,
Ligature = 2,
Mark = 3,
Component = 4,
#[doc(hidden)]
/// If font data is malformed we will map unknown values to this variant
Unknown,
}

Expand Down
2 changes: 2 additions & 0 deletions read-fonts/generated/generated_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3612,6 +3612,7 @@ impl<'a> SomeTable<'a> for ChainedSequenceContext<'a> {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u16)]
#[allow(clippy::manual_non_exhaustive)]
pub enum DeltaFormat {
/// Signed 2-bit value, 8 values per uint16
#[default]
Expand All @@ -3623,6 +3624,7 @@ pub enum DeltaFormat {
/// VariationIndex table, contains a delta-set index pair.
VariationIndex = 0x8000,
#[doc(hidden)]
/// If font data is malformed we will map unknown values to this variant
Unknown,
}

Expand Down
4 changes: 4 additions & 0 deletions read-fonts/generated/generated_test_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ use crate::codegen_prelude::*;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u16)]
#[allow(clippy::manual_non_exhaustive)]
pub enum MyEnum1 {
/// doc me baby
/// docington bear
#[default]
ItsAZero = 0,
ItsAOne = 1,
#[doc(hidden)]
/// If font data is malformed we will map unknown values to this variant
Unknown,
}

Expand Down Expand Up @@ -52,12 +54,14 @@ impl<'a> From<MyEnum1> for FieldType<'a> {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(u16)]
#[allow(clippy::manual_non_exhaustive)]
pub enum MyEnum2 {
ItsATwo = 2,
/// A very important three
#[default]
ItsAThree = 3,
#[doc(hidden)]
/// If font data is malformed we will map unknown values to this variant
Unknown,
}

Expand Down
14 changes: 7 additions & 7 deletions read-fonts/src/tables/cmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,13 @@ impl<'a> Cmap14<'a> {
let selector_records = self.var_selector();
// Variation selector records are sorted in order of var_selector. Binary search to find
// the appropriate record.
let selector_record = match selector_records.binary_search_by(|rec| {
let rec_selector: u32 = rec.var_selector().into();
rec_selector.cmp(&selector)
}) {
Ok(idx) => selector_records.get(idx)?,
_ => return None,
};
let selector_record = selector_records
.binary_search_by(|rec| {
let rec_selector: u32 = rec.var_selector().into();
rec_selector.cmp(&selector)
})
.ok()
.and_then(|idx| selector_records.get(idx))?;
// If a default UVS table is present in this selector record, binary search on the ranges
// (start_unicode_value, start_unicode_value + additional_count) to find the requested codepoint.
// If found, ignore the selector and return a value indicating that the default cmap mapping
Expand Down

0 comments on commit 48c167c

Please sign in to comment.