Fix a few clippy lints

This commit is contained in:
Laurenz 2023-01-20 14:14:13 +01:00
parent dd331f007c
commit b73b4f33bc
16 changed files with 40 additions and 39 deletions

View File

@ -44,7 +44,7 @@ pub fn func(item: syn::Item) -> Result<TokenStream> {
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<String> {
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;

View File

@ -220,7 +220,7 @@ fn create(node: &Node) -> Result<TokenStream> {
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;

View File

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

View File

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

View File

@ -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<Arc<sk::Pixmap>> {
}
DecodedImage::Svg(tree) => {
resvg::render(
&tree,
tree,
FitTo::Size(w, h),
sk::Transform::identity(),
pixmap.as_mut(),

View File

@ -26,7 +26,7 @@ fn function_tooltip(world: &dyn World, leaf: &LinkedNode) -> Option<String> {
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));
}
}

View File

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

View File

@ -183,7 +183,7 @@ impl Array {
/// Transform each item in the array with a function.
pub fn map(&self, vm: &Vm, func: Func) -> SourceResult<Self> {
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);

View File

@ -567,7 +567,7 @@ impl Eval for ast::Ident {
impl ast::Ident {
fn eval_in_math(&self, vm: &mut Vm) -> SourceResult<Content> {
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<Self::Output> {
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));
}
}

View File

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

View File

@ -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('#') {

View File

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

View File

@ -54,7 +54,7 @@ pub(super) fn reparse_markup(
at_start: &mut bool,
mut stop: impl FnMut(SyntaxKind) -> bool,
) -> Option<Vec<SyntaxNode>> {
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<usize>) -> Option<SyntaxNode> {
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;
}

View File

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

View File

@ -291,7 +291,7 @@ struct Line {
/// Create a line vector.
fn lines(text: &str) -> Vec<Line> {
std::iter::once(Line { byte_idx: 0, utf16_idx: 0 })
.chain(lines_from(0, 0, &text))
.chain(lines_from(0, 0, text))
.collect()
}

View File

@ -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",