Make recent versions of clippy happy (#2181)

This commit is contained in:
Mike Hommey 2024-05-24 15:02:45 +09:00 коммит произвёл GitHub
Родитель 0b4f211f97
Коммит 37692acdce
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
14 изменённых файлов: 43 добавлений и 49 удалений

Просмотреть файл

@ -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<u8>,
bytes: &mut [u8],
included_files: &mut HashMap<PathBuf, String>,
config: PreprocessorCacheModeConfig,
time_of_compilation: std::time::SystemTime,

Просмотреть файл

@ -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")?;
@ -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"],

Просмотреть файл

@ -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,

Просмотреть файл

@ -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,

Просмотреть файл

@ -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,

Просмотреть файл

@ -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);

Просмотреть файл

@ -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,

7
src/dist/http.rs поставляемый
Просмотреть файл

@ -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> {
@ -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> {
@ -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")]

15
src/dist/mod.rs поставляемый
Просмотреть файл

@ -92,7 +92,7 @@ mod path_transform {
}
}
#[derive(Debug, Default)]
#[derive(Debug)]
pub struct PathTransformer {
dist_to_local_path: HashMap<String, PathBuf>,
}
@ -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<String> {
if !p.is_absolute() {
return None;

Просмотреть файл

@ -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]

Просмотреть файл

@ -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)
}
@ -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)
}
@ -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

Просмотреть файл

@ -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`.

Просмотреть файл

@ -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;

Просмотреть файл

@ -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};