summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-10-07 19:28:34 +0200
committerLaurenz <laurmaedje@gmail.com>2020-10-07 19:28:34 +0200
commit13230db68c3cb2842f23f95fc1b47fd989e6277d (patch)
treeb0bf94a8e3f935a7e9076237783846dee14e3e81
parentd2e220245d9c17a0ac8c3474984924f65ed6b835 (diff)
Fix some clippy warnings ✔
-rw-r--r--src/eval/mod.rs7
-rw-r--r--src/eval/scope.rs4
-rw-r--r--src/eval/value.rs6
-rw-r--r--src/export/pdf.rs1
-rw-r--r--src/font.rs2
-rw-r--r--src/geom.rs8
-rw-r--r--src/layout/nodes/document.rs5
-rw-r--r--src/layout/nodes/mod.rs31
-rw-r--r--src/parse/tests.rs2
-rw-r--r--src/parse/tokens.rs2
-rw-r--r--src/syntax/ast/lit.rs4
11 files changed, 29 insertions, 43 deletions
diff --git a/src/eval/mod.rs b/src/eval/mod.rs
index c7d9c2a6..2c6f4d7c 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 fc530bbb..c0624393 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<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.
diff --git a/src/eval/value.rs b/src/eval/value.rs
index 8eea90df..c4b11ebe 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 ccbc01f1..02b54471 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 539f3188..9901ff1c 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 27cc87e9..90c7ac62 100644
--- a/src/geom.rs
+++ b/src/geom.rs
@@ -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,
}
}
}
diff --git a/src/layout/nodes/document.rs b/src/layout/nodes/document.rs
index af7a31e6..5c7a2410 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<BoxLayout> {
let mut layouts = vec![];
diff --git a/src/layout/nodes/mod.rs b/src/layout/nodes/mod.rs
index 44c18284..a304e63c 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<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())
- }
-}
diff --git a/src/parse/tests.rs b/src/parse/tests.rs
index 588ff765..d76c6dca 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 03dec6d7..2ff580b6 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 31566e89..4370345a 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<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()
}
}