[snowpatch] [PATCH] Fix various clippy and fmt issues

Andrew Donnellan ajd at linux.ibm.com
Thu Jun 6 13:17:05 AEST 2019


Signed-off-by: Andrew Donnellan <ajd at linux.ibm.com>

---

already applied

---
 src/git.rs       |  3 +--
 src/jenkins.rs   | 28 +++++++++++++++++-----------
 src/main.rs      | 24 ++++++++++++++++++------
 src/patchwork.rs |  7 +++----
 4 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/src/git.rs b/src/git.rs
index d025d0388816..ad4bb781d23b 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -68,7 +68,7 @@ pub fn pull(repo: &Repository) -> Result<Output, &'static str> {
     }
 }
 
-pub fn checkout_branch(repo: &Repository, branch: &str) -> () {
+pub fn checkout_branch(repo: &Repository, branch: &str) {
     let workdir = repo.workdir().unwrap(); // TODO: support bare repositories
 
     // Make sure there's no junk lying around before we switch
@@ -107,7 +107,6 @@ pub fn checkout_branch(repo: &Repository, branch: &str) -> () {
         .current_dir(&workdir)
         .output()
         .unwrap();
-    ()
 }
 
 pub fn apply_patch(repo: &Repository, path: &Path) -> Result<Output, &'static str> {
diff --git a/src/jenkins.rs b/src/jenkins.rs
index 3cb4f6f9a17b..b367e0db3a7a 100644
--- a/src/jenkins.rs
+++ b/src/jenkins.rs
@@ -118,10 +118,13 @@ impl CIBackend for JenkinsBackend {
             Some(artifact) => {
                 let artifact_url = format!("{}/artifact/{}", build_handle, artifact);
                 match self.get_url(&artifact_url) {
-                    Ok(resp) => match resp.status().is_success() {
-                        true => artifact_url,
-                        false => default_url,
-                    },
+                    Ok(resp) => {
+                        if resp.status().is_success() {
+                            artifact_url
+                        } else {
+                            default_url
+                        }
+                    }
                     Err(_e) => default_url,
                 }
             }
@@ -137,13 +140,16 @@ impl CIBackend for JenkinsBackend {
         match job.get("description") {
             Some(artifact) => {
                 match self.get_url(&format!("{}/artifact/{}", build_handle, artifact)) {
-                    Ok(mut resp) => match resp.status().is_success() {
-                        true => match resp.text() {
-                            Ok(text) => Some(text),
-                            Err(_e) => None,
-                        },
-                        false => None,
-                    },
+                    Ok(mut resp) => {
+                        if resp.status().is_success() {
+                            match resp.text() {
+                                Ok(text) => Some(text),
+                                Err(_e) => None,
+                            }
+                        } else {
+                            None
+                        }
+                    }
                     Err(_e) => None,
                 }
             }
diff --git a/src/main.rs b/src/main.rs
index ba8c54d792d9..48a09afa2d42 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -118,10 +118,9 @@ fn run_test(
     }
     params.push((&job.remote, &project.remote_uri));
     params.push((&job.branch, tag));
-    match job.base {
-        Some(ref base_param) => params.push((&base_param, base)),
-        _ => { }
-    };
+    if let Some(ref base_param) = job.base {
+        params.push((&base_param, base));
+    }
 
     info!("Starting job: {}", &job.title);
     let res = backend
@@ -288,7 +287,17 @@ fn test_patch(
         // We've set up a remote branch, time to kick off tests
         let test = thread::Builder::new()
             .name(tag.to_string())
-            .spawn(move || run_tests(&settings, client, &project, &tag, &branch_name, &base, hefty_tests))
+            .spawn(move || {
+                run_tests(
+                    &settings,
+                    client,
+                    &project,
+                    &tag,
+                    &branch_name,
+                    &base,
+                    hefty_tests,
+                )
+            })
             .unwrap();
         results.append(&mut test.join().unwrap());
 
@@ -311,7 +320,10 @@ fn test_patch(
     results
 }
 
-#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))]
+#[cfg_attr(
+    feature = "cargo-clippy",
+    allow(clippy::cyclomatic_complexity, clippy::cognitive_complexity)
+)]
 fn run() -> Result<(), Box<Error>> {
     let mut log_builder = Builder::new();
     // By default, log at the "info" level for every module
diff --git a/src/patchwork.rs b/src/patchwork.rs
index e560b666b00d..46bed953d9a9 100644
--- a/src/patchwork.rs
+++ b/src/patchwork.rs
@@ -210,8 +210,7 @@ pub struct PatchworkServer {
 }
 
 impl PatchworkServer {
-    #[cfg_attr(feature = "cargo-clippy", allow(ptr_arg))]
-    pub fn new(url: &String, client: &std::sync::Arc<Client>) -> PatchworkServer {
+    pub fn new(url: &str, client: &std::sync::Arc<Client>) -> PatchworkServer {
         let mut headers = HeaderMap::new();
         // These .parse().unwrap() blocks are making sure it's a valid ASCII
         // header value.  They don't need to be refactored and hopefully in
@@ -219,13 +218,13 @@ impl PatchworkServer {
         headers.insert(ACCEPT, "application/json".parse().unwrap());
         headers.insert(CONTENT_TYPE, "application/json".parse().unwrap());
         PatchworkServer {
-            url: url.clone(),
+            url: url.to_string(),
             client: client.clone(),
             headers,
         }
     }
 
-    #[cfg_attr(feature = "cargo-clippy", allow(ptr_arg))]
+    #[cfg_attr(feature = "cargo-clippy", allow(clippy::ptr_arg))]
     pub fn set_authentication(
         &mut self,
         username: &Option<String>,
-- 
2.20.1



More information about the snowpatch mailing list