Fix clippy warnings
diff mbox series

Message ID 20180810080455.30462-1-andrew.donnellan@au1.ibm.com
State Accepted
Headers show
Series
  • Fix clippy warnings
Related show

Commit Message

Andrew Donnellan Aug. 10, 2018, 8:04 a.m. UTC
Fix a whole bunch of clippy warnings.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
---
 src/main.rs      | 48 ++++++++++++++++++++++--------------------------
 src/patchwork.rs | 22 +++++++++++++---------
 src/settings.rs  | 21 +++++++++------------
 src/utils.rs     |  2 +-
 4 files changed, 45 insertions(+), 48 deletions(-)

Patch
diff mbox series

diff --git a/src/main.rs b/src/main.rs
index ba9e6dba1371..7a0debaebec4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -118,7 +118,7 @@  fn run_tests(
             continue;
         }
         let mut jenkins_params = Vec::<(&str, &str)>::new();
-        for (param_name, param_value) in job.parameters.iter() {
+        for (param_name, param_value) in &job.parameters {
             // TODO(ajd): do this more neatly
             debug!("Param name {}, value {}", &param_name, &param_value);
             jenkins_params.push((param_name, param_value));
@@ -151,7 +151,7 @@  fn run_tests(
                 format!("Test {} on branch {}", job.title, branch_name.to_string()).to_string(),
             ),
             state: test_result,
-            context: Some(format!("{}", job.title.replace("/", "_")).to_string()),
+            context: Some(job.title.replace("/", "_")),
             target_url: Some(jenkins.get_results_url(&build_url_real, &job.parameters)),
         });
     }
@@ -170,7 +170,7 @@  fn test_patch(
     if !path.is_file() {
         return results;
     }
-    let tag = utils::sanitise_path(path.file_name().unwrap().to_str().unwrap().to_string());
+    let tag = utils::sanitise_path(path.file_name().unwrap().to_str().unwrap());
     let mut remote = repo.find_remote(&project.remote_name).unwrap();
 
     let mut push_callbacks = RemoteCallbacks::new();
@@ -318,18 +318,16 @@  fn main() {
             let proxy = Proxy::all(&proxy_url).unwrap_or_else(|e| {
                 panic!("Couldn't set proxy: {:?}, error: {}", proxy_url, e);
             });
-            let mut c = Client::builder().proxy(proxy).build().unwrap_or_else(|e| {
+            Client::builder().proxy(proxy).build().unwrap_or_else(|e| {
                 panic!(
                     "Couldn't create client with proxy: {:?}, error: {}",
                     proxy_url, e
                 );
-            });
-            c
+            })
         }
         _ => {
             debug!("snowpatch starting without a HTTP proxy");
-            let mut c = Client::new();
-            c
+            Client::new()
         }
     });
 
