[librsvg: 6/12] Clear len_zero, match_bool, singel_match warnings.



commit 341f68559ce926347320ca4cff40b4d9b1b64632
Author: Jordan Petridis <jordanpetridis protonmail com>
Date:   Sun Dec 17 10:28:54 2017 +0200

    Clear len_zero, match_bool, singel_match warnings.
    
    For more see:
    https://rust-lang-nursery.github.io/rust-clippy/v0.0.176/index.html#len_zero
    https://rust-lang-nursery.github.io/rust-clippy/v0.0.176/index.html#match_bool
    https://rust-lang-nursery.github.io/rust-clippy/v0.0.176/index.html#single_match

 rust/src/gradient.rs    |  2 +-
 rust/src/image.rs       |  9 ++-------
 rust/src/lib.rs         |  1 +
 rust/src/marker.rs      | 48 ++++++++++++++++--------------------------------
 rust/src/path_parser.rs |  7 ++++---
 5 files changed, 24 insertions(+), 43 deletions(-)
---
diff --git a/rust/src/gradient.rs b/rust/src/gradient.rs
index 82625e5..d46663c 100644
--- a/rust/src/gradient.rs
+++ b/rust/src/gradient.rs
@@ -146,7 +146,7 @@ impl GradientCommon {
         if let Some (ref mut stops) = self.stops {
             let mut last_offset: f64 = 0.0;
 
-            if stops.len () > 0 {
+            if !stops.is_empty() {
                 last_offset = stops[stops.len () - 1].offset;
             }
 
diff --git a/rust/src/image.rs b/rust/src/image.rs
index c584d58..514c7fa 100644
--- a/rust/src/image.rs
+++ b/rust/src/image.rs
@@ -93,13 +93,8 @@ impl NodeTrait for NodeImage {
             let aspect = self.aspect.get();
 
             if !drawing_ctx::state_is_overflow(state) {
-                match aspect.align {
-                    Align::Aligned { align: _,
-                                     fit: FitMode::Slice } => {
-                        drawing_ctx::add_clipping_rect(draw_ctx, x, y, w, h);
-                    },
-
-                    _ => ()
+                if let Align::Aligned {fit: FitMode::Slice, ..} = aspect.align {
+                    drawing_ctx::add_clipping_rect(draw_ctx, x, y, w, h);
                 }
             }
 
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 8451d1a..f18235b 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -177,6 +177,7 @@ mod mask;
 mod node;
 mod opacity;
 mod paint_server;
+#[cfg_attr(feature = "cargo-clippy", allow(clippy))]
 mod parse_transform;
 mod parsers;
 mod path_builder;
diff --git a/rust/src/marker.rs b/rust/src/marker.rs
index 5b8b35e..1087775 100644
--- a/rust/src/marker.rs
+++ b/rust/src/marker.rs
@@ -381,17 +381,9 @@ pub fn path_builder_to_segments (builder: &RsvgPathBuilder) -> Vec<Segment> {
         }
     }
 
-    match state {
-        SegmentState::NewSubpath => {
-            /* Output a lone point if we started a subpath with a
-             * moveto command, but there are no subsequent commands.
-             */
-            segments.push (make_degenerate (cur_x, cur_y));
-        },
-
-        _ => {
-        }
-    }
+    if let SegmentState::NewSubpath = state {
+        segments.push (make_degenerate (cur_x, cur_y));
+    };
 
     segments
 }
@@ -672,21 +664,17 @@ fn emit_markers_for_path_builder<E> (builder: &RsvgPathBuilder,
     for (i, segment) in segments.iter ().enumerate () {
         match *segment {
             Segment::Degenerate { .. } => {
-                match subpath_state {
-                    SubpathState::InSubpath => {
-                        assert! (i > 0);
+                if let SubpathState::InSubpath = subpath_state {
+                    assert! (i > 0);
 
-                        /* Got a lone point after a subpath; render the subpath's end marker first */
+                    /* Got a lone point after a subpath; render the subpath's end marker first */
 
-                        let (_, incoming_vx, incoming_vy) = find_incoming_directionality_backwards 
(&segments, i - 1);
-                        emit_marker (&segments[i - 1],
-                                     MarkerEndpoint::End,
-                                     MarkerType::End,
-                                     angle_from_vector (incoming_vx, incoming_vy),
-                                     emit_fn);
-                    },
-
-                    _ => { }
+                    let (_, incoming_vx, incoming_vy) = find_incoming_directionality_backwards (&segments, i 
- 1);
+                    emit_marker (&segments[i - 1],
+                                    MarkerEndpoint::End,
+                                    MarkerType::End,
+                                    angle_from_vector (incoming_vx, incoming_vy),
+                                    emit_fn);
                 }
 
                 /* Render marker for the lone point; no directionality */
@@ -743,16 +731,12 @@ fn emit_markers_for_path_builder<E> (builder: &RsvgPathBuilder,
 
     /* Finally, render the last point */
 
-    if segments.len() > 0 {
+    if !segments.is_empty() {
         let segment = &segments[segments.len() - 1];
-        match *segment {
-            Segment::LineOrCurve { .. } => {
-                let (_, incoming_vx, incoming_vy) = find_incoming_directionality_backwards (&segments, 
segments.len () - 1);
-
-                emit_marker (segment, MarkerEndpoint::End, MarkerType::End, angle_from_vector (incoming_vx, 
incoming_vy), emit_fn);
-            },
+        if let Segment::LineOrCurve{ .. } = *segment {
+            let (_, incoming_vx, incoming_vy) = find_incoming_directionality_backwards (&segments, 
segments.len () - 1);
 
-            _ => { }
+            emit_marker (segment, MarkerEndpoint::End, MarkerType::End, angle_from_vector (incoming_vx, 
incoming_vy), emit_fn);
         }
     }
 }
diff --git a/rust/src/path_parser.rs b/rust/src/path_parser.rs
index f8eaffd..1a71d2a 100644
--- a/rust/src/path_parser.rs
+++ b/rust/src/path_parser.rs
@@ -905,9 +905,10 @@ impl<'b> PathParser<'b> {
                             if let Some (sweep_flag) = self.flag () {
                                 assert! (self.optional_comma_whitespace ());
 
-                                let sweep = match sweep_flag {
-                                    false => Sweep::Negative,
-                                    true => Sweep::Positive
+                                let sweep = if sweep_flag {
+                                    Sweep::Positive
+                                } else {
+                                    Sweep::Negative
                                 };
 
                                 if let Some ((mut x, mut y)) = self.coordinate_pair () {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]