diff --git a/crates/typst-cli/src/server.rs b/crates/typst-cli/src/server.rs index 8910e0323..11c564e8d 100644 --- a/crates/typst-cli/src/server.rs +++ b/crates/typst-cli/src/server.rs @@ -162,7 +162,7 @@ impl Bucket { } /// Retrieves the current data in the bucket. - fn get(&self) -> MutexGuard { + fn get(&self) -> MutexGuard<'_, T> { self.mutex.lock() } diff --git a/crates/typst-cli/src/world.rs b/crates/typst-cli/src/world.rs index 8ad766b14..900199354 100644 --- a/crates/typst-cli/src/world.rs +++ b/crates/typst-cli/src/world.rs @@ -361,22 +361,20 @@ impl SlotCell { f: impl FnOnce(Vec, Option) -> FileResult, ) -> FileResult { // If we accessed the file already in this compilation, retrieve it. - if mem::replace(&mut self.accessed, true) { - if let Some(data) = &self.data { + if mem::replace(&mut self.accessed, true) + && let Some(data) = &self.data { return data.clone(); } - } // Read and hash the file. let result = timed!("loading file", load()); let fingerprint = timed!("hashing file", typst::utils::hash128(&result)); // If the file contents didn't change, yield the old processed data. - if mem::replace(&mut self.fingerprint, fingerprint) == fingerprint { - if let Some(data) = &self.data { + if mem::replace(&mut self.fingerprint, fingerprint) == fingerprint + && let Some(data) = &self.data { return data.clone(); } - } let prev = self.data.take().and_then(Result::ok); let value = result.and_then(|data| f(data, prev)); diff --git a/crates/typst-eval/src/access.rs b/crates/typst-eval/src/access.rs index 22a6b7f3d..ddcc8b98b 100644 --- a/crates/typst-eval/src/access.rs +++ b/crates/typst-eval/src/access.rs @@ -29,11 +29,10 @@ impl Access for ast::Expr<'_> { impl Access for ast::Ident<'_> { fn access<'a>(self, vm: &'a mut Vm) -> SourceResult<&'a mut Value> { let span = self.span(); - if vm.inspected == Some(span) { - if let Ok(binding) = vm.scopes.get(&self) { + if vm.inspected == Some(span) + && let Ok(binding) = vm.scopes.get(&self) { vm.trace(binding.read().clone()); } - } vm.scopes .get_mut(&self) .and_then(|b| b.write().map_err(Into::into)) diff --git a/crates/typst-eval/src/import.rs b/crates/typst-eval/src/import.rs index 1b1641487..138d7ccfe 100644 --- a/crates/typst-eval/src/import.rs +++ b/crates/typst-eval/src/import.rs @@ -46,15 +46,14 @@ impl Eval for ast::ModuleImport<'_> { // If there is a rename, import the source itself under that name. let new_name = self.new_name(); if let Some(new_name) = new_name { - if let ast::Expr::Ident(ident) = self.source() { - if ident.as_str() == new_name.as_str() { + if let ast::Expr::Ident(ident) = self.source() + && ident.as_str() == new_name.as_str() { // Warn on `import x as x` vm.engine.sink.warn(warning!( new_name.span(), "unnecessary import rename to same name", )); } - } // Define renamed module on the scope. vm.define(new_name, source.clone()); @@ -142,8 +141,8 @@ impl Eval for ast::ModuleImport<'_> { // it. // Warn on `import ...: x as x` - if let ast::ImportItem::Renamed(renamed_item) = &item { - if renamed_item.original_name().as_str() + if let ast::ImportItem::Renamed(renamed_item) = &item + && renamed_item.original_name().as_str() == renamed_item.new_name().as_str() { vm.engine.sink.warn(warning!( @@ -151,7 +150,6 @@ impl Eval for ast::ModuleImport<'_> { "unnecessary import rename to same name", )); } - } vm.bind(item.bound_name(), binding.clone()); } diff --git a/crates/typst-eval/src/ops.rs b/crates/typst-eval/src/ops.rs index ebbd67430..9a8eb5239 100644 --- a/crates/typst-eval/src/ops.rs +++ b/crates/typst-eval/src/ops.rs @@ -76,13 +76,12 @@ fn apply_assignment( // An assignment to a dictionary field is different from a normal access // since it can create the field instead of just modifying it. - if binary.op() == ast::BinOp::Assign { - if let ast::Expr::FieldAccess(access) = lhs { + if binary.op() == ast::BinOp::Assign + && let ast::Expr::FieldAccess(access) = lhs { let dict = access_dict(vm, access)?; dict.insert(access.field().get().clone().into(), rhs); return Ok(Value::None); } - } let location = binary.lhs().access(vm)?; let lhs = std::mem::take(&mut *location); diff --git a/crates/typst-eval/src/rules.rs b/crates/typst-eval/src/rules.rs index eb6a1e6da..36fde561c 100644 --- a/crates/typst-eval/src/rules.rs +++ b/crates/typst-eval/src/rules.rs @@ -12,11 +12,10 @@ impl Eval for ast::SetRule<'_> { type Output = Styles; fn eval(self, vm: &mut Vm) -> SourceResult { - if let Some(condition) = self.condition() { - if !condition.eval(vm)?.cast::().at(condition.span())? { + if let Some(condition) = self.condition() + && !condition.eval(vm)?.cast::().at(condition.span())? { return Ok(Styles::new()); } - } let target = self.target(); let target = target diff --git a/crates/typst-html/src/rules.rs b/crates/typst-html/src/rules.rs index 3d215d56e..14885bd36 100644 --- a/crates/typst-html/src/rules.rs +++ b/crates/typst-html/src/rules.rs @@ -238,14 +238,12 @@ const QUOTE_RULE: ShowFn = |elem, _, styles| { if block { let mut blockquote = HtmlElem::new(tag::blockquote).with_body(Some(realized)); - if let Some(Attribution::Content(attribution)) = attribution { - if let Some(link) = attribution.to_packed::() { - if let LinkTarget::Dest(Destination::Url(url)) = &link.dest { + if let Some(Attribution::Content(attribution)) = attribution + && let Some(link) = attribution.to_packed::() + && let LinkTarget::Dest(Destination::Url(url)) = &link.dest { blockquote = blockquote.with_attr(attr::cite, url.clone().into_inner()); } - } - } realized = blockquote.pack().spanned(span); diff --git a/crates/typst-ide/src/analyze.rs b/crates/typst-ide/src/analyze.rs index e9fb8a7d7..e7fd8af8e 100644 --- a/crates/typst-ide/src/analyze.rs +++ b/crates/typst-ide/src/analyze.rs @@ -27,17 +27,15 @@ pub fn analyze_expr( ast::Expr::Numeric(v) => Value::numeric(v.get()), ast::Expr::Str(v) => Value::Str(v.get().into()), _ => { - if node.kind() == SyntaxKind::Contextual { - if let Some(child) = node.children().next_back() { + if node.kind() == SyntaxKind::Contextual + && let Some(child) = node.children().next_back() { return analyze_expr(world, &child); } - } - if let Some(parent) = node.parent() { - if parent.kind() == SyntaxKind::FieldAccess && node.index() > 0 { + if let Some(parent) = node.parent() + && parent.kind() == SyntaxKind::FieldAccess && node.index() > 0 { return analyze_expr(world, parent); } - } return typst::trace::(world.upcast(), node.span()); } diff --git a/crates/typst-ide/src/complete.rs b/crates/typst-ide/src/complete.rs index 5b6d6fd97..6cde69f3c 100644 --- a/crates/typst-ide/src/complete.rs +++ b/crates/typst-ide/src/complete.rs @@ -1382,11 +1382,10 @@ impl<'a> CompletionContext<'a> { } } else if at { apply = Some(eco_format!("at(\"{label}\")")); - } else if label.starts_with('"') && self.after.starts_with('"') { - if let Some(trimmed) = label.strip_suffix('"') { + } else if label.starts_with('"') && self.after.starts_with('"') + && let Some(trimmed) = label.strip_suffix('"') { apply = Some(trimmed.into()); } - } self.completions.push(Completion { kind: kind.unwrap_or_else(|| match value { diff --git a/crates/typst-ide/src/jump.rs b/crates/typst-ide/src/jump.rs index c9a53547a..f0035163b 100644 --- a/crates/typst-ide/src/jump.rs +++ b/crates/typst-ide/src/jump.rs @@ -36,8 +36,8 @@ pub fn jump_from_click( ) -> Option { // Try to find a link first. for (pos, item) in frame.items() { - if let FrameItem::Link(dest, size) = item { - if is_in_rect(*pos, *size, click) { + if let FrameItem::Link(dest, size) = item + && is_in_rect(*pos, *size, click) { return Some(match dest { Destination::Url(url) => Jump::Url(url.clone()), Destination::Position(pos) => Jump::Position(*pos), @@ -46,7 +46,6 @@ pub fn jump_from_click( } }); } - } } // If there's no link, search for a jump target. @@ -54,11 +53,10 @@ pub fn jump_from_click( match item { FrameItem::Group(group) => { let pos = click - pos; - if let Some(clip) = &group.clip { - if !clip.contains(FillRule::NonZero, pos) { + if let Some(clip) = &group.clip + && !clip.contains(FillRule::NonZero, pos) { continue; } - } // Realistic transforms should always be invertible. // An example of one that isn't is a scale of 0, which would // not be clickable anyway. @@ -178,11 +176,10 @@ pub fn jump_from_cursor( /// Find the position of a span in a frame. fn find_in_frame(frame: &Frame, span: Span) -> Option { for &(mut pos, ref item) in frame.items() { - if let FrameItem::Group(group) = item { - if let Some(point) = find_in_frame(&group.frame, span) { + if let FrameItem::Group(group) = item + && let Some(point) = find_in_frame(&group.frame, span) { return Some(pos + point.transform(group.transform)); } - } if let FrameItem::Text(text) = item { for glyph in &text.glyphs { diff --git a/crates/typst-ide/src/matchers.rs b/crates/typst-ide/src/matchers.rs index 93fdc5dd5..709d1d156 100644 --- a/crates/typst-ide/src/matchers.rs +++ b/crates/typst-ide/src/matchers.rs @@ -59,11 +59,10 @@ pub fn named_items( }; // Seeing the module itself. - if let Some((name, span)) = name_and_span { - if let Some(res) = recv(NamedItem::Module(&name, span, module)) { + if let Some((name, span)) = name_and_span + && let Some(res) = recv(NamedItem::Module(&name, span, module)) { return Some(res); } - } // Seeing the imported items. match imports { @@ -124,8 +123,8 @@ pub fn named_items( } if let Some(parent) = node.parent() { - if let Some(v) = parent.cast::() { - if node.prev_sibling_kind() != Some(SyntaxKind::In) { + if let Some(v) = parent.cast::() + && node.prev_sibling_kind() != Some(SyntaxKind::In) { let pattern = v.pattern(); for ident in pattern.bindings() { if let Some(res) = recv(NamedItem::Var(ident)) { @@ -133,7 +132,6 @@ pub fn named_items( } } } - } if let Some(v) = parent.cast::().filter(|v| { // Check if the node is in the body of the closure. @@ -155,11 +153,10 @@ pub fn named_items( } } ast::Param::Spread(s) => { - if let Some(sink_ident) = s.sink_ident() { - if let Some(t) = recv(NamedItem::Var(sink_ident)) { + if let Some(sink_ident) = s.sink_ident() + && let Some(t) = recv(NamedItem::Var(sink_ident)) { return Some(t); } - } } } } @@ -216,7 +213,7 @@ impl<'a> NamedItem<'a> { /// Categorize an expression into common classes IDE functionality can operate /// on. -pub fn deref_target(node: LinkedNode) -> Option> { +pub fn deref_target(node: LinkedNode<'_>) -> Option> { // Move to the first ancestor that is an expression. let mut ancestor = node; while !ancestor.is::() { diff --git a/crates/typst-ide/src/tooltip.rs b/crates/typst-ide/src/tooltip.rs index e0d66a89b..700414637 100644 --- a/crates/typst-ide/src/tooltip.rs +++ b/crates/typst-ide/src/tooltip.rs @@ -66,11 +66,10 @@ fn expr_tooltip(world: &dyn IdeWorld, leaf: &LinkedNode) -> Option { return Some(Tooltip::Text(plain_docs_sentence(docs))); } - if let &Value::Length(length) = value { - if let Some(tooltip) = length_tooltip(length) { + if let &Value::Length(length) = value + && let Some(tooltip) = length_tooltip(length) { return Some(tooltip); } - } } if expr.is_literal() { @@ -93,11 +92,10 @@ fn expr_tooltip(world: &dyn IdeWorld, leaf: &LinkedNode) -> Option { last = Some((value, 1)); } - if let Some((_, count)) = last { - if count > 1 { + if let Some((_, count)) = last + && count > 1 { write!(pieces.last_mut().unwrap(), " (×{count})").unwrap(); } - } if iter.next().is_some() { pieces.push("...".into()); diff --git a/crates/typst-layout/src/flow/block.rs b/crates/typst-layout/src/flow/block.rs index d6cfe3a9e..11096dc7a 100644 --- a/crates/typst-layout/src/flow/block.rs +++ b/crates/typst-layout/src/flow/block.rs @@ -407,11 +407,10 @@ fn distribute<'a>( // If there is still something remaining, apply it to the // last region (it will overflow, but there's nothing else // we can do). - if !remaining.approx_empty() { - if let Some(last) = buf.last_mut() { + if !remaining.approx_empty() + && let Some(last) = buf.last_mut() { *last += remaining; } - } // Distribute the heights to the first region and the // backlog. There is no last region, since the height is diff --git a/crates/typst-layout/src/flow/collect.rs b/crates/typst-layout/src/flow/collect.rs index 76268b590..561b578bb 100644 --- a/crates/typst-layout/src/flow/collect.rs +++ b/crates/typst-layout/src/flow/collect.rs @@ -684,11 +684,10 @@ impl CachedCell { let input_hash = typst_utils::hash128(&input); let mut slot = self.0.borrow_mut(); - if let Some((hash, output)) = &*slot { - if *hash == input_hash { + if let Some((hash, output)) = &*slot + && *hash == input_hash { return output.clone(); } - } let output = f(input); *slot = Some((input_hash, output.clone())); diff --git a/crates/typst-layout/src/grid/layouter.rs b/crates/typst-layout/src/grid/layouter.rs index a5803f830..ee613f8f2 100644 --- a/crates/typst-layout/src/grid/layouter.rs +++ b/crates/typst-layout/src/grid/layouter.rs @@ -274,32 +274,29 @@ impl<'a> GridLayouter<'a> { pub fn layout(mut self, engine: &mut Engine) -> SourceResult { self.measure_columns(engine)?; - if let Some(footer) = &self.grid.footer { - if footer.repeated { + if let Some(footer) = &self.grid.footer + && footer.repeated { // Ensure rows in the first region will be aware of the // possible presence of the footer. self.prepare_footer(footer, engine, 0)?; self.regions.size.y -= self.current.footer_height; self.current.initial_after_repeats = self.regions.size.y; } - } let mut y = 0; let mut consecutive_header_count = 0; while y < self.grid.rows.len() { if let Some(next_header) = self.upcoming_headers.get(consecutive_header_count) - { - if next_header.range.contains(&y) { + && next_header.range.contains(&y) { self.place_new_headers(&mut consecutive_header_count, engine)?; y = next_header.range.end; // Skip header rows during normal layout. continue; } - } - if let Some(footer) = &self.grid.footer { - if footer.repeated && y >= footer.start { + if let Some(footer) = &self.grid.footer + && footer.repeated && y >= footer.start { if y == footer.start { self.layout_footer(footer, engine, self.finished.len())?; self.flush_orphans(); @@ -307,7 +304,6 @@ impl<'a> GridLayouter<'a> { y = footer.end; continue; } - } self.layout_row(y, engine, 0)?; @@ -1283,15 +1279,13 @@ impl<'a> GridLayouter<'a> { // remeasure. if let Some([first, rest @ ..]) = frames.get(measurement_data.frames_in_previous_regions..) - { - if can_skip + && can_skip && breakable && first.is_empty() && rest.iter().any(|frame| !frame.is_empty()) { return Ok(None); } - } // Skip frames from previous regions if applicable. let mut sizes = frames @@ -1529,8 +1523,8 @@ impl<'a> GridLayouter<'a> { // The latest rows have orphan prevention (headers) and no other rows // were placed, so remove those rows and try again in a new region, // unless this is the last region. - if let Some(orphan_snapshot) = self.current.lrows_orphan_snapshot.take() { - if !last { + if let Some(orphan_snapshot) = self.current.lrows_orphan_snapshot.take() + && !last { self.current.lrows.truncate(orphan_snapshot); self.current.repeated_header_rows = self.current.repeated_header_rows.min(orphan_snapshot); @@ -1540,7 +1534,6 @@ impl<'a> GridLayouter<'a> { self.current.last_repeated_header_end = 0; } } - } if self .current @@ -1571,8 +1564,8 @@ impl<'a> GridLayouter<'a> { && self.current.could_progress_at_top; let mut laid_out_footer_start = None; - if !footer_would_be_widow { - if let Some(footer) = &self.grid.footer { + if !footer_would_be_widow + && let Some(footer) = &self.grid.footer { // Don't layout the footer if it would be alone with the header // in the page (hence the widow check), and don't layout it // twice (check below). @@ -1587,7 +1580,6 @@ impl<'a> GridLayouter<'a> { self.layout_footer(footer, engine, self.finished.len())?; } } - } // Determine the height of existing rows in the region. let mut used = Abs::zero(); diff --git a/crates/typst-layout/src/grid/lines.rs b/crates/typst-layout/src/grid/lines.rs index d5da7e263..0b823c07d 100644 --- a/crates/typst-layout/src/grid/lines.rs +++ b/crates/typst-layout/src/grid/lines.rs @@ -291,13 +291,12 @@ pub fn vline_stroke_at_row( // We would then analyze the cell one column after (if at a gutter // column), and/or one row below (if at a gutter row), in order to // check if it would be merged with a cell before the vline. - if let Some(parent) = grid.effective_parent_cell_position(x, y) { - if parent.x < x { + if let Some(parent) = grid.effective_parent_cell_position(x, y) + && parent.x < x { // There is a colspan cell going through this vline's position, // so don't draw it here. return None; } - } } let (left_cell_stroke, left_cell_prioritized) = x @@ -416,8 +415,8 @@ pub fn hline_stroke_at_column( // We would then analyze the cell one column after (if at a gutter // column), and/or one row below (if at a gutter row), in order to // check if it would be merged with a cell before the hline. - if let Some(parent) = grid.effective_parent_cell_position(x, y) { - if parent.y < y { + if let Some(parent) = grid.effective_parent_cell_position(x, y) + && parent.y < y { // Get the first 'y' spanned by the possible rowspan in this region. // The 'parent.y' row and any other spanned rows above 'y' could be // missing from this region, which could have lead the check above @@ -437,7 +436,6 @@ pub fn hline_stroke_at_column( return None; } } - } } // When the hline is at the top of the region and this isn't the first diff --git a/crates/typst-layout/src/grid/repeated.rs b/crates/typst-layout/src/grid/repeated.rs index 8db33df5e..573ef1a47 100644 --- a/crates/typst-layout/src/grid/repeated.rs +++ b/crates/typst-layout/src/grid/repeated.rs @@ -240,8 +240,8 @@ impl<'a> GridLayouter<'a> { self.current.initial_after_repeats = self.regions.size.y; } - if let Some(footer) = &self.grid.footer { - if footer.repeated && skipped_region { + if let Some(footer) = &self.grid.footer + && footer.repeated && skipped_region { // Simulate the footer again; the region's 'full' might have // changed. self.regions.size.y += self.current.footer_height; @@ -250,7 +250,6 @@ impl<'a> GridLayouter<'a> { .height; self.regions.size.y -= self.current.footer_height; } - } let repeating_header_rows = total_header_row_count(self.repeating_headers.iter().copied()); diff --git a/crates/typst-layout/src/grid/rowspans.rs b/crates/typst-layout/src/grid/rowspans.rs index 02ea14813..c31bfcb28 100644 --- a/crates/typst-layout/src/grid/rowspans.rs +++ b/crates/typst-layout/src/grid/rowspans.rs @@ -238,8 +238,8 @@ impl GridLayouter<'_> { // current row is dynamic and depends on the amount of upcoming // unbreakable cells (with or without a rowspan setting). let mut amount_unbreakable_rows = None; - if let Some(footer) = &self.grid.footer { - if !footer.repeated && current_row >= footer.start { + if let Some(footer) = &self.grid.footer + && !footer.repeated && current_row >= footer.start { // Non-repeated footer, so keep it unbreakable. // // TODO(subfooters): This will become unnecessary @@ -247,7 +247,6 @@ impl GridLayouter<'_> { // have widow prevention. amount_unbreakable_rows = Some(self.grid.rows.len() - footer.start); } - } let row_group = self.simulate_unbreakable_row_group( current_row, @@ -1268,9 +1267,8 @@ fn subtract_end_sizes(sizes: &mut Vec, mut subtract: Abs) { while subtract > Abs::zero() && sizes.last().is_some_and(|&size| size <= subtract) { subtract -= sizes.pop().unwrap(); } - if subtract > Abs::zero() { - if let Some(last_size) = sizes.last_mut() { + if subtract > Abs::zero() + && let Some(last_size) = sizes.last_mut() { *last_size -= subtract; } - } } diff --git a/crates/typst-layout/src/inline/collect.rs b/crates/typst-layout/src/inline/collect.rs index 2744b31e0..1856cb13d 100644 --- a/crates/typst-layout/src/inline/collect.rs +++ b/crates/typst-layout/src/inline/collect.rs @@ -274,12 +274,11 @@ impl<'a> Collector<'a> { let segment_len = self.full.len() - prev; // Merge adjacent text segments with the same styles. - if let Some(Segment::Text(last_len, last_styles)) = self.segments.last_mut() { - if *last_styles == styles { + if let Some(Segment::Text(last_len, last_styles)) = self.segments.last_mut() + && *last_styles == styles { *last_len += segment_len; return; } - } self.segments.push(Segment::Text(segment_len, styles)); } diff --git a/crates/typst-layout/src/inline/line.rs b/crates/typst-layout/src/inline/line.rs index 58162d12b..2d921b394 100644 --- a/crates/typst-layout/src/inline/line.rs +++ b/crates/typst-layout/src/inline/line.rs @@ -155,18 +155,16 @@ pub fn line<'a>( let mut items = collect_items(engine, p, range, trim); // Add a hyphen at the line start, if a previous dash should be repeated. - if pred.is_some_and(|pred| should_repeat_hyphen(pred, full)) { - if let Some(shaped) = items.first_text_mut() { + if pred.is_some_and(|pred| should_repeat_hyphen(pred, full)) + && let Some(shaped) = items.first_text_mut() { shaped.prepend_hyphen(engine, p.config.fallback); } - } // Add a hyphen at the line end, if we ended on a soft hyphen. - if dash == Some(Dash::Soft) { - if let Some(shaped) = items.last_text_mut() { + if dash == Some(Dash::Soft) + && let Some(shaped) = items.last_text_mut() { shaped.push_hyphen(engine, p.config.fallback); } - } // Deal with CJ characters at line boundaries. adjust_cj_at_line_boundaries(p, full, &mut items); @@ -218,11 +216,10 @@ fn collect_items<'a>( } // Add fallback text to expand the line height, if necessary. - if !items.iter().any(|item| matches!(item, Item::Text(_))) { - if let Some(fallback) = fallback { + if !items.iter().any(|item| matches!(item, Item::Text(_))) + && let Some(fallback) = fallback { items.push(fallback, usize::MAX); } - } items } @@ -461,9 +458,9 @@ pub fn commit( } // Handle hanging punctuation to the left. - if let Some(Item::Text(text)) = line.items.first() { - if let Some(glyph) = text.glyphs.first() { - if !text.dir.is_positive() + if let Some(Item::Text(text)) = line.items.first() + && let Some(glyph) = text.glyphs.first() + && !text.dir.is_positive() && text.styles.get(TextElem::overhang) && (line.items.len() > 1 || text.glyphs.len() > 1) { @@ -471,21 +468,17 @@ pub fn commit( offset -= amount; remaining += amount; } - } - } // Handle hanging punctuation to the right. - if let Some(Item::Text(text)) = line.items.last() { - if let Some(glyph) = text.glyphs.last() { - if text.dir.is_positive() + if let Some(Item::Text(text)) = line.items.last() + && let Some(glyph) = text.glyphs.last() + && text.dir.is_positive() && text.styles.get(TextElem::overhang) && (line.items.len() > 1 || text.glyphs.len() > 1) { let amount = overhang(glyph.c) * glyph.x_advance.at(glyph.size); remaining += amount; } - } - } // Determine how much additional space is needed. The justification_ratio is // for the first step justification, extra_justification is for the last diff --git a/crates/typst-layout/src/inline/linebreak.rs b/crates/typst-layout/src/inline/linebreak.rs index 955360df1..e40027edb 100644 --- a/crates/typst-layout/src/inline/linebreak.rs +++ b/crates/typst-layout/src/inline/linebreak.rs @@ -136,13 +136,12 @@ fn linebreak_simple<'a>( // If the line doesn't fit anymore, we push the last fitting attempt // into the stack and rebuild the line from the attempt's end. The // resulting line cannot be broken up further. - if !width.fits(attempt.width) { - if let Some((last_attempt, last_end)) = last.take() { + if !width.fits(attempt.width) + && let Some((last_attempt, last_end)) = last.take() { lines.push(last_attempt); start = last_end; attempt = line(engine, p, start..end, breakpoint, lines.last()); } - } // Finish the current line if there is a mandatory line break (i.e. due // to "\n") or if the line doesn't fit horizontally already since then diff --git a/crates/typst-layout/src/math/fragment.rs b/crates/typst-layout/src/math/fragment.rs index 758dd401f..877158100 100644 --- a/crates/typst-layout/src/math/fragment.rs +++ b/crates/typst-layout/src/math/fragment.rs @@ -681,7 +681,7 @@ fn min_connector_overlap(font: &Font) -> Option { .map(|variants| font.to_em(variants.min_connector_overlap)) } -fn glyph_construction(font: &Font, id: GlyphId, axis: Axis) -> Option { +fn glyph_construction(font: &Font, id: GlyphId, axis: Axis) -> Option> { font.ttf() .tables() .math? @@ -810,7 +810,7 @@ fn assemble( /// Return an iterator over the assembly's parts with extenders repeated the /// specified number of times. -fn parts(assembly: GlyphAssembly, repeat: usize) -> impl Iterator + '_ { +fn parts(assembly: GlyphAssembly<'_>, repeat: usize) -> impl Iterator + '_ { assembly.parts.into_iter().flat_map(move |part| { let count = if part.part_flags.extender() { repeat } else { 1 }; std::iter::repeat_n(part, count) diff --git a/crates/typst-layout/src/math/lr.rs b/crates/typst-layout/src/math/lr.rs index cba794935..59dac03af 100644 --- a/crates/typst-layout/src/math/lr.rs +++ b/crates/typst-layout/src/math/lr.rs @@ -21,11 +21,10 @@ pub fn layout_lr( } // Extract implicit LrElem. - if let Some(lr) = body.to_packed::() { - if lr.size.get(styles).is_one() { + if let Some(lr) = body.to_packed::() + && lr.size.get(styles).is_one() { body = &lr.body; } - } let mut fragments = ctx.layout_into_fragments(body, styles)?; @@ -55,12 +54,11 @@ pub fn layout_lr( // Handle MathFragment::Glyph fragments that should be scaled up. for fragment in inner_fragments.iter_mut() { - if let MathFragment::Glyph(glyph) = fragment { - if glyph.mid_stretched == Some(false) { + if let MathFragment::Glyph(glyph) = fragment + && glyph.mid_stretched == Some(false) { glyph.mid_stretched = Some(true); scale(ctx, fragment, relative_to, height); } - } } // Remove weak SpacingFragment immediately after the opening or immediately diff --git a/crates/typst-layout/src/math/mod.rs b/crates/typst-layout/src/math/mod.rs index 390835067..5ee3e14a8 100644 --- a/crates/typst-layout/src/math/mod.rs +++ b/crates/typst-layout/src/math/mod.rs @@ -603,14 +603,13 @@ fn layout_h( ctx: &mut MathContext, styles: StyleChain, ) -> SourceResult<()> { - if let Spacing::Rel(rel) = elem.amount { - if rel.rel.is_zero() { + if let Spacing::Rel(rel) = elem.amount + && rel.rel.is_zero() { ctx.push(MathFragment::Spacing( rel.abs.resolve(styles), elem.weak.get(styles), )); } - } Ok(()) } diff --git a/crates/typst-layout/src/math/run.rs b/crates/typst-layout/src/math/run.rs index 161fa1062..fb206dc2e 100644 --- a/crates/typst-layout/src/math/run.rs +++ b/crates/typst-layout/src/math/run.rs @@ -87,11 +87,10 @@ impl MathRun { // Insert spacing between the last and this non-ignorant item. if !fragment.is_ignorant() { - if let Some(i) = last { - if let Some(s) = spacing(&resolved[i], space.take(), &fragment) { + if let Some(i) = last + && let Some(s) = spacing(&resolved[i], space.take(), &fragment) { resolved.insert(i + 1, s); } - } last = Some(resolved.len()); } @@ -123,11 +122,10 @@ impl MathRun { 1 + self.0.iter().filter(|f| matches!(f, MathFragment::Linebreak)).count(); // A linebreak at the very end does not introduce an extra row. - if let Some(f) = self.0.last() { - if matches!(f, MathFragment::Linebreak) { + if let Some(f) = self.0.last() + && matches!(f, MathFragment::Linebreak) { count -= 1 } - } count } @@ -344,11 +342,10 @@ impl MathRun { descent = Abs::zero(); space_is_visible = true; - if let Some(f_next) = iter.peek() { - if !is_space(f_next) { + if let Some(f_next) = iter.peek() + && !is_space(f_next) { items.push(InlineItem::Space(Abs::zero(), true)); } - } } else { space_is_visible = false; } diff --git a/crates/typst-library/src/diag.rs b/crates/typst-library/src/diag.rs index 41b92ed65..611ec6338 100644 --- a/crates/typst-library/src/diag.rs +++ b/crates/typst-library/src/diag.rs @@ -296,14 +296,13 @@ impl Trace for SourceResult { let Some(trace_range) = world.range(span) else { return errors }; for error in errors.make_mut().iter_mut() { // Skip traces that surround the error. - if let Some(error_range) = world.range(error.span) { - if error.span.id() == span.id() + if let Some(error_range) = world.range(error.span) + && error.span.id() == span.id() && trace_range.start <= error_range.start && trace_range.end >= error_range.end { continue; } - } error.trace.push(Spanned::new(make_point(), span)); } diff --git a/crates/typst-library/src/foundations/cast.rs b/crates/typst-library/src/foundations/cast.rs index 5e0ba688e..17d194e1a 100644 --- a/crates/typst-library/src/foundations/cast.rs +++ b/crates/typst-library/src/foundations/cast.rs @@ -347,14 +347,13 @@ impl CastInfo { msg.hint(eco_format!("use `label({})` to create a label", s.repr())); } } - } else if let Value::Decimal(_) = found { - if !matching_type && parts.iter().any(|p| p == "float") { + } else if let Value::Decimal(_) = found + && !matching_type && parts.iter().any(|p| p == "float") { msg.hint(eco_format!( "if loss of precision is acceptable, explicitly cast the \ decimal to a float with `float(value)`" )); } - } msg } diff --git a/crates/typst-library/src/foundations/content/mod.rs b/crates/typst-library/src/foundations/content/mod.rs index 7ba790d88..f5e8314d8 100644 --- a/crates/typst-library/src/foundations/content/mod.rs +++ b/crates/typst-library/src/foundations/content/mod.rs @@ -174,11 +174,10 @@ impl Content { id: u8, styles: Option, ) -> Result { - if id == 255 { - if let Some(label) = self.label() { + if id == 255 + && let Some(label) = self.label() { return Ok(label.into_value()); } - } match self.0.handle().field(id) { Some(handle) => match styles { diff --git a/crates/typst-library/src/layout/corners.rs b/crates/typst-library/src/layout/corners.rs index fe69126a4..e47fee1e7 100644 --- a/crates/typst-library/src/layout/corners.rs +++ b/crates/typst-library/src/layout/corners.rs @@ -150,11 +150,10 @@ where T: PartialEq + IntoValue, { fn into_value(self) -> Value { - if self.is_uniform() { - if let Some(top_left) = self.top_left { + if self.is_uniform() + && let Some(top_left) = self.top_left { return top_left.into_value(); } - } let mut dict = Dict::new(); let mut handle = |key: &str, component: Option| { diff --git a/crates/typst-library/src/layout/grid/resolve.rs b/crates/typst-library/src/layout/grid/resolve.rs index f3004088e..edf50cdd2 100644 --- a/crates/typst-library/src/layout/grid/resolve.rs +++ b/crates/typst-library/src/layout/grid/resolve.rs @@ -2098,14 +2098,13 @@ fn check_for_conflicting_cell_row( ); } - if let Some((_, _, footer)) = footer { - if cell_y < footer.end && cell_y + rowspan > footer.start { + if let Some((_, _, footer)) = footer + && cell_y < footer.end && cell_y + rowspan > footer.start { bail!( "cell would conflict with footer spanning the same position"; hint: "try reducing the cell's rowspan or moving the footer" ); } - } Ok(()) } diff --git a/crates/typst-library/src/layout/page.rs b/crates/typst-library/src/layout/page.rs index a0b1c6fec..ab8cc8ea4 100644 --- a/crates/typst-library/src/layout/page.rs +++ b/crates/typst-library/src/layout/page.rs @@ -530,11 +530,10 @@ cast! { Margin, self => { let two_sided = self.two_sided.unwrap_or(false); - if !two_sided && self.sides.is_uniform() { - if let Some(left) = self.sides.left { + if !two_sided && self.sides.is_uniform() + && let Some(left) = self.sides.left { return left.into_value(); } - } let mut dict = Dict::new(); let mut handle = |key: &str, component: Option>>| { diff --git a/crates/typst-library/src/layout/sides.rs b/crates/typst-library/src/layout/sides.rs index e04b63d98..1147eeb77 100644 --- a/crates/typst-library/src/layout/sides.rs +++ b/crates/typst-library/src/layout/sides.rs @@ -184,11 +184,10 @@ where T: PartialEq + IntoValue, { fn into_value(self) -> Value { - if self.is_uniform() { - if let Some(left) = self.left { + if self.is_uniform() + && let Some(left) = self.left { return left.into_value(); } - } let mut dict = Dict::new(); let mut handle = |key: &str, component: Option| { diff --git a/crates/typst-library/src/model/bibliography.rs b/crates/typst-library/src/model/bibliography.rs index 188af4da1..ef7e69273 100644 --- a/crates/typst-library/src/model/bibliography.rs +++ b/crates/typst-library/src/model/bibliography.rs @@ -927,12 +927,11 @@ impl ElemRenderer<'_> { _ => {} } - if let Some(hayagriva::ElemMeta::Entry(i)) = elem.meta { - if let Some(location) = (self.link)(i) { + if let Some(hayagriva::ElemMeta::Entry(i)) = elem.meta + && let Some(location) = (self.link)(i) { let dest = Destination::Location(location); content = content.linked(dest); } - } Ok(content) } diff --git a/crates/typst-library/src/model/reference.rs b/crates/typst-library/src/model/reference.rs index f7922ef3e..cf1b43da0 100644 --- a/crates/typst-library/src/model/reference.rs +++ b/crates/typst-library/src/model/reference.rs @@ -210,12 +210,11 @@ impl Synthesize for Packed { elem.citation = Some(Some(citation)); elem.element = Some(None); - if !BibliographyElem::has(engine, elem.target) { - if let Ok(found) = engine.introspector.query_label(elem.target).cloned() { + if !BibliographyElem::has(engine, elem.target) + && let Ok(found) = engine.introspector.query_label(elem.target).cloned() { elem.element = Some(Some(found)); return Ok(()); } - } Ok(()) } diff --git a/crates/typst-library/src/text/font/book.rs b/crates/typst-library/src/text/font/book.rs index d0c821b39..374b83908 100644 --- a/crates/typst-library/src/text/font/book.rs +++ b/crates/typst-library/src/text/font/book.rs @@ -284,11 +284,9 @@ impl FontInfo { .raw_face() .table(Tag::from_bytes(b"OS/2")) .and_then(|os2| os2.get(32..45)) - { - if matches!(panose, [2, 2..=10, ..]) { + && matches!(panose, [2, 2..=10, ..]) { flags.insert(FontFlags::SERIF); } - } Some(FontInfo { family, @@ -397,11 +395,10 @@ fn typographic_family(mut family: &str) -> &str { // Also allow an extra modifier, but apply it only if it is separated it // from the text before it (to prevent false positives). - if let Some(t) = MODIFIERS.iter().find_map(|s| t.strip_suffix(s)) { - if let Some(stripped) = t.strip_suffix(SEPARATORS) { + if let Some(t) = MODIFIERS.iter().find_map(|s| t.strip_suffix(s)) + && let Some(stripped) = t.strip_suffix(SEPARATORS) { trimmed = stripped; } - } } // Apply style suffix trimming. diff --git a/crates/typst-library/src/text/lang.rs b/crates/typst-library/src/text/lang.rs index 4f8d1e93f..d396eef8b 100644 --- a/crates/typst-library/src/text/lang.rs +++ b/crates/typst-library/src/text/lang.rs @@ -144,17 +144,15 @@ cast! { self => self.as_str().into_value(), string: EcoString => { let result = Self::from_str(&string); - if result.is_err() { - if let Some((lang, region)) = string.split_once('-') { - if Lang::from_str(lang).is_ok() && Region::from_str(region).is_ok() { + if result.is_err() + && let Some((lang, region)) = string.split_once('-') + && Lang::from_str(lang).is_ok() && Region::from_str(region).is_ok() { return result .hint(eco_format!( "you should leave only \"{}\" in the `lang` parameter and specify \"{}\" in the `region` parameter", lang, region, )); } - } - } result? } diff --git a/crates/typst-library/src/text/mod.rs b/crates/typst-library/src/text/mod.rs index c2efe210b..5f2330cbd 100644 --- a/crates/typst-library/src/text/mod.rs +++ b/crates/typst-library/src/text/mod.rs @@ -270,15 +270,14 @@ pub struct TextElem { /// ``` #[parse({ let paint: Option> = args.named_or_find("fill")?; - if let Some(paint) = &paint { - if paint.v.relative() == Smart::Custom(RelativeTo::Self_) { + if let Some(paint) = &paint + && paint.v.relative() == Smart::Custom(RelativeTo::Self_) { bail!( paint.span, "gradients and tilings on text must be relative to the parent"; hint: "make sure to set `relative: auto` on your text fill" ); } - } paint.map(|paint| paint.v) })] #[default(Color::BLACK.into())] diff --git a/crates/typst-library/src/text/raw.rs b/crates/typst-library/src/text/raw.rs index 0e61a8ef1..1677d3d07 100644 --- a/crates/typst-library/src/text/raw.rs +++ b/crates/typst-library/src/text/raw.rs @@ -750,11 +750,10 @@ fn preprocess( styles: StyleChain, span: Span, ) -> EcoVec<(EcoString, Span)> { - if let RawContent::Lines(lines) = text { - if lines.iter().all(|(s, _)| !s.contains('\t')) { + if let RawContent::Lines(lines) = text + && lines.iter().all(|(s, _)| !s.contains('\t')) { return lines.clone(); } - } let mut text = text.get(); if text.contains('\t') { diff --git a/crates/typst-library/src/visualize/color.rs b/crates/typst-library/src/visualize/color.rs index dd0287d4b..9c8eacaf5 100644 --- a/crates/typst-library/src/visualize/color.rs +++ b/crates/typst-library/src/visualize/color.rs @@ -1123,8 +1123,8 @@ impl Color { } // Ensure that the hue circle is traversed in the short direction. - if let Some(index) = space.hue_index() { - if (c0[index] - c1[index]).abs() > 180.0 { + if let Some(index) = space.hue_index() + && (c0[index] - c1[index]).abs() > 180.0 { let (h0, h1) = if c0[index] < c1[index] { (c0[index] + 360.0, c1[index]) } else { @@ -1132,7 +1132,6 @@ impl Color { }; m[index] = (w0 * h0 + w1 * h1) / (w0 + w1); } - } m } else { diff --git a/crates/typst-macros/src/scope.rs b/crates/typst-macros/src/scope.rs index 392ab1a53..2eac76b53 100644 --- a/crates/typst-macros/src/scope.rs +++ b/crates/typst-macros/src/scope.rs @@ -14,14 +14,12 @@ pub fn scope(_: TokenStream, item: syn::Item) -> Result { let self_ty = &item.self_ty; let mut primitive_ident_ext = None; - if let syn::Type::Path(syn::TypePath { path, .. }) = self_ty.as_ref() { - if let Some(ident) = path.get_ident() { - if is_primitive(ident) { + if let syn::Type::Path(syn::TypePath { path, .. }) = self_ty.as_ref() + && let Some(ident) = path.get_ident() + && is_primitive(ident) { let ident_ext = quote::format_ident!("{ident}Ext"); primitive_ident_ext = Some(ident_ext); } - } - } let self_ty_expr = match &primitive_ident_ext { None => quote! { #self_ty }, diff --git a/crates/typst-macros/src/util.rs b/crates/typst-macros/src/util.rs index e8c0910b6..87e398c97 100644 --- a/crates/typst-macros/src/util.rs +++ b/crates/typst-macros/src/util.rs @@ -27,18 +27,15 @@ pub fn documentation(attrs: &[syn::Attribute]) -> String { // Parse doc comments. for attr in attrs { - if let syn::Meta::NameValue(meta) = &attr.meta { - if meta.path.is_ident("doc") { - if let syn::Expr::Lit(lit) = &meta.value { - if let syn::Lit::Str(string) = &lit.lit { + if let syn::Meta::NameValue(meta) = &attr.meta + && meta.path.is_ident("doc") + && let syn::Expr::Lit(lit) = &meta.value + && let syn::Lit::Str(string) = &lit.lit { let full = string.value(); let line = full.strip_prefix(' ').unwrap_or(&full); doc.push_str(line); doc.push('\n'); } - } - } - } } doc.trim().into() diff --git a/crates/typst-pdf/src/outline.rs b/crates/typst-pdf/src/outline.rs index f73822c4b..e95bf67fb 100644 --- a/crates/typst-pdf/src/outline.rs +++ b/crates/typst-pdf/src/outline.rs @@ -21,14 +21,13 @@ pub(crate) fn build_outline(gc: &GlobalContext) -> Outline { let elements = &gc.document.introspector.query(&HeadingElem::ELEM.select()); for elem in elements.iter() { - if let Some(page_ranges) = &gc.options.page_ranges { - if !page_ranges + if let Some(page_ranges) = &gc.options.page_ranges + && !page_ranges .includes_page(gc.document.introspector.page(elem.location().unwrap())) { // Don't bookmark headings in non-exported pages. continue; } - } let heading = elem.to_packed::().unwrap(); let leaf = HeadingNode::leaf(heading); diff --git a/crates/typst-realize/src/lib.rs b/crates/typst-realize/src/lib.rs index f3f071505..cbb3ac21d 100644 --- a/crates/typst-realize/src/lib.rs +++ b/crates/typst-realize/src/lib.rs @@ -307,12 +307,11 @@ fn visit_kind_rules<'a>( visit_regex_match(s, &[(content, styles)], m)?; return Ok(true); } - } else if let Some(elem) = content.to_packed::() { - if let Some(m) = find_regex_match_in_str(&elem.text, styles) { + } else if let Some(elem) = content.to_packed::() + && let Some(m) = find_regex_match_in_str(&elem.text, styles) { visit_regex_match(s, &[(content, styles)], m)?; return Ok(true); } - } } else { // Transparently wrap mathy content into equations. if content.can::() && !content.is::() { @@ -1092,11 +1091,10 @@ fn find_regex_match_in_elems<'a>( } let linebreak = content.is::(); - if linebreak { - if let SpaceState::Space(_) = space { + if linebreak + && let SpaceState::Space(_) = space { buf.pop(); } - } if styles != current && !buf.is_empty() { leftmost = find_regex_match_in_str(&buf, current); diff --git a/crates/typst-render/src/lib.rs b/crates/typst-render/src/lib.rs index 2c57fe2db..5a993dbb9 100644 --- a/crates/typst-render/src/lib.rs +++ b/crates/typst-render/src/lib.rs @@ -193,8 +193,8 @@ fn render_group(canvas: &mut sk::Pixmap, state: State, pos: Point, group: &Group let mut mask = state.mask; let storage; - if let Some(clip_curve) = group.clip.as_ref() { - if let Some(path) = shape::convert_curve(clip_curve) + if let Some(clip_curve) = group.clip.as_ref() + && let Some(path) = shape::convert_curve(clip_curve) .and_then(|path| path.transform(state.transform)) { if let Some(mask) = mask { @@ -226,7 +226,6 @@ fn render_group(canvas: &mut sk::Pixmap, state: State, pos: Point, group: &Group mask = Some(&storage); } - } render_frame(canvas, state.with_mask(mask), &group.frame); } diff --git a/crates/typst-render/src/text.rs b/crates/typst-render/src/text.rs index 55fe04b51..a56528220 100644 --- a/crates/typst-render/src/text.rs +++ b/crates/typst-render/src/text.rs @@ -87,8 +87,7 @@ fn render_outline_glyph( if let Some(FixedStroke { paint, thickness, cap, join, dash, miter_limit }) = &text.stroke - { - if thickness.to_f32() > 0.0 { + && thickness.to_f32() > 0.0 { let dash = dash.as_ref().and_then(shape::to_sk_dash_pattern); let paint = paint::to_sk_paint( @@ -110,7 +109,6 @@ fn render_outline_glyph( canvas.stroke_path(&path, &paint, &stroke, ts, state.mask); } - } return Some(()); } diff --git a/crates/typst-svg/src/lib.rs b/crates/typst-svg/src/lib.rs index 5b6db69da..85bd5d7cb 100644 --- a/crates/typst-svg/src/lib.rs +++ b/crates/typst-svg/src/lib.rs @@ -340,12 +340,11 @@ impl<'a> SVGRenderer<'a> { Destination::Location(loc) => { // TODO: Location links on the same page could also be supported // outside of HTML. - if let Some(introspector) = self.introspector { - if let Some(id) = introspector.html_id(*loc) { + if let Some(introspector) = self.introspector + && let Some(id) = introspector.html_id(*loc) { self.xml.write_attribute_fmt("href", format_args!("#{id}")); self.xml.write_attribute_fmt("xlink:href", format_args!("#{id}")); } - } } Destination::Position(_) => { // TODO: Links on the same page could be supported. diff --git a/crates/typst-syntax/src/highlight.rs b/crates/typst-syntax/src/highlight.rs index cd815694d..9754312b3 100644 --- a/crates/typst-syntax/src/highlight.rs +++ b/crates/typst-syntax/src/highlight.rs @@ -300,8 +300,8 @@ pub fn highlight(node: &LinkedNode) -> Option { fn highlight_ident(node: &LinkedNode) -> Option { // Are we directly before an argument list? let next_leaf = node.next_leaf(); - if let Some(next) = &next_leaf { - if node.range().end == next.offset() + if let Some(next) = &next_leaf + && node.range().end == next.offset() && ((next.kind() == SyntaxKind::LeftParen && matches!( next.parent_kind(), @@ -312,7 +312,6 @@ fn highlight_ident(node: &LinkedNode) -> Option { { return Some(Tag::Function); } - } // Are we in math? if node.kind() == SyntaxKind::MathIdent { @@ -379,14 +378,13 @@ pub fn highlight_html(root: &SyntaxNode) -> String { /// Highlight one source node, emitting HTML. fn highlight_html_impl(html: &mut String, node: &LinkedNode) { let mut span = false; - if let Some(tag) = highlight(node) { - if tag != Tag::Error { + if let Some(tag) = highlight(node) + && tag != Tag::Error { span = true; html.push_str(""); } - } let text = node.text(); if !text.is_empty() { diff --git a/crates/typst-syntax/src/lexer.rs b/crates/typst-syntax/src/lexer.rs index 82f65cd36..9da45958f 100644 --- a/crates/typst-syntax/src/lexer.rs +++ b/crates/typst-syntax/src/lexer.rs @@ -783,11 +783,10 @@ impl Lexer<'_> { let ident = self.s.from(start); let prev = self.s.get(0..start); - if !prev.ends_with(['.', '@']) || prev.ends_with("..") { - if let Some(keyword) = keyword(ident) { + if (!prev.ends_with(['.', '@']) || prev.ends_with("..")) + && let Some(keyword) = keyword(ident) { return keyword; } - } if ident == "_" { SyntaxKind::Underscore diff --git a/crates/typst-syntax/src/node.rs b/crates/typst-syntax/src/node.rs index 948657ca4..15c96b08f 100644 --- a/crates/typst-syntax/src/node.rs +++ b/crates/typst-syntax/src/node.rs @@ -733,11 +733,9 @@ impl<'a> LinkedNode<'a> { if children .peek() .is_none_or(|next| next.span().number() > span.number()) - { - if let Some(found) = child.find(span) { + && let Some(found) = child.find(span) { return Some(found); } - } } } diff --git a/crates/typst-syntax/src/parser.rs b/crates/typst-syntax/src/parser.rs index b452c2c09..22f073601 100644 --- a/crates/typst-syntax/src/parser.rs +++ b/crates/typst-syntax/src/parser.rs @@ -442,14 +442,13 @@ fn math_unparen(p: &mut Parser, m: Marker) { return; } - if let [first, .., last] = node.children_mut() { - if first.text() == "(" && last.text() == ")" { + if let [first, .., last] = node.children_mut() + && first.text() == "(" && last.text() == ")" { first.convert_to_kind(SyntaxKind::LeftParen); last.convert_to_kind(SyntaxKind::RightParen); // Only convert if we did have regular parens. node.convert_to_kind(SyntaxKind::Math); } - } } /// The unicode math class of a string. Only returns `Some` if `text` has @@ -1199,11 +1198,10 @@ fn array_or_dict_item(p: &mut Parser, state: &mut GroupState) { Some(ast::Expr::Ident(ident)) => Some(ident.get().clone()), Some(ast::Expr::Str(s)) => Some(s.get()), _ => None, - } { - if !state.seen.insert(key.clone()) { + } + && !state.seen.insert(key.clone()) { node.convert_to_error(eco_format!("duplicate key: {key}")); } - } p.wrap(m, pair_kind); state.maybe_just_parens = false; @@ -1855,8 +1853,8 @@ impl<'s> Parser<'s> { self.nl_mode = mode; func(self); self.nl_mode = previous; - if let Some(newline) = self.token.newline { - if mode != previous { + if let Some(newline) = self.token.newline + && mode != previous { // Restore our actual token's kind or insert a fake end. let actual_kind = self.token.node.kind(); if self.nl_mode.stop_at(newline, actual_kind) { @@ -1865,7 +1863,6 @@ impl<'s> Parser<'s> { self.token.kind = actual_kind; } } - } } /// Move the lexer forward and prepare the current token. In Code, this diff --git a/crates/typst-syntax/src/reparser.rs b/crates/typst-syntax/src/reparser.rs index 55555c96e..2df606310 100644 --- a/crates/typst-syntax/src/reparser.rs +++ b/crates/typst-syntax/src/reparser.rs @@ -70,14 +70,13 @@ fn try_reparse( } // If the child is a block, try to reparse the block. - if child.kind().is_block() { - if let Some(newborn) = reparse_block(text, new_range.clone()) { + if child.kind().is_block() + && let Some(newborn) = reparse_block(text, new_range.clone()) { return node .replace_children(i..i + 1, vec![newborn]) .is_ok() .then_some(new_range); } - } } // Does the child overlap with the edit? diff --git a/docs/src/link.rs b/docs/src/link.rs index 2e836b6ce..b883399e5 100644 --- a/docs/src/link.rs +++ b/docs/src/link.rs @@ -96,12 +96,11 @@ fn resolve_definition(head: &str, base: &str) -> StrResult { if let Ok(field) = value.field(next, ()) { route.push_str("/#definitions-"); route.push_str(next); - if let Some(next) = parts.next() { - if field.cast::().is_ok_and(|func| func.param(next).is_some()) { + if let Some(next) = parts.next() + && field.cast::().is_ok_and(|func| func.param(next).is_some()) { route.push('-'); route.push_str(next); } - } } else if value .clone() .cast::() diff --git a/tests/fuzz/src/compile.rs b/tests/fuzz/src/compile.rs index 945e9fce8..1bc85fd62 100644 --- a/tests/fuzz/src/compile.rs +++ b/tests/fuzz/src/compile.rs @@ -66,10 +66,9 @@ impl World for FuzzWorld { fuzz_target!(|text: &str| { let world = FuzzWorld::new(text); - if let Ok(document) = typst::compile::(&world).output { - if let Some(page) = document.pages.first() { + if let Ok(document) = typst::compile::(&world).output + && let Some(page) = document.pages.first() { std::hint::black_box(typst_render::render(page, 1.0)); } - } comemo::evict(10); });