diff --git a/src/eval/mod.rs b/src/eval/mod.rs index c7d9c2a62..2c6f4d7cf 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -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); diff --git a/src/eval/scope.rs b/src/eval/scope.rs index fc530bbb9..c06243937 100644 --- a/src/eval/scope.rs +++ b/src/eval/scope.rs @@ -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, } @@ -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. diff --git a/src/eval/value.rs b/src/eval/value.rs index 8eea90dff..c4b11ebe2 100644 --- a/src/eval/value.rs +++ b/src/eval/value.rs @@ -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 } } diff --git a/src/export/pdf.rs b/src/export/pdf.rs index ccbc01f15..02b544717 100644 --- a/src/export/pdf.rs +++ b/src/export/pdf.rs @@ -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; diff --git a/src/font.rs b/src/font.rs index 539f3188e..9901ff1c8 100644 --- a/src/font.rs +++ b/src/font.rs @@ -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 diff --git a/src/geom.rs b/src/geom.rs index 27cc87e9e..90c7ac622 100644 --- a/src/geom.rs +++ b/src/geom.rs @@ -178,8 +178,8 @@ impl Mul 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 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, } } } diff --git a/src/layout/nodes/document.rs b/src/layout/nodes/document.rs index af7a31e6d..5c7a24109 100644 --- a/src/layout/nodes/document.rs +++ b/src/layout/nodes/document.rs @@ -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 { let mut layouts = vec![]; diff --git a/src/layout/nodes/mod.rs b/src/layout/nodes/mod.rs index 44c182849..a304e63c6 100644 --- a/src/layout/nodes/mod.rs +++ b/src/layout/nodes/mod.rs @@ -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); 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 for LayoutNode { fn from(dynamic: Dynamic) -> Self { Self::Dyn(dynamic) @@ -153,15 +158,3 @@ where Box::new(self.clone()) } } - -impl Clone for Box { - fn clone(&self) -> Self { - self.dyn_clone() - } -} - -impl PartialEq for Box { - fn eq(&self, other: &Self) -> bool { - self.dyn_eq(other.as_ref()) - } -} diff --git a/src/parse/tests.rs b/src/parse/tests.rs index 588ff7654..d76c6dcac 100644 --- a/src/parse/tests.rs +++ b/src/parse/tests.rs @@ -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))); diff --git a/src/parse/tokens.rs b/src/parse/tokens.rs index 03dec6d7c..2ff580b6c 100644 --- a/src/parse/tokens.rs +++ b/src/parse/tokens.rs @@ -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); diff --git a/src/syntax/ast/lit.rs b/src/syntax/ast/lit.rs index 31566e896..4370345aa 100644 --- a/src/syntax/ast/lit.rs +++ b/src/syntax/ast/lit.rs @@ -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); /// 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() } }