mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Fix some clippy warnings ✔
This commit is contained in:
parent
d2e220245d
commit
13230db68c
@ -421,11 +421,10 @@ impl Eval for ExprUnary {
|
||||
type Output = Value;
|
||||
|
||||
fn eval(&self, ctx: &mut EvalContext) -> Self::Output {
|
||||
use Value::*;
|
||||
|
||||
let value = self.expr.v.eval(ctx);
|
||||
if value == Error {
|
||||
return Error;
|
||||
|
||||
if let Value::Error = value {
|
||||
return Value::Error;
|
||||
}
|
||||
|
||||
let span = self.op.span.join(self.expr.span);
|
||||
|
@ -6,7 +6,7 @@ use std::fmt::{self, Debug, Formatter};
|
||||
use super::value::ValueFunc;
|
||||
|
||||
/// A map from identifiers to functions.
|
||||
#[derive(Clone, PartialEq)]
|
||||
#[derive(Default, Clone, PartialEq)]
|
||||
pub struct Scope {
|
||||
functions: HashMap<String, ValueFunc>,
|
||||
}
|
||||
@ -15,7 +15,7 @@ impl Scope {
|
||||
// Create a new empty scope with a fallback function that is invoked when no
|
||||
// match is found.
|
||||
pub fn new() -> Self {
|
||||
Self { functions: HashMap::new() }
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Return the function with the given name if there is one.
|
||||
|
@ -157,11 +157,9 @@ impl ValueFunc {
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for ValueFunc {}
|
||||
|
||||
impl PartialEq for ValueFunc {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
Rc::ptr_eq(&self.0, &other.0)
|
||||
fn eq(&self, _: &Self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,6 +141,7 @@ impl<'a, W: Write> PdfExporter<'a, W> {
|
||||
for (pos, element) in &page.elements {
|
||||
match element {
|
||||
LayoutElement::Text(shaped) => {
|
||||
// Check if we need to issue a font switching action.
|
||||
if shaped.face != face || shaped.size != size {
|
||||
face = shaped.face;
|
||||
size = shaped.size;
|
||||
|
@ -23,7 +23,7 @@ pub struct OwnedFace {
|
||||
|
||||
impl OwnedFace {
|
||||
/// Get a reference to the underlying face.
|
||||
pub fn get<'a>(&'a self) -> &'a Face<'a> {
|
||||
pub fn get(&self) -> &Face<'_> {
|
||||
// We can't implement Deref because that would leak the internal 'static
|
||||
// lifetime.
|
||||
&self.face
|
||||
|
@ -178,8 +178,8 @@ impl Mul<f64> for Linear {
|
||||
|
||||
fn mul(self, other: f64) -> Self {
|
||||
Self {
|
||||
rel: self.rel + other,
|
||||
abs: self.abs + other,
|
||||
rel: self.rel * other,
|
||||
abs: self.abs * other,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -196,8 +196,8 @@ impl Mul<Linear> for f64 {
|
||||
|
||||
fn mul(self, other: Linear) -> Linear {
|
||||
Linear {
|
||||
rel: self + other.rel,
|
||||
abs: self + other.abs,
|
||||
rel: self * other.rel,
|
||||
abs: self * other.abs,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,6 @@ pub struct Document {
|
||||
}
|
||||
|
||||
impl Document {
|
||||
/// Create a new document.
|
||||
pub fn new() -> Self {
|
||||
Self { runs: vec![] }
|
||||
}
|
||||
|
||||
/// Layout the document.
|
||||
pub async fn layout(&self, ctx: &mut LayoutContext) -> Vec<BoxLayout> {
|
||||
let mut layouts = vec![];
|
||||
|
@ -75,7 +75,6 @@ impl Layout for LayoutNode {
|
||||
///
|
||||
/// [`LayoutNode`]: enum.LayoutNode.html
|
||||
/// [Rust Issue]: https://github.com/rust-lang/rust/issues/31740
|
||||
#[derive(Clone)]
|
||||
pub struct Dynamic(pub Box<dyn DynNode>);
|
||||
|
||||
impl Dynamic {
|
||||
@ -85,12 +84,6 @@ impl Dynamic {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Dynamic {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
&self.0 == &other.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Dynamic {
|
||||
type Target = dyn DynNode;
|
||||
|
||||
@ -105,6 +98,18 @@ impl Debug for Dynamic {
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Dynamic {
|
||||
fn clone(&self) -> Self {
|
||||
Self(self.0.dyn_clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Dynamic {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0.dyn_eq(other.0.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Dynamic> for LayoutNode {
|
||||
fn from(dynamic: Dynamic) -> Self {
|
||||
Self::Dyn(dynamic)
|
||||
@ -153,15 +158,3 @@ where
|
||||
Box::new(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Box<dyn DynNode> {
|
||||
fn clone(&self) -> Self {
|
||||
self.dyn_clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Box<dyn DynNode> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.dyn_eq(other.as_ref())
|
||||
}
|
||||
}
|
||||
|
@ -409,7 +409,7 @@ fn test_parse_values() {
|
||||
v!("true" => Bool(true));
|
||||
v!("false" => Bool(false));
|
||||
v!("1.0e-4" => Float(1e-4));
|
||||
v!("3.14" => Float(3.14));
|
||||
v!("3.15" => Float(3.15));
|
||||
v!("50%" => Percent(50.0));
|
||||
v!("4.5cm" => Len(Length::cm(4.5)));
|
||||
v!("12e1pt" => Len(Length::pt(12e1)));
|
||||
|
@ -431,7 +431,7 @@ mod tests {
|
||||
t!(Header, "(1,2)" => LP, Int(1), Comma, Int(2), RP);
|
||||
t!(Header, "12_pt, 12pt" => Invalid("12_pt"), Comma, S(0), Len(Length::pt(12.0)));
|
||||
t!(Header, "f: arg >> g" => Id("f"), Colon, S(0), Id("arg"), S(0), Chain, S(0), Id("g"));
|
||||
t!(Header, "=3.14" => Equals, Float(3.14));
|
||||
t!(Header, "=3.15" => Equals, Float(3.15));
|
||||
t!(Header, "arg, _b, _1" => Id("arg"), Comma, S(0), Id("_b"), Comma, S(0), Id("_1"));
|
||||
t!(Header, "a:b" => Id("a"), Colon, Id("b"));
|
||||
t!(Header, "(){}:=," => LP, RP, LB, RB, Colon, Equals, Comma);
|
||||
|
@ -36,7 +36,7 @@ pub enum Lit {
|
||||
}
|
||||
|
||||
/// A dictionary literal: `(false, 12cm, greeting = "hi")`.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
pub struct LitDict(pub Vec<LitDictEntry>);
|
||||
|
||||
/// An entry in a dictionary literal: `false` or `greeting = "hi"`.
|
||||
@ -51,6 +51,6 @@ pub struct LitDictEntry {
|
||||
impl LitDict {
|
||||
/// Create an empty dict literal.
|
||||
pub fn new() -> Self {
|
||||
Self(vec![])
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user