Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make recent versions of clippy happy #2181

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/compiler/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ where
.map(|f| f.path())
.collect()
})
.unwrap_or(Vec::default())
.unwrap_or_default()
}
}

Expand Down Expand Up @@ -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!");
Expand Down Expand Up @@ -624,7 +622,7 @@ const INCBIN_DIRECTIVE: &[u8] = b".incbin";
fn process_preprocessed_file(
input_file: &Path,
cwd: &Path,
bytes: &mut Vec<u8>,
bytes: &mut [u8],
included_files: &mut HashMap<PathBuf, String>,
config: PreprocessorCacheModeConfig,
time_of_compilation: std::time::SystemTime,
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ async fn dist_or_local_compile<T>(
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")?;
Expand Down Expand Up @@ -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")?;
Expand Down Expand Up @@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/tasking_vx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions src/dist/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ mod common {
pub trait ReqwestRequestBuilderExt: Sized {
fn bincode<T: serde::Serialize + ?Sized>(self, bincode: &T) -> Result<Self>;
fn bytes(self, bytes: Vec<u8>) -> Self;
fn bearer_auth(self, token: String) -> Self;
}
impl ReqwestRequestBuilderExt for reqwest::blocking::RequestBuilder {
fn bincode<T: serde::Serialize + ?Sized>(self, bincode: &T) -> Result<Self> {
Expand All @@ -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<T: serde::Serialize + ?Sized>(self, bincode: &T) -> Result<Self> {
Expand All @@ -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")]
Expand Down
15 changes: 9 additions & 6 deletions src/dist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ mod path_transform {
}
}

#[derive(Debug, Default)]
#[derive(Debug)]
pub struct PathTransformer {
dist_to_local_path: HashMap<String, PathBuf>,
}
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -221,15 +221,15 @@ 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"));
}

#[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"
Expand All @@ -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"));
Expand All @@ -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<String> {
if !p.is_absolute() {
return None;
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 4 additions & 8 deletions src/lru_disk_cache/lru_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,9 @@ impl<K: Eq + Hash, V, S: BuildHasher> LruCache<K, V, S, Count> {
/// assert_eq!(cache.get_mut(&1), None);
/// assert_eq!(cache.get_mut(&2), Some(&mut "c"));
/// ```
pub fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V>
pub fn get_mut<Q: Hash + Eq + ?Sized>(&mut self, k: &Q) -> Option<&mut V>
where
K: Borrow<Q>,
Q: Hash + Eq,
{
self.map.get_refresh(k)
}
Expand Down Expand Up @@ -367,18 +366,16 @@ impl<K: Eq + Hash, V, S: BuildHasher, M: CountableMeter<K, V>> LruCache<K, V, S,
/// cache.insert(1, "a");
/// assert!(cache.contains_key(&1));
/// ```
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool
pub fn contains_key<Q: Hash + Eq + ?Sized>(&self, key: &Q) -> bool
where
K: Borrow<Q>,
Q: Hash + Eq,
{
self.map.contains_key(key)
}

pub fn get<Q: ?Sized>(&mut self, k: &Q) -> Option<&V>
pub fn get<Q: Hash + Eq + ?Sized>(&mut self, k: &Q) -> Option<&V>
where
K: Borrow<Q>,
Q: Hash + Eq,
{
self.map.get_refresh(k).map(|v| v as &V)
}
Expand Down Expand Up @@ -429,10 +426,9 @@ impl<K: Eq + Hash, V, S: BuildHasher, M: CountableMeter<K, V>> LruCache<K, V, S,
/// assert_eq!(cache.remove(&2), None);
/// assert_eq!(cache.len(), 0);
/// ```
pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V>
pub fn remove<Q: Hash + Eq + ?Sized>(&mut self, k: &Q) -> Option<V>
where
K: Borrow<Q>,
Q: Hash + Eq,
{
self.map.remove(k).map(|v| {
self.current_measure = self
Expand Down
2 changes: 1 addition & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<(String, u32, u32)>> = Cell::new(None);
static PANIC_LOCATION: Cell<Option<(String, u32, u32)>> = const { Cell::new(None) };
}

/// Start an sccache server, listening on `port`.
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/oauth.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
Loading