From 190c3b1356a03d3be8c9c7f9d88aa805593fe593 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Sun, 19 May 2024 12:55:54 +0900 Subject: [PATCH] Make recent versions of clippy happy --- src/compiler/c.rs | 22 ++++++++++------------ src/compiler/compiler.rs | 6 +++--- src/compiler/diab.rs | 2 +- src/compiler/gcc.rs | 4 ++-- src/compiler/msvc.rs | 6 +++--- src/compiler/rust.rs | 2 +- src/compiler/tasking_vx.rs | 4 ++-- src/dist/http.rs | 7 ------- src/dist/mod.rs | 15 +++++++++------ src/lib.rs | 6 +++++- src/lru_disk_cache/lru_cache.rs | 12 ++++-------- src/server.rs | 2 +- src/util.rs | 2 +- tests/oauth.rs | 2 +- 14 files changed, 43 insertions(+), 49 deletions(-) diff --git a/src/compiler/c.rs b/src/compiler/c.rs index 9e8db55ed..b3914143b 100644 --- a/src/compiler/c.rs +++ b/src/compiler/c.rs @@ -275,7 +275,7 @@ where .map(|f| f.path()) .collect() }) - .unwrap_or(Vec::default()) + .unwrap_or_default() } } @@ -485,16 +485,14 @@ where debug!("removing files {:?}", &outputs); let v: std::result::Result<(), std::io::Error> = - outputs.values().fold(Ok(()), |r, output| { - r.and_then(|_| { - let mut path = args_cwd.clone(); - path.push(&output.path); - match fs::metadata(&path) { - // File exists, remove it. - Ok(_) => fs::remove_file(&path), - _ => Ok(()), - } - }) + outputs.values().try_for_each(|output| { + let mut path = args_cwd.clone(); + path.push(&output.path); + match fs::metadata(&path) { + // File exists, remove it. + Ok(_) => fs::remove_file(&path), + _ => Ok(()), + } }); if v.is_err() { warn!("Could not remove files after preprocessing failed!"); @@ -624,7 +622,7 @@ const INCBIN_DIRECTIVE: &[u8] = b".incbin"; fn process_preprocessed_file( input_file: &Path, cwd: &Path, - bytes: &mut Vec, + bytes: &mut [u8], included_files: &mut HashMap, config: PreprocessorCacheModeConfig, time_of_compilation: std::time::SystemTime, diff --git a/src/compiler/compiler.rs b/src/compiler/compiler.rs index c41406962..d1c4692d4 100644 --- a/src/compiler/compiler.rs +++ b/src/compiler/compiler.rs @@ -524,7 +524,7 @@ async fn dist_or_local_compile( where T: CommandCreatorSync, { - let mut path_transformer = dist::PathTransformer::default(); + let mut path_transformer = dist::PathTransformer::new(); let (compile_cmd, _dist_compile_cmd, cacheable) = compilation .generate_compile_commands(&mut path_transformer, true) .context("Failed to generate compile commands")?; @@ -554,7 +554,7 @@ where Some(ref client) => client.rewrite_includes_only(), _ => false, }; - let mut path_transformer = dist::PathTransformer::default(); + let mut path_transformer = dist::PathTransformer::new(); let (compile_cmd, dist_compile_cmd, cacheable) = compilation .generate_compile_commands(&mut path_transformer, rewrite_includes_only) .context("Failed to generate compile commands")?; @@ -1875,7 +1875,7 @@ LLVM version: 6.0", let runtime = single_threaded_runtime(); let pool = runtime.handle(); let output = "compiler_id=clang\ncompiler_version=\"16.0.0\""; - let arguments = vec![ + let arguments = [ ovec!["-c", "foo.c", "-o", "foo.o", "-DHELLO"], ovec!["-c", "foo.c", "-o", "foo.o", "-DHI"], ovec!["-c", "foo.c", "-o", "foo.o"], diff --git a/src/compiler/diab.rs b/src/compiler/diab.rs index 7ef453b29..f56bfce95 100644 --- a/src/compiler/diab.rs +++ b/src/compiler/diab.rs @@ -773,7 +773,7 @@ mod test { let compiler = &f.bins[0]; // Compiler invocation. next_command(&creator, Ok(MockChild::new(exit_status(0), "", ""))); - let mut path_transformer = dist::PathTransformer::default(); + let mut path_transformer = dist::PathTransformer::new(); let (command, _, cacheable) = generate_compile_commands( &mut path_transformer, compiler, diff --git a/src/compiler/gcc.rs b/src/compiler/gcc.rs index 549d3323d..d845e9751 100644 --- a/src/compiler/gcc.rs +++ b/src/compiler/gcc.rs @@ -2035,7 +2035,7 @@ mod test { let compiler = &f.bins[0]; // Compiler invocation. next_command(&creator, Ok(MockChild::new(exit_status(0), "", ""))); - let mut path_transformer = dist::PathTransformer::default(); + let mut path_transformer = dist::PathTransformer::new(); let (command, dist_command, cacheable) = generate_compile_commands( &mut path_transformer, compiler, @@ -2065,7 +2065,7 @@ mod test { }; let f = TestFixture::new(); let compiler = &f.bins[0]; - let mut path_transformer = dist::PathTransformer::default(); + let mut path_transformer = dist::PathTransformer::new(); let (command, _, _) = generate_compile_commands( &mut path_transformer, compiler, diff --git a/src/compiler/msvc.rs b/src/compiler/msvc.rs index 3f513e86d..9eae06413 100644 --- a/src/compiler/msvc.rs +++ b/src/compiler/msvc.rs @@ -2450,7 +2450,7 @@ mod test { let compiler = &f.bins[0]; // Compiler invocation. next_command(&creator, Ok(MockChild::new(exit_status(0), "", ""))); - let mut path_transformer = dist::PathTransformer::default(); + let mut path_transformer = dist::PathTransformer::new(); let (command, dist_command, cacheable) = generate_compile_commands( &mut path_transformer, compiler, @@ -2478,7 +2478,7 @@ mod test { }; let f = TestFixture::new(); let compiler = &f.bins[0]; - let mut path_transformer = dist::PathTransformer::default(); + let mut path_transformer = dist::PathTransformer::new(); let (command, _, _) = generate_compile_commands( &mut path_transformer, compiler, @@ -2535,7 +2535,7 @@ mod test { let compiler = &f.bins[0]; // Compiler invocation. next_command(&creator, Ok(MockChild::new(exit_status(0), "", ""))); - let mut path_transformer = dist::PathTransformer::default(); + let mut path_transformer = dist::PathTransformer::new(); let (command, dist_command, cacheable) = generate_compile_commands( &mut path_transformer, compiler, diff --git a/src/compiler/rust.rs b/src/compiler/rust.rs index 1f4077c22..0a4f73905 100644 --- a/src/compiler/rust.rs +++ b/src/compiler/rust.rs @@ -2202,7 +2202,7 @@ fn test_rust_outputs_rewriter() { use crate::test::utils::create_file; use std::io::Write; - let mut pt = dist::PathTransformer::default(); + let mut pt = dist::PathTransformer::new(); pt.as_dist(Path::new("c:\\")).unwrap(); let mappings: Vec<_> = pt.disk_mappings().collect(); assert!(mappings.len() == 1); diff --git a/src/compiler/tasking_vx.rs b/src/compiler/tasking_vx.rs index 09cc8d74a..944824ca2 100644 --- a/src/compiler/tasking_vx.rs +++ b/src/compiler/tasking_vx.rs @@ -712,7 +712,7 @@ mod test { let compiler = &f.bins[0]; // Compiler invocation. next_command(&creator, Ok(MockChild::new(exit_status(0), "", ""))); - let mut path_transformer = dist::PathTransformer::default(); + let mut path_transformer = dist::PathTransformer::new(); let (command, _, cacheable) = generate_compile_commands( &mut path_transformer, compiler, @@ -761,7 +761,7 @@ mod test { let compiler = &f.bins[0]; // Compiler invocation. next_command(&creator, Ok(MockChild::new(exit_status(0), "", ""))); - let mut path_transformer = dist::PathTransformer::default(); + let mut path_transformer = dist::PathTransformer::new(); let (command, _, cacheable) = generate_compile_commands( &mut path_transformer, compiler, diff --git a/src/dist/http.rs b/src/dist/http.rs index 5dfeac0cc..621fe8277 100644 --- a/src/dist/http.rs +++ b/src/dist/http.rs @@ -35,7 +35,6 @@ mod common { pub trait ReqwestRequestBuilderExt: Sized { fn bincode(self, bincode: &T) -> Result; fn bytes(self, bytes: Vec) -> Self; - fn bearer_auth(self, token: String) -> Self; } impl ReqwestRequestBuilderExt for reqwest::blocking::RequestBuilder { fn bincode(self, bincode: &T) -> Result { @@ -51,9 +50,6 @@ mod common { .header(header::CONTENT_LENGTH, bytes.len()) .body(bytes) } - fn bearer_auth(self, token: String) -> Self { - self.bearer_auth(token) - } } impl ReqwestRequestBuilderExt for reqwest::RequestBuilder { fn bincode(self, bincode: &T) -> Result { @@ -69,9 +65,6 @@ mod common { .header(header::CONTENT_LENGTH, bytes.len()) .body(bytes) } - fn bearer_auth(self, token: String) -> Self { - self.bearer_auth(token) - } } #[cfg(feature = "dist-client")] diff --git a/src/dist/mod.rs b/src/dist/mod.rs index 90ffc2b37..93a6859cf 100644 --- a/src/dist/mod.rs +++ b/src/dist/mod.rs @@ -92,7 +92,7 @@ mod path_transform { } } - #[derive(Debug, Default)] + #[derive(Debug)] pub struct PathTransformer { dist_to_local_path: HashMap, } @@ -189,7 +189,7 @@ mod path_transform { #[test] fn test_basic() { - let mut pt = PathTransformer::default(); + let mut pt = PathTransformer::new(); assert_eq!(pt.as_dist(Path::new("C:/a")).unwrap(), "/prefix/disk-C/a"); assert_eq!( pt.as_dist(Path::new(r#"C:\a\b.c"#)).unwrap(), @@ -221,7 +221,7 @@ mod path_transform { #[test] fn test_relative_paths() { - let mut pt = PathTransformer::default(); + let mut pt = PathTransformer::new(); assert_eq!(pt.as_dist(Path::new("a/b")).unwrap(), "a/b"); assert_eq!(pt.as_dist(Path::new(r#"a\b"#)).unwrap(), "a/b"); assert_eq!(pt.to_local("a/b").unwrap(), Path::new("a/b")); @@ -229,7 +229,7 @@ mod path_transform { #[test] fn test_verbatim_disks() { - let mut pt = PathTransformer::default(); + let mut pt = PathTransformer::new(); assert_eq!( pt.as_dist(Path::new("X:/other.c")).unwrap(), "/prefix/disk-X/other.c" @@ -256,7 +256,7 @@ mod path_transform { #[test] fn test_slash_directions() { - let mut pt = PathTransformer::default(); + let mut pt = PathTransformer::new(); assert_eq!(pt.as_dist(Path::new("C:/a")).unwrap(), "/prefix/disk-C/a"); assert_eq!(pt.as_dist(Path::new("C:\\a")).unwrap(), "/prefix/disk-C/a"); assert_eq!(pt.to_local("/prefix/disk-C/a").unwrap(), Path::new("C:/a")); @@ -269,10 +269,13 @@ mod path_transform { use std::iter; use std::path::{Path, PathBuf}; - #[derive(Debug, Default)] + #[derive(Debug)] pub struct PathTransformer; impl PathTransformer { + pub fn new() -> Self { + PathTransformer + } pub fn as_dist_abs(&mut self, p: &Path) -> Option { if !p.is_absolute() { return None; diff --git a/src/lib.rs b/src/lib.rs index 3c95d3776..a893a155f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,11 @@ // limitations under the License. #![deny(rust_2018_idioms)] -#![allow(clippy::type_complexity, clippy::new_without_default)] +#![allow( + clippy::type_complexity, + clippy::new_without_default, + clippy::blocks_in_conditions +)] #![recursion_limit = "256"] #[macro_use] diff --git a/src/lru_disk_cache/lru_cache.rs b/src/lru_disk_cache/lru_cache.rs index 3c282361c..ed6028bb5 100644 --- a/src/lru_disk_cache/lru_cache.rs +++ b/src/lru_disk_cache/lru_cache.rs @@ -285,10 +285,9 @@ impl LruCache { /// assert_eq!(cache.get_mut(&1), None); /// assert_eq!(cache.get_mut(&2), Some(&mut "c")); /// ``` - pub fn get_mut(&mut self, k: &Q) -> Option<&mut V> + pub fn get_mut(&mut self, k: &Q) -> Option<&mut V> where K: Borrow, - Q: Hash + Eq, { self.map.get_refresh(k) } @@ -367,18 +366,16 @@ impl> LruCache(&self, key: &Q) -> bool + pub fn contains_key(&self, key: &Q) -> bool where K: Borrow, - Q: Hash + Eq, { self.map.contains_key(key) } - pub fn get(&mut self, k: &Q) -> Option<&V> + pub fn get(&mut self, k: &Q) -> Option<&V> where K: Borrow, - Q: Hash + Eq, { self.map.get_refresh(k).map(|v| v as &V) } @@ -429,10 +426,9 @@ impl> LruCache(&mut self, k: &Q) -> Option + pub fn remove(&mut self, k: &Q) -> Option where K: Borrow, - Q: Hash + Eq, { self.map.remove(k).map(|v| { self.current_measure = self diff --git a/src/server.rs b/src/server.rs index 70dc4f859..094dc4ac9 100644 --- a/src/server.rs +++ b/src/server.rs @@ -398,7 +398,7 @@ thread_local! { /// catch_unwind doesn't provide panic location, so we store that /// information via a panic hook to be used when catch_unwind /// catches a panic. - static PANIC_LOCATION: Cell> = Cell::new(None); + static PANIC_LOCATION: Cell> = const { Cell::new(None) }; } /// Start an sccache server, listening on `port`. diff --git a/src/util.rs b/src/util.rs index 2cd298238..18b1a15a5 100644 --- a/src/util.rs +++ b/src/util.rs @@ -203,7 +203,7 @@ impl TimeMacroFinder { // importance compared to just getting many small reads. self.previous_small_read.extend(visit); } else { - self.previous_small_read = visit.to_owned(); + visit.clone_into(&mut self.previous_small_read); } self.find_macros(&self.previous_small_read); return; diff --git a/tests/oauth.rs b/tests/oauth.rs index c975a6a24..af8709c35 100755 --- a/tests/oauth.rs +++ b/tests/oauth.rs @@ -1,5 +1,5 @@ #![deny(rust_2018_idioms)] -#![cfg(all(feature = "dist-client"))] +#![cfg(feature = "dist-client")] use fs_err as fs; use std::io::{self, Read, Write};