Clippy fixes (#581)

This commit is contained in:
Marek Barvíř 2023-04-16 11:10:35 +02:00 committed by GitHub
parent 261b96da68
commit ee32e7ad1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 27 additions and 22 deletions

View File

@ -71,7 +71,7 @@ cast_from_value! {
v: i64 => Self(Value::Int(v.abs())), v: i64 => Self(Value::Int(v.abs())),
v: f64 => Self(Value::Float(v.abs())), v: f64 => Self(Value::Float(v.abs())),
v: Length => Self(Value::Length(v.try_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: Angle => Self(Value::Angle(v.abs())),
v: Ratio => Self(Value::Ratio(v.abs())), v: Ratio => Self(Value::Ratio(v.abs())),
v: Fr => Self(Value::Fraction(v.abs())), v: Fr => Self(Value::Fraction(v.abs())),

View File

@ -238,7 +238,7 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
Self { Self {
vt, vt,
scratch, scratch,
doc: top.then(|| DocBuilder::default()), doc: top.then(DocBuilder::default),
flow: FlowBuilder::default(), flow: FlowBuilder::default(),
par: ParBuilder::default(), par: ParBuilder::default(),
list: ListBuilder::default(), list: ListBuilder::default(),
@ -295,7 +295,7 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
.to::<PagebreakElem>() .to::<PagebreakElem>()
.map_or(false, |pagebreak| !pagebreak.weak(styles)); .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 let Some(doc) = &mut self.doc {
if doc.accept(content, styles) { if doc.accept(content, styles) {

View File

@ -135,6 +135,7 @@ impl ParElem {
expand: bool, expand: bool,
) -> SourceResult<Fragment> { ) -> SourceResult<Fragment> {
#[comemo::memoize] #[comemo::memoize]
#[allow(clippy::too_many_arguments)]
fn cached( fn cached(
par: &ParElem, par: &ParElem,
world: Tracked<dyn World>, world: Tracked<dyn World>,
@ -760,7 +761,7 @@ fn shared_get<T: PartialEq>(
.iter() .iter()
.filter_map(|child| child.to_styled()) .filter_map(|child| child.to_styled())
.all(|(_, local)| getter(styles.chain(local)) == value) .all(|(_, local)| getter(styles.chain(local)) == value)
.then(|| value) .then_some(value)
} }
/// Find suitable linebreaks. /// Find suitable linebreaks.

View File

@ -1,3 +1,4 @@
#![allow(clippy::wildcard_in_or_patterns)]
//! Typst's standard library. //! Typst's standard library.
pub mod compute; pub mod compute;

View File

@ -9,12 +9,12 @@ pub struct MathRow(Vec<MathFragment>);
impl MathRow { impl MathRow {
pub fn new(fragments: Vec<MathFragment>) -> Self { pub fn new(fragments: Vec<MathFragment>) -> Self {
let mut iter = fragments.into_iter().peekable(); let iter = fragments.into_iter().peekable();
let mut last: Option<usize> = None; let mut last: Option<usize> = None;
let mut space: Option<MathFragment> = None; let mut space: Option<MathFragment> = None;
let mut resolved: Vec<MathFragment> = vec![]; let mut resolved: Vec<MathFragment> = vec![];
while let Some(mut fragment) = iter.next() { for mut fragment in iter {
match fragment { match fragment {
// Keep space only if supported by spaced fragments. // Keep space only if supported by spaced fragments.
MathFragment::Space(_) => { 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; let mut i = 0;
while let Some(fragment) = fragments.next() { for fragment in fragments {
if matches!(fragment, MathFragment::Align) { if matches!(fragment, MathFragment::Align) {
if let Some(&point) = points.get(i) { if let Some(&point) = points.get(i) {
x = point; x = point;

View File

@ -489,7 +489,7 @@ fn create(
&mut *citation_style, &mut *citation_style,
&[Citation { &[Citation {
entry, entry,
supplement: supplement.is_some().then(|| SUPPLEMENT), supplement: supplement.is_some().then_some(SUPPLEMENT),
}], }],
) )
.display; .display;

View File

@ -149,7 +149,7 @@ impl NumberingPattern {
/// Apply the pattern to the given number. /// Apply the pattern to the given number.
pub fn apply(&self, numbers: &[usize]) -> EcoString { pub fn apply(&self, numbers: &[usize]) -> EcoString {
let mut fmt = EcoString::new(); let mut fmt = EcoString::new();
let mut numbers = numbers.into_iter(); let mut numbers = numbers.iter();
for (i, ((prefix, kind, case), &n)) in for (i, ((prefix, kind, case), &n)) in
self.pieces.iter().zip(&mut numbers).enumerate() self.pieces.iter().zip(&mut numbers).enumerate()

View File

@ -315,11 +315,13 @@ pub(super) fn decorate(
// Only do the costly segments intersection test if the line // Only do the costly segments intersection test if the line
// intersects the bounding box. // 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_min = -text.font.to_em(bbox.y_max).at(text.size);
let y_max = -text.font.to_em(bbox.y_min).at(text.size); let y_max = -text.font.to_em(bbox.y_min).at(text.size);
offset >= y_min && offset <= y_max offset >= y_min && offset <= y_max
}) { });
if intersect {
// Find all intersections of segments with the line. // Find all intersections of segments with the line.
intersections.extend( intersections.extend(
path.segments() path.segments()

View File

@ -285,7 +285,7 @@ fn to_syn(RgbaColor { r, g, b, a }: RgbaColor) -> synt::Color {
/// The syntect syntax definitions. /// The syntect syntax definitions.
static SYNTAXES: Lazy<syntect::parsing::SyntaxSet> = static SYNTAXES: Lazy<syntect::parsing::SyntaxSet> =
Lazy::new(|| syntect::parsing::SyntaxSet::load_defaults_nonewlines()); Lazy::new(syntect::parsing::SyntaxSet::load_defaults_nonewlines);
/// The default theme used for syntax highlighting. /// The default theme used for syntax highlighting.
pub static THEME: Lazy<synt::Theme> = Lazy::new(|| synt::Theme { pub static THEME: Lazy<synt::Theme> = Lazy::new(|| synt::Theme {

View File

@ -379,7 +379,7 @@ impl<'a> ShapedText<'a> {
// RTL needs offset one because the left side of the range should be // RTL needs offset one because the left side of the range should be
// exclusive and the right side inclusive, contrary to the normal // exclusive and the right side inclusive, contrary to the normal
// behaviour of ranges. // 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))
} }
} }

View File

@ -477,6 +477,7 @@ impl Layout for CircleElem {
} }
/// Layout a shape. /// Layout a shape.
#[allow(clippy::too_many_arguments)]
fn layout( fn layout(
vt: &mut Vt, vt: &mut Vt,
styles: StyleChain, styles: StyleChain,

View File

@ -69,7 +69,7 @@ impl Args {
let vec = self.items.to_vec(); let vec = self.items.to_vec();
let (left, right) = vec.split_at(n); let (left, right) = vec.split_at(n);
self.items = right.into(); self.items = right.into();
return Ok(left.into()); Ok(left.into())
} }
/// Consume and cast the first positional argument. /// Consume and cast the first positional argument.

View File

@ -1203,7 +1203,7 @@ impl ast::Pattern {
return None; return None;
}; };
if let Some(ident) = ident { if let Some(ident) = ident {
vm.define(ident.clone(), sink.clone()); vm.define(ident.clone(), sink);
} }
i += sink_size as i64; i += sink_size as i64;
Some(()) 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"); bail!(self.span(), "too many elements to destructure");
} }
} }

View File

@ -386,7 +386,7 @@ impl Content {
for attr in &self.attrs { for attr in &self.attrs {
match attr { match attr {
Attr::Child(child) => child.query_into(introspector, selector, results), 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),
_ => {} _ => {}
} }
} }

View File

@ -628,13 +628,13 @@ impl<'a> StyleChain<'a> {
) -> T::Output { ) -> T::Output {
fn next<T: Fold>( fn next<T: Fold>(
mut values: impl Iterator<Item = T>, mut values: impl Iterator<Item = T>,
styles: StyleChain, _styles: StyleChain,
default: &impl Fn() -> T::Output, default: &impl Fn() -> T::Output,
) -> T::Output { ) -> T::Output {
values values
.next() .next()
.map(|value| value.fold(next(values, styles, default))) .map(|value| value.fold(next(values, _styles, default)))
.unwrap_or_else(|| default()) .unwrap_or_else(default)
} }
next(self.properties::<T>(func, name, inherent), self, &default) next(self.properties::<T>(func, name, inherent), self, &default)
} }
@ -663,7 +663,7 @@ impl<'a> StyleChain<'a> {
values values
.next() .next()
.map(|value| value.resolve(styles).fold(next(values, styles, default))) .map(|value| value.resolve(styles).fold(next(values, styles, default)))
.unwrap_or_else(|| default()) .unwrap_or_else(default)
} }
next(self.properties::<T>(func, name, inherent), self, &default) next(self.properties::<T>(func, name, inherent), self, &default)
} }