@@ -347,7 +345,7 @@  fn main() {
 
     if args.flag_patch > 0 {
         info!("snowpatch is testing a patch from Patchwork.");
-        let patch = patchwork.get_patch(&(args.flag_patch as u64)).unwrap();
+        let patch = patchwork.get_patch(u64::from(args.flag_patch)).unwrap();
         match settings.projects.get(&patch.project.link_name) {
             None => panic!("Couldn't find project {}", &patch.project.link_name),
             Some(project) => {
@@ -357,7 +355,7 @@  fn main() {
                 } else {
                     patchwork.get_patch_mbox(&patch)
                 };
-                test_patch(&settings, &client, project, &mbox, true);
+                test_patch(&settings, &client, &project, &mbox, true);
             }
         }
         return;
@@ -365,7 +363,7 @@  fn main() {
 
     if args.flag_series > 0 {
         info!("snowpatch is testing a series from Patchwork.");
-        let series = patchwork.get_series(&(args.flag_series as u64)).unwrap();
+        let series = patchwork.get_series(u64::from(args.flag_series)).unwrap();
         // The last patch in the series, so its dependencies are the whole series
         let patch = patchwork
             .get_patch_by_url(&series.patches.last().unwrap().url)
@@ -375,14 +373,14 @@  fn main() {
             Some(project) => {
                 let dependencies = patchwork.get_patch_dependencies(&patch);
                 let mbox = patchwork.get_patches_mbox(dependencies);
-                let results = test_patch(&settings, &client, project, &mbox, true);
+                let results = test_patch(&settings, &client, &project, &mbox, true);
 
                 // Delete the temporary directory with the patch in it
                 fs::remove_dir_all(mbox.parent().unwrap())
                     .unwrap_or_else(|err| error!("Couldn't delete temp directory: {}", err));
                 if project.push_results {
                     for result in results {
-                        patchwork.post_test_result(result, &patch.checks).unwrap();
+                        patchwork.post_test_result(&result, &patch.checks).unwrap();
                     }
                 }
             }
@@ -391,12 +389,12 @@  fn main() {
     }
 
     // At this point, specifying a project is required
-    let project = settings.projects.get(&args.flag_project).unwrap();
+    let project = &settings.projects[&args.flag_project];
 
     if args.flag_mbox != "" {
         info!("snowpatch is testing a local patch.");
         let patch = Path::new(&args.flag_mbox);
-        test_patch(&settings, &client, project, patch, true);
+        test_patch(&settings, &client, &project, patch, true);
 
         return;
     }
@@ -407,20 +405,18 @@  fn main() {
      * If the patch is part of a series, apply all of its dependencies.
      * Spawn tests.
      */
-    'daemon: loop {
-        let patch_list;
-
+    loop {
         // TODO: This is hacky and we should refactor out daemon vs patch/count
         // mode
-        if args.flag_count > 0 {
-            patch_list = patchwork
+        let patch_list = if args.flag_count > 0 {
+            patchwork
                 .get_patch_query_num(&args.flag_project, args.flag_count as usize)
-                .unwrap_or_else(|err| panic!("Failed to obtain patch list: {}", err));
+                .unwrap_or_else(|err| panic!("Failed to obtain patch list: {}", err))
         } else {
-            patch_list = patchwork
+            patchwork
                 .get_patch_query(&args.flag_project)
-                .unwrap_or_else(|err| panic!("Failed to obtain patch list: {}", err));
-        }
+                .unwrap_or_else(|err| panic!("Failed to obtain patch list: {}", err))
+        };
         info!("snowpatch is ready to test new revisions from Patchwork.");
         for patch in patch_list {
             // If it's already been tested, we can skip it
@@ -478,14 +474,14 @@  fn main() {
                 patchwork.get_patch_mbox(&patch)
             };
 
-            let results = test_patch(&settings, &client, project, &mbox, hefty_tests);
+            let results = test_patch(&settings, &client, &project, &mbox, hefty_tests);
 
             // Delete the temporary directory with the patch in it
             fs::remove_dir_all(mbox.parent().unwrap())
                 .unwrap_or_else(|err| error!("Couldn't delete temp directory: {}", err));
             if project.push_results {
                 for result in results {
-                    patchwork.post_test_result(result, &patch.checks).unwrap();
+                    patchwork.post_test_result(&result, &patch.checks).unwrap();
                 }
             }
         }
diff --git a/src/patchwork.rs b/src/patchwork.rs
index 31ac8ef95911..a0722c7df0c6 100644
--- a/src/patchwork.rs
+++ b/src/patchwork.rs
@@ -218,7 +218,7 @@  impl PatchworkServer {
         PatchworkServer {
             url: url.clone(),
             client: client.clone(),
-            headers: headers,
+            headers,
         }
     }
 
@@ -266,7 +266,7 @@  impl PatchworkServer {
 
     pub fn post_test_result(
         &self,
-        result: TestResult,
+        result: &TestResult,
         checks_url: &str,
     ) -> Result<StatusCode, reqwest::Error> {
         let encoded = serde_json::to_string(&result).unwrap();
@@ -286,7 +286,7 @@  impl PatchworkServer {
         Ok(resp.status())
     }
 
-    pub fn get_patch(&self, patch_id: &u64) -> Result<Patch, serde_json::Error> {
+    pub fn get_patch(&self, patch_id: u64) -> Result<Patch, serde_json::Error> {
         let url = format!(
             "{}{}/patches/{}{}",
             &self.url, PATCHWORK_API, patch_id, PATCHWORK_QUERY
@@ -304,8 +304,11 @@  impl PatchworkServer {
             &self.url, PATCHWORK_API, PATCHWORK_QUERY, project
         );
 
-        serde_json::from_str(&self.get_url_string(&url)
-            .unwrap_or_else(|err| panic!("Failed to connect to Patchwork: {}", err)))
+        serde_json::from_str(
+            &self
+                .get_url_string(&url)
+                .unwrap_or_else(|err| panic!("Failed to connect to Patchwork: {}", err)),
+        )
     }
 
     fn get_next_link(&self, resp: &Response) -> Option<String> {
@@ -332,7 +335,8 @@  impl PatchworkServer {
         ));
 
         while let Some(real_url) = url {
-            let resp = self.get_url(&real_url)
+            let resp = self
+                .get_url(&real_url)
                 .unwrap_or_else(|err| panic!("Failed to connect to Patchwork: {}", err));
             url = self.get_next_link(&resp);
             let new_patches: Vec<Patch> = serde_json::from_reader(resp)?;
@@ -364,7 +368,7 @@  impl PatchworkServer {
     pub fn get_patch_mbox(&self, patch: &Patch) -> PathBuf {
         let dir = TempDir::new("snowpatch").unwrap().into_path();
         let mut path = dir.clone();
-        let tag = utils::sanitise_path(patch.name.clone());
+        let tag = utils::sanitise_path(&patch.name);
         path.push(format!("{}.mbox", tag));
 
         let mut mbox_resp = self.get_url(&patch.mbox).unwrap();
@@ -380,7 +384,7 @@  impl PatchworkServer {
     pub fn get_patches_mbox(&self, patches: Vec<Patch>) -> PathBuf {
         let dir = TempDir::new("snowpatch").unwrap().into_path();
         let mut path = dir.clone();
-        let tag = utils::sanitise_path(patches.last().unwrap().name.clone());
+        let tag = utils::sanitise_path(&patches.last().unwrap().name);
         path.push(format!("{}.mbox", tag));
 
         let mut mbox = OpenOptions::new()
@@ -399,7 +403,7 @@  impl PatchworkServer {
         path
     }
 
-    pub fn get_series(&self, series_id: &u64) -> Result<Series, serde_json::Error> {
+    pub fn get_series(&self, series_id: u64) -> Result<Series, serde_json::Error> {
         let url = format!(
             "{}{}/series/{}{}",
             &self.url, PATCHWORK_API, series_id, PATCHWORK_QUERY
diff --git a/src/settings.rs b/src/settings.rs
index 2d3935451cd9..241580b36e20 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -157,18 +157,18 @@  impl<'de> Deserialize<'de> for Job {
                 let job: String = job.ok_or_else(|| de::Error::missing_field("job"))?;
                 let remote = remote.ok_or_else(|| de::Error::missing_field("remote"))?;
                 let branch = branch.ok_or_else(|| de::Error::missing_field("branch"))?;
-                let title = title.unwrap_or(job.clone());
+                let title = title.unwrap_or_else(|| job.clone());
                 let hefty = hefty.unwrap_or(false);
                 let warn_on_fail = warn_on_fail.unwrap_or(false);
 
                 Ok(Job {
-                    job: job,
-                    title: title,
-                    remote: remote,
-                    branch: branch,
-                    hefty: hefty,
-                    warn_on_fail: warn_on_fail,
-                    parameters: parameters,
+                    job,
+                    title,
+                    remote,
+                    branch,
+                    hefty,
+                    warn_on_fail,
+                    parameters,
                 })
             }
         }
@@ -188,10 +188,7 @@  pub struct Config {
 pub fn parse(path: &str) -> Config {
     let mut toml_config = String::new();
 
-    let mut file = match File::open(&path) {
-        Ok(file) => file,
-        Err(_) => panic!("Couldn't open config file, exiting."),
-    };
+    let mut file = File::open(&path).expect("Couldn't open config file, exiting.");
 
     file.read_to_string(&mut toml_config)
         .unwrap_or_else(|err| panic!("Couldn't read config: {}", err));
diff --git a/src/utils.rs b/src/utils.rs
index 10ffd9562ae2..5f791afd59eb 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -13,7 +13,7 @@ 
 // utils.rs - snowpatch generic helpers
 //
 
-pub fn sanitise_path(path: String) -> String {
+pub fn sanitise_path(path: &str) -> String {
     path.replace("/", "_")
         .replace("\\", "_")
         .replace(".", "_")