diff --git a/library/src/compute/calc.rs b/library/src/compute/calc.rs index d5166449..35e7ddb8 100644 --- a/library/src/compute/calc.rs +++ b/library/src/compute/calc.rs @@ -71,7 +71,7 @@ cast_from_value! { v: i64 => Self(Value::Int(v.abs())), v: f64 => Self(Value::Float(v.abs())), v: Length => Self(Value::Length(v.try_abs() - .ok_or_else(|| "cannot take absolute value of this length")?)), + .ok_or("cannot take absolute value of this length")?)), v: Angle => Self(Value::Angle(v.abs())), v: Ratio => Self(Value::Ratio(v.abs())), v: Fr => Self(Value::Fraction(v.abs())), diff --git a/library/src/layout/mod.rs b/library/src/layout/mod.rs index 0fed1a34..e84e35fc 100644 --- a/library/src/layout/mod.rs +++ b/library/src/layout/mod.rs @@ -238,7 +238,7 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> { Self { vt, scratch, - doc: top.then(|| DocBuilder::default()), + doc: top.then(DocBuilder::default), flow: FlowBuilder::default(), par: ParBuilder::default(), list: ListBuilder::default(), @@ -295,7 +295,7 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> { .to::() .map_or(false, |pagebreak| !pagebreak.weak(styles)); - self.interrupt_page(keep.then(|| styles))?; + self.interrupt_page(keep.then_some(styles))?; if let Some(doc) = &mut self.doc { if doc.accept(content, styles) { diff --git a/library/src/layout/par.rs b/library/src/layout/par.rs index 011502e6..5d33de40 100644 --- a/library/src/layout/par.rs +++ b/library/src/layout/par.rs @@ -135,6 +135,7 @@ impl ParElem { expand: bool, ) -> SourceResult { #[comemo::memoize] + #[allow(clippy::too_many_arguments)] fn cached( par: &ParElem, world: Tracked, @@ -760,7 +761,7 @@ fn shared_get( .iter() .filter_map(|child| child.to_styled()) .all(|(_, local)| getter(styles.chain(local)) == value) - .then(|| value) + .then_some(value) } /// Find suitable linebreaks. diff --git a/library/src/lib.rs b/library/src/lib.rs index 9b4e9644..caf76ded 100644 --- a/library/src/lib.rs +++ b/library/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::wildcard_in_or_patterns)] //! Typst's standard library. pub mod compute; diff --git a/library/src/math/row.rs b/library/src/math/row.rs index ce9bc94a..0b0578aa 100644 --- a/library/src/math/row.rs +++ b/library/src/math/row.rs @@ -9,12 +9,12 @@ pub struct MathRow(Vec); impl MathRow { pub fn new(fragments: Vec) -> Self { - let mut iter = fragments.into_iter().peekable(); + let iter = fragments.into_iter().peekable(); let mut last: Option = None; let mut space: Option = None; let mut resolved: Vec = vec![]; - while let Some(mut fragment) = iter.next() { + for mut fragment in iter { match fragment { // Keep space only if supported by spaced fragments. MathFragment::Space(_) => { @@ -180,9 +180,9 @@ impl MathRow { } } - let mut fragments = self.0.into_iter().peekable(); + let fragments = self.0.into_iter().peekable(); let mut i = 0; - while let Some(fragment) = fragments.next() { + for fragment in fragments { if matches!(fragment, MathFragment::Align) { if let Some(&point) = points.get(i) { x = point; diff --git a/library/src/meta/bibliography.rs b/library/src/meta/bibliography.rs index 8fa2ee34..2f9a099e 100644 --- a/library/src/meta/bibliography.rs +++ b/library/src/meta/bibliography.rs @@ -489,7 +489,7 @@ fn create( &mut *citation_style, &[Citation { entry, - supplement: supplement.is_some().then(|| SUPPLEMENT), + supplement: supplement.is_some().then_some(SUPPLEMENT), }], ) .display; diff --git a/library/src/meta/numbering.rs b/library/src/meta/numbering.rs index f0a1c34e..b5416f68 100644 --- a/library/src/meta/numbering.rs +++ b/library/src/meta/numbering.rs @@ -149,7 +149,7 @@ impl NumberingPattern { /// Apply the pattern to the given number. pub fn apply(&self, numbers: &[usize]) -> EcoString { let mut fmt = EcoString::new(); - let mut numbers = numbers.into_iter(); + let mut numbers = numbers.iter(); for (i, ((prefix, kind, case), &n)) in self.pieces.iter().zip(&mut numbers).enumerate() diff --git a/library/src/text/deco.rs b/library/src/text/deco.rs index ab89e6b5..7b90b22f 100644 --- a/library/src/text/deco.rs +++ b/library/src/text/deco.rs @@ -315,11 +315,13 @@ pub(super) fn decorate( // Only do the costly segments intersection test if the line // intersects the bounding box. - if bbox.map_or(false, |bbox| { + let intersect = bbox.map_or(false, |bbox| { let y_min = -text.font.to_em(bbox.y_max).at(text.size); let y_max = -text.font.to_em(bbox.y_min).at(text.size); offset >= y_min && offset <= y_max - }) { + }); + + if intersect { // Find all intersections of segments with the line. intersections.extend( path.segments() diff --git a/library/src/text/raw.rs b/library/src/text/raw.rs index c6fba253..6d90bc5b 100644 --- a/library/src/text/raw.rs +++ b/library/src/text/raw.rs @@ -285,7 +285,7 @@ fn to_syn(RgbaColor { r, g, b, a }: RgbaColor) -> synt::Color { /// The syntect syntax definitions. static SYNTAXES: Lazy = - Lazy::new(|| syntect::parsing::SyntaxSet::load_defaults_nonewlines()); + Lazy::new(syntect::parsing::SyntaxSet::load_defaults_nonewlines); /// The default theme used for syntax highlighting. pub static THEME: Lazy = Lazy::new(|| synt::Theme { diff --git a/library/src/text/shaping.rs b/library/src/text/shaping.rs index 0e5e0a73..50c4bcbd 100644 --- a/library/src/text/shaping.rs +++ b/library/src/text/shaping.rs @@ -379,7 +379,7 @@ impl<'a> ShapedText<'a> { // RTL needs offset one because the left side of the range should be // exclusive and the right side inclusive, contrary to the normal // behaviour of ranges. - self.glyphs[idx].safe_to_break.then(|| idx + (!ltr) as usize) + self.glyphs[idx].safe_to_break.then_some(idx + usize::from(!ltr)) } } diff --git a/library/src/visualize/shape.rs b/library/src/visualize/shape.rs index e0214f03..48c4d7a3 100644 --- a/library/src/visualize/shape.rs +++ b/library/src/visualize/shape.rs @@ -477,6 +477,7 @@ impl Layout for CircleElem { } /// Layout a shape. +#[allow(clippy::too_many_arguments)] fn layout( vt: &mut Vt, styles: StyleChain, diff --git a/src/eval/args.rs b/src/eval/args.rs index 66ca4a85..aadd7d54 100644 --- a/src/eval/args.rs +++ b/src/eval/args.rs @@ -69,7 +69,7 @@ impl Args { let vec = self.items.to_vec(); let (left, right) = vec.split_at(n); self.items = right.into(); - return Ok(left.into()); + Ok(left.into()) } /// Consume and cast the first positional argument. diff --git a/src/eval/mod.rs b/src/eval/mod.rs index 1b3c6ea3..68d8148f 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -1203,7 +1203,7 @@ impl ast::Pattern { return None; }; if let Some(ident) = ident { - vm.define(ident.clone(), sink.clone()); + vm.define(ident.clone(), sink); } i += sink_size as i64; Some(()) @@ -1217,7 +1217,7 @@ impl ast::Pattern { } } } - if i < value.len() as i64 { + if i < value.len() { bail!(self.span(), "too many elements to destructure"); } } diff --git a/src/model/content.rs b/src/model/content.rs index fa189b11..3f02369f 100644 --- a/src/model/content.rs +++ b/src/model/content.rs @@ -386,7 +386,7 @@ impl Content { for attr in &self.attrs { match attr { Attr::Child(child) => child.query_into(introspector, selector, results), - Attr::Value(value) => walk_value(introspector, &value, selector, results), + Attr::Value(value) => walk_value(introspector, value, selector, results), _ => {} } } diff --git a/src/model/styles.rs b/src/model/styles.rs index 7fda52cf..8b7a829f 100644 --- a/src/model/styles.rs +++ b/src/model/styles.rs @@ -628,13 +628,13 @@ impl<'a> StyleChain<'a> { ) -> T::Output { fn next( mut values: impl Iterator, - styles: StyleChain, + _styles: StyleChain, default: &impl Fn() -> T::Output, ) -> T::Output { values .next() - .map(|value| value.fold(next(values, styles, default))) - .unwrap_or_else(|| default()) + .map(|value| value.fold(next(values, _styles, default))) + .unwrap_or_else(default) } next(self.properties::(func, name, inherent), self, &default) } @@ -663,7 +663,7 @@ impl<'a> StyleChain<'a> { values .next() .map(|value| value.resolve(styles).fold(next(values, styles, default))) - .unwrap_or_else(|| default()) + .unwrap_or_else(default) } next(self.properties::(func, name, inherent), self, &default) }