Fix cargo clippy warnings (mostly about .repeat.take and .next_back) (#6038)

This commit is contained in:
evie 2025-03-11 03:00:53 -07:00 committed by GitHub
parent bd531e08dc
commit 3650859ae8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 12 additions and 11 deletions

View File

@ -26,7 +26,7 @@ pub fn analyze_expr(
ast::Expr::Str(v) => Value::Str(v.get().into()), ast::Expr::Str(v) => Value::Str(v.get().into()),
_ => { _ => {
if node.kind() == SyntaxKind::Contextual { if node.kind() == SyntaxKind::Contextual {
if let Some(child) = node.children().last() { if let Some(child) = node.children().next_back() {
return analyze_expr(world, &child); return analyze_expr(world, &child);
} }
} }

View File

@ -115,7 +115,7 @@ impl<'a, 'b> Composer<'a, 'b, '_, '_> {
let column_height = regions.size.y; let column_height = regions.size.y;
let backlog: Vec<_> = std::iter::once(&column_height) let backlog: Vec<_> = std::iter::once(&column_height)
.chain(regions.backlog) .chain(regions.backlog)
.flat_map(|&h| std::iter::repeat(h).take(self.config.columns.count)) .flat_map(|&h| std::iter::repeat_n(h, self.config.columns.count))
.skip(1) .skip(1)
.collect(); .collect();

View File

@ -1469,7 +1469,7 @@ impl<'a> GridLayouter<'a> {
// last height is the one for the current region. // last height is the one for the current region.
rowspan rowspan
.heights .heights
.extend(std::iter::repeat(Abs::zero()).take(amount_missing_heights)); .extend(std::iter::repeat_n(Abs::zero(), amount_missing_heights));
// Ensure that, in this region, the rowspan will span at least // Ensure that, in this region, the rowspan will span at least
// this row. // this row.

View File

@ -302,6 +302,6 @@ fn assemble(
fn parts(assembly: GlyphAssembly, repeat: usize) -> impl Iterator<Item = GlyphPart> + '_ { fn parts(assembly: GlyphAssembly, repeat: usize) -> impl Iterator<Item = GlyphPart> + '_ {
assembly.parts.into_iter().flat_map(move |part| { assembly.parts.into_iter().flat_map(move |part| {
let count = if part.part_flags.extender() { repeat } else { 1 }; let count = if part.part_flags.extender() { repeat } else { 1 };
std::iter::repeat(part).take(count) std::iter::repeat_n(part, count)
}) })
} }

View File

@ -21,7 +21,7 @@ use crate::foundations::{
/// ///
/// Type casting works as follows: /// Type casting works as follows:
/// - [`Reflect for T`](Reflect) describes the possible Typst values for `T` /// - [`Reflect for T`](Reflect) describes the possible Typst values for `T`
/// (for documentation and autocomplete). /// (for documentation and autocomplete).
/// - [`IntoValue for T`](IntoValue) is for conversion from `T -> Value` /// - [`IntoValue for T`](IntoValue) is for conversion from `T -> Value`
/// (infallible) /// (infallible)
/// - [`FromValue for T`](FromValue) is for conversion from `Value -> T` /// - [`FromValue for T`](FromValue) is for conversion from `Value -> T`

View File

@ -394,7 +394,7 @@ impl NumberingKind {
const SYMBOLS: &[char] = &['*', '†', '‡', '§', '¶', '‖']; const SYMBOLS: &[char] = &['*', '†', '‡', '§', '¶', '‖'];
let symbol = SYMBOLS[(n - 1) % SYMBOLS.len()]; let symbol = SYMBOLS[(n - 1) % SYMBOLS.len()];
let amount = ((n - 1) / SYMBOLS.len()) + 1; let amount = ((n - 1) / SYMBOLS.len()) + 1;
std::iter::repeat(symbol).take(amount).collect() std::iter::repeat_n(symbol, amount).collect()
} }
Self::Hebrew => hebrew_numeral(n), Self::Hebrew => hebrew_numeral(n),

View File

@ -574,8 +574,7 @@ impl Gradient {
} }
let n = repetitions.v; let n = repetitions.v;
let mut stops = std::iter::repeat(self.stops_ref()) let mut stops = std::iter::repeat_n(self.stops_ref(), n)
.take(n)
.enumerate() .enumerate()
.flat_map(|(i, stops)| { .flat_map(|(i, stops)| {
let mut stops = stops let mut stops = stops

View File

@ -69,9 +69,11 @@ pub fn render_shape(canvas: &mut sk::Pixmap, state: State, shape: &Shape) -> Opt
let dash = dash.as_ref().and_then(to_sk_dash_pattern); let dash = dash.as_ref().and_then(to_sk_dash_pattern);
let bbox = shape.geometry.bbox_size(); let bbox = shape.geometry.bbox_size();
let offset_bbox = (!matches!(shape.geometry, Geometry::Line(..))) let offset_bbox = if !matches!(shape.geometry, Geometry::Line(..)) {
.then(|| offset_bounding_box(bbox, *thickness)) offset_bounding_box(bbox, *thickness)
.unwrap_or(bbox); } else {
bbox
};
let fill_transform = let fill_transform =
(!matches!(shape.geometry, Geometry::Line(..))).then(|| { (!matches!(shape.geometry, Geometry::Line(..))).then(|| {