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: 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())),

View File

@ -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::<PagebreakElem>()
.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) {

View File

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

View File

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

View File

@ -9,12 +9,12 @@ pub struct MathRow(Vec<MathFragment>);
impl MathRow {
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 space: Option<MathFragment> = None;
let mut resolved: Vec<MathFragment> = 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;

View File

@ -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;

View File

@ -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()

View File

@ -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()

View File

@ -285,7 +285,7 @@ fn to_syn(RgbaColor { r, g, b, a }: RgbaColor) -> synt::Color {
/// The syntect syntax definitions.
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.
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
// 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))
}
}

View File

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

View File

@ -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.

View File

@ -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");
}
}

View File

@ -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),
_ => {}
}
}

View File

@ -628,13 +628,13 @@ impl<'a> StyleChain<'a> {
) -> T::Output {
fn next<T: Fold>(
mut values: impl Iterator<Item = T>,
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::<T>(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::<T>(func, name, inherent), self, &default)
}