diff --git a/macros/src/func.rs b/macros/src/func.rs index fe06749b0..3253455be 100644 --- a/macros/src/func.rs +++ b/macros/src/func.rs @@ -44,7 +44,7 @@ pub fn func(item: syn::Item) -> Result { let vis = &item.vis; let ident = &item.sig.ident; let s = ident.to_string(); - let mut chars = s.trim_end_matches("_").chars(); + let mut chars = s.trim_end_matches('_').chars(); let ty = quote::format_ident!( "{}{}Func", chars.next().unwrap().to_ascii_uppercase(), @@ -98,8 +98,8 @@ pub fn section(docs: &mut String, title: &str, level: usize) -> Option { let rest = &docs[start..]; let len = rest[1..] .find("\n# ") - .or(rest[1..].find("\n## ")) - .or(rest[1..].find("\n### ")) + .or_else(|| rest[1..].find("\n## ")) + .or_else(|| rest[1..].find("\n### ")) .map(|x| 1 + x) .unwrap_or(rest.len()); let end = start + len; diff --git a/macros/src/node.rs b/macros/src/node.rs index e8324594a..cffac1842 100644 --- a/macros/src/node.rs +++ b/macros/src/node.rs @@ -220,7 +220,7 @@ fn create(node: &Node) -> Result { let scope = quote::format_ident!("__{}_keys", node.self_name); for property in node.properties.iter() { - let (key, module) = create_property_module(node, &property); + let (key, module) = create_property_module(node, property); modules.push(module); let name = &property.name; diff --git a/src/export/pdf/image.rs b/src/export/pdf/image.rs index 78731734d..906737dee 100644 --- a/src/export/pdf/image.rs +++ b/src/export/pdf/image.rs @@ -20,7 +20,7 @@ pub fn write_images(ctx: &mut PdfContext) { match image.decode().unwrap().as_ref() { DecodedImage::Raster(dynamic, format) => { // TODO: Error if image could not be encoded. - let (data, filter, has_color) = encode_image(*format, &dynamic).unwrap(); + let (data, filter, has_color) = encode_image(*format, dynamic).unwrap(); let mut image = ctx.writer.image_xobject(image_ref, &data); image.filter(filter); image.width(width as i32); @@ -37,7 +37,7 @@ pub fn write_images(ctx: &mut PdfContext) { // Add a second gray-scale image containing the alpha values if // this image has an alpha channel. if dynamic.color().has_alpha() { - let (alpha_data, alpha_filter) = encode_alpha(&dynamic); + let (alpha_data, alpha_filter) = encode_alpha(dynamic); let mask_ref = ctx.alloc.bump(); image.s_mask(mask_ref); image.finish(); @@ -52,7 +52,7 @@ pub fn write_images(ctx: &mut PdfContext) { } DecodedImage::Svg(svg) => { let next_ref = svg2pdf::convert_tree_into( - &svg, + svg, svg2pdf::Options::default(), &mut ctx.writer, image_ref, diff --git a/src/export/pdf/page.rs b/src/export/pdf/page.rs index f2ab78e3a..d1a2e70e5 100644 --- a/src/export/pdf/page.rs +++ b/src/export/pdf/page.rs @@ -289,7 +289,7 @@ fn write_frame(ctx: &mut PageContext, frame: &Frame) { Element::Image(image, size) => write_image(ctx, x, y, image, *size), Element::Meta(meta, size) => match meta { Meta::Link(dest) => write_link(ctx, pos, dest, *size), - _ => {} + Meta::Node(_, _) => {} }, } } diff --git a/src/export/render.rs b/src/export/render.rs index 86648e969..b018608cb 100644 --- a/src/export/render.rs +++ b/src/export/render.rs @@ -9,7 +9,7 @@ use tiny_skia as sk; use ttf_parser::{GlyphId, OutlineBuilder}; use usvg::FitTo; -use crate::doc::{Element, Frame, Group, Text}; +use crate::doc::{Element, Frame, Group, Meta, Text}; use crate::geom::{ self, Abs, Geometry, Paint, PathElement, Shape, Size, Stroke, Transform, }; @@ -58,7 +58,10 @@ fn render_frame( Element::Image(image, size) => { render_image(canvas, ts, mask, image, *size); } - Element::Meta(_, _) => {} + Element::Meta(meta, _) => match meta { + Meta::Link(_) => {} + Meta::Node(_, _) => {} + }, } } } @@ -400,7 +403,7 @@ fn scaled_texture(image: &Image, w: u32, h: u32) -> Option> { } DecodedImage::Svg(tree) => { resvg::render( - &tree, + tree, FitTo::Size(w, h), sk::Transform::identity(), pixmap.as_mut(), diff --git a/src/ide/tooltip.rs b/src/ide/tooltip.rs index 8c734bbbb..0d46695b7 100644 --- a/src/ide/tooltip.rs +++ b/src/ide/tooltip.rs @@ -26,7 +26,7 @@ fn function_tooltip(world: &dyn World, leaf: &LinkedNode) -> Option { if let Some(Value::Func(func)) = world.library().scope.get(&ident); if let Some(info) = func.info(); then { - return Some(plain_docs_sentence(&info.docs)); + return Some(plain_docs_sentence(info.docs)); } } diff --git a/src/image.rs b/src/image.rs index 038641a42..44b00adb1 100644 --- a/src/image.rs +++ b/src/image.rs @@ -140,8 +140,8 @@ fn determine_size(data: &Buffer, format: ImageFormat) -> StrResult<(u32, u32)> { } ImageFormat::Vector(VectorFormat::Svg) => { let opts = usvg::Options::default(); - let tree = usvg::Tree::from_data(&data, &opts.to_ref()) - .map_err(format_usvg_error)?; + let tree = + usvg::Tree::from_data(data, &opts.to_ref()).map_err(format_usvg_error)?; let size = tree.svg_node().size; let width = size.width().ceil() as u32; diff --git a/src/model/array.rs b/src/model/array.rs index 28b9d1a03..0071d4f41 100644 --- a/src/model/array.rs +++ b/src/model/array.rs @@ -183,7 +183,7 @@ impl Array { /// Transform each item in the array with a function. pub fn map(&self, vm: &Vm, func: Func) -> SourceResult { - if func.argc().map_or(false, |count| count < 1 || count > 2) { + if func.argc().map_or(false, |count| !(1..=2).contains(&count)) { bail!(func.span(), "function must have one or two parameters"); } let enumerate = func.argc() == Some(2); diff --git a/src/model/eval.rs b/src/model/eval.rs index 0469649bc..b037a1bd7 100644 --- a/src/model/eval.rs +++ b/src/model/eval.rs @@ -567,7 +567,7 @@ impl Eval for ast::Ident { impl ast::Ident { fn eval_in_math(&self, vm: &mut Vm) -> SourceResult { if self.as_untyped().len() == self.len() - && matches!(vm.scopes.get(&self), Ok(Value::Func(_)) | Err(_)) + && matches!(vm.scopes.get(self), Ok(Value::Func(_)) | Err(_)) { Ok((vm.items.symbol)(EcoString::from(self.get()) + ":op".into())) } else { @@ -635,7 +635,7 @@ impl Eval for ast::Str { type Output = Value; fn eval(&self, _: &mut Vm) -> SourceResult { - Ok(Value::Str(self.get().clone().into())) + Ok(Value::Str(self.get().into())) } } @@ -1245,7 +1245,7 @@ impl Eval for ast::ModuleImport { errors.push(error!(ident.span(), "unresolved import")); } } - if errors.len() > 0 { + if !errors.is_empty() { return Err(Box::new(errors)); } } diff --git a/src/model/realize.rs b/src/model/realize.rs index 39c1fd422..b33cc0bbd 100644 --- a/src/model/realize.rs +++ b/src/model/realize.rs @@ -39,7 +39,7 @@ pub fn realize( for recipe in styles.recipes() { let guard = Guard::Nth(n); if recipe.applicable(target) && !target.is_guarded(guard) { - if let Some(content) = try_apply(vt, &target, recipe, guard)? { + if let Some(content) = try_apply(vt, target, recipe, guard)? { realized = Some(content); break; } @@ -92,13 +92,13 @@ fn try_apply( } Some(Selector::Regex(regex)) => { - let Some(text) = item!(text_str)(&target) else { + let Some(text) = item!(text_str)(target) else { return Ok(None); }; let make = |s| { let mut content = item!(text)(s); - content.copy_modifiers(&target); + content.copy_modifiers(target); content }; @@ -166,7 +166,7 @@ pub trait Finalize { } /// Guards content against being affected by the same show rule multiple times. -#[derive(Debug, Copy, Clone, PartialEq, Hash)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum Guard { /// The nth recipe from the top of the chain. Nth(usize), diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index 169b0276a..d70c4ae40 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -720,7 +720,7 @@ impl Ident { self.0.text().trim_start_matches('#') } - /// Take out the container identifier. + /// Take out the contained identifier. pub fn take(self) -> EcoString { let text = self.0.into_text(); match text.strip_prefix('#') { diff --git a/src/syntax/node.rs b/src/syntax/node.rs index 3465f73fd..038d13bcb 100644 --- a/src/syntax/node.rs +++ b/src/syntax/node.rs @@ -861,14 +861,12 @@ mod tests { // Find "text". let node = LinkedNode::new(source.root()).leaf_at(7).unwrap(); assert_eq!(node.offset(), 5); - assert_eq!(node.len(), 4); - assert_eq!(node.kind(), SyntaxKind::Ident); + assert_eq!(node.text(), "text"); // Go back to "#set". Skips the space. let prev = node.prev_sibling().unwrap(); assert_eq!(prev.offset(), 0); - assert_eq!(prev.len(), 4); - assert_eq!(prev.kind(), SyntaxKind::Set); + assert_eq!(prev.text(), "#set"); } #[test] @@ -876,15 +874,15 @@ mod tests { let source = Source::detached("#set fun(12pt, red)"); let leaf = LinkedNode::new(source.root()).leaf_at(6).unwrap(); let prev = leaf.prev_leaf().unwrap(); - assert_eq!(leaf.kind(), SyntaxKind::Ident); - assert_eq!(prev.kind(), SyntaxKind::Set); + assert_eq!(leaf.text(), "fun"); + assert_eq!(prev.text(), "#set"); let source = Source::detached("#let x = 10"); let leaf = LinkedNode::new(source.root()).leaf_at(9).unwrap(); let prev = leaf.prev_leaf().unwrap(); let next = leaf.next_leaf().unwrap(); - assert_eq!(prev.kind(), SyntaxKind::Eq); - assert_eq!(leaf.kind(), SyntaxKind::Space); - assert_eq!(next.kind(), SyntaxKind::Int); + assert_eq!(prev.text(), "="); + assert_eq!(leaf.text(), " "); + assert_eq!(next.text(), "10"); } } diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs index 0e1b52b1a..a379500c9 100644 --- a/src/syntax/parser.rs +++ b/src/syntax/parser.rs @@ -54,7 +54,7 @@ pub(super) fn reparse_markup( at_start: &mut bool, mut stop: impl FnMut(SyntaxKind) -> bool, ) -> Option> { - let mut p = Parser::new(&text, range.start, LexMode::Markup); + let mut p = Parser::new(text, range.start, LexMode::Markup); while !p.eof() && !stop(p.current) && p.current_start() < range.end { if p.newline() { *at_start = true; @@ -512,7 +512,7 @@ fn block(p: &mut Parser) { } pub(super) fn reparse_block(text: &str, range: Range) -> Option { - let mut p = Parser::new(&text, range.start, LexMode::Code); + let mut p = Parser::new(text, range.start, LexMode::Code); assert!(p.at(SyntaxKind::LeftBracket) || p.at(SyntaxKind::LeftBrace)); block(&mut p); (p.balanced && p.prev_end() == range.end) @@ -630,7 +630,7 @@ fn item(p: &mut Parser, keyed: bool) -> SyntaxKind { Some(SyntaxKind::Ident) => SyntaxKind::Named, Some(SyntaxKind::Str) if keyed => SyntaxKind::Keyed, _ => { - for child in p.post_process(m).next() { + for child in p.post_process(m) { if child.kind() == SyntaxKind::Colon { break; } diff --git a/src/syntax/reparser.rs b/src/syntax/reparser.rs index 9404055d8..40ac24228 100644 --- a/src/syntax/reparser.rs +++ b/src/syntax/reparser.rs @@ -96,7 +96,7 @@ fn try_reparse( // contained in things like headings or lists because too much can go wrong // with indent and line breaks. if node.kind() == SyntaxKind::Markup - && (parent_kind == None || parent_kind == Some(SyntaxKind::ContentBlock)) + && (parent_kind.is_none() || parent_kind == Some(SyntaxKind::ContentBlock)) && !overlap.is_empty() { // Add one node of slack in both directions. diff --git a/src/syntax/source.rs b/src/syntax/source.rs index 472e8c6ca..63509dc88 100644 --- a/src/syntax/source.rs +++ b/src/syntax/source.rs @@ -291,7 +291,7 @@ struct Line { /// Create a line vector. fn lines(text: &str) -> Vec { std::iter::once(Line { byte_idx: 0, utf16_idx: 0 }) - .chain(lines_from(0, 0, &text)) + .chain(lines_from(0, 0, text)) .collect() } diff --git a/tools/support/typst.tmLanguage.json b/tools/support/typst.tmLanguage.json index c849382e6..692fe652d 100644 --- a/tools/support/typst.tmLanguage.json +++ b/tools/support/typst.tmLanguage.json @@ -157,7 +157,7 @@ }, { "name": "keyword.other.typst", - "match": "(#)(as|in|from)\\b", + "match": "(#)(as|in)\\b", "captures": { "1": { "name": "punctuation.definition.keyword.typst" } } }, { @@ -257,7 +257,7 @@ }, { "name": "keyword.other.typst", - "match": "\\b(let|as|in|from|set|show)\\b" + "match": "\\b(let|as|in|set|show)\\b" }, { "name": "keyword.control.conditional.typst",