From d10b53df0b487036b0d639b6033f4568648cfff1 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 18 Apr 2023 19:10:55 +0200 Subject: [PATCH] Clippy --- .github/workflows/ci.yml | 3 ++- docs/src/html.rs | 6 +++--- docs/src/lib.rs | 6 +++--- library/src/lib.rs | 3 ++- src/eval/func.rs | 4 ++-- src/eval/module.rs | 2 +- src/eval/value.rs | 4 ++-- src/lib.rs | 2 +- src/model/content.rs | 2 +- tests/src/benches.rs | 6 +++--- tests/src/tests.rs | 16 +++++++++------- 11 files changed, 29 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 66af6d69d..0eb493ec8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,7 @@ jobs: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - - run: cargo fmt --check + - run: cargo fmt --check --all + - run: cargo clippy --workspace --all-targets - run: cargo build --workspace - run: cargo test --workspace --no-fail-fast diff --git a/docs/src/html.rs b/docs/src/html.rs index 8778fbafb..b189a09c5 100644 --- a/docs/src/html.rs +++ b/docs/src/html.rs @@ -33,7 +33,7 @@ impl Html { pub fn markdown(resolver: &dyn Resolver, md: &str) -> Self { let mut text = md; let mut description = None; - let document = YamlFrontMatter::parse::(&md); + let document = YamlFrontMatter::parse::(md); if let Ok(document) = &document { text = &document.content; description = Some(document.metadata.description.clone()) @@ -43,7 +43,7 @@ impl Html { let mut handler = Handler::new(resolver); let iter = md::Parser::new_ext(text, options) - .filter_map(|mut event| handler.handle(&mut event).then(|| event)); + .filter_map(|mut event| handler.handle(&mut event).then_some(event)); let mut raw = String::new(); md::html::push_html(&mut raw, iter); @@ -169,7 +169,7 @@ impl<'a> Handler<'a> { fn handle_image(&self, link: &str) -> String { if let Some(file) = FILES.get_file(link) { - self.resolver.image(&link, file.contents()).into() + self.resolver.image(link, file.contents()) } else if let Some(url) = self.resolver.link(link) { url } else { diff --git a/docs/src/lib.rs b/docs/src/lib.rs index 92ff69f0e..4a20a008b 100644 --- a/docs/src/lib.rs +++ b/docs/src/lib.rs @@ -229,7 +229,7 @@ fn category_page(resolver: &dyn Resolver, category: &str) -> PageModel { for group in grouped { let mut functions = vec![]; for name in &group.functions { - let value = focus.get(&name).unwrap(); + let value = focus.get(name).unwrap(); let Value::Func(func) = value else { panic!("not a function") }; let info = func.info().unwrap(); functions.push(func_model(resolver, func, info)); @@ -335,7 +335,7 @@ fn func_model(resolver: &dyn Resolver, func: &Func, info: &FuncInfo) -> FuncMode let mut s = unscanny::Scanner::new(info.docs); let docs = s.eat_until("\n## Methods").trim(); FuncModel { - name: info.name.into(), + name: info.name, display: info.display, oneliner: oneliner(docs), showable: func.element().is_some(), @@ -721,7 +721,7 @@ pub fn urlify(title: &str) -> String { /// Extract the first line of documentation. fn oneliner(docs: &str) -> &str { - docs.lines().next().unwrap_or_default().into() + docs.lines().next().unwrap_or_default() } /// The order of types in the documentation. diff --git a/library/src/lib.rs b/library/src/lib.rs index fa8cec80c..3254dfd89 100644 --- a/library/src/lib.rs +++ b/library/src/lib.rs @@ -1,6 +1,7 @@ +//! Typst's standard library. + #![allow(clippy::wildcard_in_or_patterns)] #![allow(clippy::comparison_chain)] -//! Typst's standard library. pub mod compute; pub mod layout; diff --git a/src/eval/func.rs b/src/eval/func.rs index 582eabd4f..faf2d696c 100644 --- a/src/eval/func.rs +++ b/src/eval/func.rs @@ -17,8 +17,8 @@ use crate::syntax::{SourceId, Span, SyntaxNode}; use crate::World; /// An evaluatable function. -#[allow(clippy::derived_hash_with_manual_eq)] #[derive(Clone, Hash)] +#[allow(clippy::derived_hash_with_manual_eq)] pub struct Func { /// The internal representation. repr: Repr, @@ -278,8 +278,8 @@ pub enum Param { impl Closure { /// Call the function in the context with the arguments. - #[allow(clippy::too_many_arguments)] #[comemo::memoize] + #[allow(clippy::too_many_arguments)] fn call( this: &Func, world: Tracked, diff --git a/src/eval/module.rs b/src/eval/module.rs index 350252706..fbfdd4e60 100644 --- a/src/eval/module.rs +++ b/src/eval/module.rs @@ -7,8 +7,8 @@ use super::{Content, Scope, Value}; use crate::diag::StrResult; /// An evaluated module, ready for importing or typesetting. -#[allow(clippy::derived_hash_with_manual_eq)] #[derive(Clone, Hash)] +#[allow(clippy::derived_hash_with_manual_eq)] pub struct Module(Arc); /// The internal representation. diff --git a/src/eval/value.rs b/src/eval/value.rs index 3fd9ed422..53db169ca 100644 --- a/src/eval/value.rs +++ b/src/eval/value.rs @@ -241,8 +241,8 @@ impl Hash for Value { } /// A dynamic value. -#[allow(clippy::derived_hash_with_manual_eq)] #[derive(Clone, Hash)] +#[allow(clippy::derived_hash_with_manual_eq)] pub struct Dynamic(Arc); impl Dynamic { @@ -426,7 +426,7 @@ mod tests { test(Value::None, "none"); test(false, "false"); test(12i64, "12"); - test(3.14, "3.14"); + test(3.24, "3.24"); test(Abs::pt(5.5), "5.5pt"); test(Angle::deg(90.0), "90deg"); test(Ratio::one() / 2.0, "50%"); diff --git a/src/lib.rs b/src/lib.rs index 744013cee..53887a498 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -#![allow(clippy::comparison_chain)] //! The compiler for the _Typst_ markup language. //! //! # Steps @@ -34,6 +33,7 @@ //! [raster images]: export::render #![recursion_limit = "1000"] +#![allow(clippy::comparison_chain)] extern crate self as typst; diff --git a/src/model/content.rs b/src/model/content.rs index 4300790cd..619793ecb 100644 --- a/src/model/content.rs +++ b/src/model/content.rs @@ -17,8 +17,8 @@ use crate::syntax::Span; use crate::util::pretty_array_like; /// Composable representation of styled content. -#[allow(clippy::derived_hash_with_manual_eq)] #[derive(Clone, Hash)] +#[allow(clippy::derived_hash_with_manual_eq)] pub struct Content { func: ElemFunc, attrs: EcoVec, diff --git a/tests/src/benches.rs b/tests/src/benches.rs index b1e77692e..9e9b98d07 100644 --- a/tests/src/benches.rs +++ b/tests/src/benches.rs @@ -30,8 +30,8 @@ fn bench_decode(iai: &mut Iai) { // We don't use chars().count() because that has a special // superfast implementation. let mut count = 0; - let mut chars = black_box(TEXT).chars(); - while let Some(_) = chars.next() { + let chars = black_box(TEXT).chars(); + for _ in chars { count += 1; } count @@ -42,7 +42,7 @@ fn bench_scan(iai: &mut Iai) { iai.run(|| { let mut count = 0; let mut scanner = Scanner::new(black_box(TEXT)); - while let Some(_) = scanner.eat() { + while scanner.eat().is_some() { count += 1; } count diff --git a/tests/src/tests.rs b/tests/src/tests.rs index fef8c0cf5..46bf343c4 100644 --- a/tests/src/tests.rs +++ b/tests/src/tests.rs @@ -1,3 +1,5 @@ +#![allow(clippy::comparison_chain)] + use std::cell::{RefCell, RefMut}; use std::collections::HashMap; use std::env; @@ -324,10 +326,10 @@ fn read(path: &Path) -> FileResult> { .unwrap_or_else(|_| path.into()); let f = |e| FileError::from_io(e, &suffix); - if fs::metadata(&path).map_err(f)?.is_dir() { + if fs::metadata(path).map_err(f)?.is_dir() { Err(FileError::IsDirectory) } else { - fs::read(&path).map_err(f) + fs::read(path).map_err(f) } } @@ -379,7 +381,7 @@ fn test( if compare_ever { if let Some(pdf_path) = pdf_path { let pdf_data = typst::export::pdf(&document); - fs::create_dir_all(&pdf_path.parent().unwrap()).unwrap(); + fs::create_dir_all(pdf_path.parent().unwrap()).unwrap(); fs::write(pdf_path, pdf_data).unwrap(); } @@ -390,7 +392,7 @@ fn test( } let canvas = render(&document.pages); - fs::create_dir_all(&png_path.parent().unwrap()).unwrap(); + fs::create_dir_all(png_path.parent().unwrap()).unwrap(); canvas.save_png(png_path).unwrap(); if let Ok(ref_pixmap) = sk::Pixmap::load_png(ref_path) { @@ -438,7 +440,7 @@ fn test_part( println!("Syntax Tree:\n{:#?}\n", source.root()) } - let (local_compare_ref, mut ref_errors) = parse_metadata(&source); + let (local_compare_ref, mut ref_errors) = parse_metadata(source); let compare_ref = local_compare_ref.unwrap_or(compare_ref); ok &= test_spans(source.root()); @@ -482,14 +484,14 @@ fn test_part( for error in errors.iter() { if !ref_errors.contains(error) { print!(" Not annotated | "); - print_error(&source, line, error); + print_error(source, line, error); } } for error in ref_errors.iter() { if !errors.contains(error) { print!(" Not emitted | "); - print_error(&source, line, error); + print_error(source, line, error); } } }