Clippy
This commit is contained in:
parent
35302d2004
commit
d10b53df0b
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@ -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
|
||||
|
@ -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::<Metadata>(&md);
|
||||
let document = YamlFrontMatter::parse::<Metadata>(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 {
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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<dyn World>,
|
||||
|
@ -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<Repr>);
|
||||
|
||||
/// The internal representation.
|
||||
|
@ -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<dyn Bounds>);
|
||||
|
||||
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%");
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<Attr>,
|
||||
|
@ -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
|
||||
|
@ -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<Vec<u8>> {
|
||||
.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user