Skip to content

Commit 37692ac

Browse files
authored
Make recent versions of clippy happy (#2181)
1 parent 0b4f211 commit 37692ac

14 files changed

Lines changed: 43 additions & 49 deletions

File tree

src/compiler/c.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ where
275275
.map(|f| f.path())
276276
.collect()
277277
})
278-
.unwrap_or(Vec::default())
278+
.unwrap_or_default()
279279
}
280280
}
281281

@@ -485,16 +485,14 @@ where
485485
debug!("removing files {:?}", &outputs);
486486

487487
let v: std::result::Result<(), std::io::Error> =
488-
outputs.values().fold(Ok(()), |r, output| {
489-
r.and_then(|_| {
490-
let mut path = args_cwd.clone();
491-
path.push(&output.path);
492-
match fs::metadata(&path) {
493-
// File exists, remove it.
494-
Ok(_) => fs::remove_file(&path),
495-
_ => Ok(()),
496-
}
497-
})
488+
outputs.values().try_for_each(|output| {
489+
let mut path = args_cwd.clone();
490+
path.push(&output.path);
491+
match fs::metadata(&path) {
492+
// File exists, remove it.
493+
Ok(_) => fs::remove_file(&path),
494+
_ => Ok(()),
495+
}
498496
});
499497
if v.is_err() {
500498
warn!("Could not remove files after preprocessing failed!");
@@ -624,7 +622,7 @@ const INCBIN_DIRECTIVE: &[u8] = b".incbin";
624622
fn process_preprocessed_file(
625623
input_file: &Path,
626624
cwd: &Path,
627-
bytes: &mut Vec<u8>,
625+
bytes: &mut [u8],
628626
included_files: &mut HashMap<PathBuf, String>,
629627
config: PreprocessorCacheModeConfig,
630628
time_of_compilation: std::time::SystemTime,

src/compiler/compiler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ async fn dist_or_local_compile<T>(
524524
where
525525
T: CommandCreatorSync,
526526
{
527-
let mut path_transformer = dist::PathTransformer::default();
527+
let mut path_transformer = dist::PathTransformer::new();
528528
let (compile_cmd, _dist_compile_cmd, cacheable) = compilation
529529
.generate_compile_commands(&mut path_transformer, true)
530530
.context("Failed to generate compile commands")?;
@@ -554,7 +554,7 @@ where
554554
Some(ref client) => client.rewrite_includes_only(),
555555
_ => false,
556556
};
557-
let mut path_transformer = dist::PathTransformer::default();
557+
let mut path_transformer = dist::PathTransformer::new();
558558
let (compile_cmd, dist_compile_cmd, cacheable) = compilation
559559
.generate_compile_commands(&mut path_transformer, rewrite_includes_only)
560560
.context("Failed to generate compile commands")?;
@@ -1875,7 +1875,7 @@ LLVM version: 6.0",
18751875
let runtime = single_threaded_runtime();
18761876
let pool = runtime.handle();
18771877
let output = "compiler_id=clang\ncompiler_version=\"16.0.0\"";
1878-
let arguments = vec![
1878+
let arguments = [
18791879
ovec!["-c", "foo.c", "-o", "foo.o", "-DHELLO"],
18801880
ovec!["-c", "foo.c", "-o", "foo.o", "-DHI"],
18811881
ovec!["-c", "foo.c", "-o", "foo.o"],

src/compiler/diab.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ mod test {
773773
let compiler = &f.bins[0];
774774
// Compiler invocation.
775775
next_command(&creator, Ok(MockChild::new(exit_status(0), "", "")));
776-
let mut path_transformer = dist::PathTransformer::default();
776+
let mut path_transformer = dist::PathTransformer::new();
777777
let (command, _, cacheable) = generate_compile_commands(
778778
&mut path_transformer,
779779
compiler,

src/compiler/gcc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,7 @@ mod test {
20352035
let compiler = &f.bins[0];
20362036
// Compiler invocation.
20372037
next_command(&creator, Ok(MockChild::new(exit_status(0), "", "")));
2038-
let mut path_transformer = dist::PathTransformer::default();
2038+
let mut path_transformer = dist::PathTransformer::new();
20392039
let (command, dist_command, cacheable) = generate_compile_commands(
20402040
&mut path_transformer,
20412041
compiler,
@@ -2065,7 +2065,7 @@ mod test {
20652065
};
20662066
let f = TestFixture::new();
20672067
let compiler = &f.bins[0];
2068-
let mut path_transformer = dist::PathTransformer::default();
2068+
let mut path_transformer = dist::PathTransformer::new();
20692069
let (command, _, _) = generate_compile_commands(
20702070
&mut path_transformer,
20712071
compiler,

src/compiler/msvc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,7 +2450,7 @@ mod test {
24502450
let compiler = &f.bins[0];
24512451
// Compiler invocation.
24522452
next_command(&creator, Ok(MockChild::new(exit_status(0), "", "")));
2453-
let mut path_transformer = dist::PathTransformer::default();
2453+
let mut path_transformer = dist::PathTransformer::new();
24542454
let (command, dist_command, cacheable) = generate_compile_commands(
24552455
&mut path_transformer,
24562456
compiler,
@@ -2478,7 +2478,7 @@ mod test {
24782478
};
24792479
let f = TestFixture::new();
24802480
let compiler = &f.bins[0];
2481-
let mut path_transformer = dist::PathTransformer::default();
2481+
let mut path_transformer = dist::PathTransformer::new();
24822482
let (command, _, _) = generate_compile_commands(
24832483
&mut path_transformer,
24842484
compiler,
@@ -2535,7 +2535,7 @@ mod test {
25352535
let compiler = &f.bins[0];
25362536
// Compiler invocation.
25372537
next_command(&creator, Ok(MockChild::new(exit_status(0), "", "")));
2538-
let mut path_transformer = dist::PathTransformer::default();
2538+
let mut path_transformer = dist::PathTransformer::new();
25392539
let (command, dist_command, cacheable) = generate_compile_commands(
25402540
&mut path_transformer,
25412541
compiler,

src/compiler/rust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2202,7 +2202,7 @@ fn test_rust_outputs_rewriter() {
22022202
use crate::test::utils::create_file;
22032203
use std::io::Write;
22042204

2205-
let mut pt = dist::PathTransformer::default();
2205+
let mut pt = dist::PathTransformer::new();
22062206
pt.as_dist(Path::new("c:\\")).unwrap();
22072207
let mappings: Vec<_> = pt.disk_mappings().collect();
22082208
assert!(mappings.len() == 1);

src/compiler/tasking_vx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ mod test {
712712
let compiler = &f.bins[0];
713713
// Compiler invocation.
714714
next_command(&creator, Ok(MockChild::new(exit_status(0), "", "")));
715-
let mut path_transformer = dist::PathTransformer::default();
715+
let mut path_transformer = dist::PathTransformer::new();
716716
let (command, _, cacheable) = generate_compile_commands(
717717
&mut path_transformer,
718718
compiler,
@@ -761,7 +761,7 @@ mod test {
761761
let compiler = &f.bins[0];
762762
// Compiler invocation.
763763
next_command(&creator, Ok(MockChild::new(exit_status(0), "", "")));
764-
let mut path_transformer = dist::PathTransformer::default();
764+
let mut path_transformer = dist::PathTransformer::new();
765765
let (command, _, cacheable) = generate_compile_commands(
766766
&mut path_transformer,
767767
compiler,

src/dist/http.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ mod common {
3535
pub trait ReqwestRequestBuilderExt: Sized {
3636
fn bincode<T: serde::Serialize + ?Sized>(self, bincode: &T) -> Result<Self>;
3737
fn bytes(self, bytes: Vec<u8>) -> Self;
38-
fn bearer_auth(self, token: String) -> Self;
3938
}
4039
impl ReqwestRequestBuilderExt for reqwest::blocking::RequestBuilder {
4140
fn bincode<T: serde::Serialize + ?Sized>(self, bincode: &T) -> Result<Self> {
@@ -51,9 +50,6 @@ mod common {
5150
.header(header::CONTENT_LENGTH, bytes.len())
5251
.body(bytes)
5352
}
54-
fn bearer_auth(self, token: String) -> Self {
55-
self.bearer_auth(token)
56-
}
5753
}
5854
impl ReqwestRequestBuilderExt for reqwest::RequestBuilder {
5955
fn bincode<T: serde::Serialize + ?Sized>(self, bincode: &T) -> Result<Self> {
@@ -69,9 +65,6 @@ mod common {
6965
.header(header::CONTENT_LENGTH, bytes.len())
7066
.body(bytes)
7167
}
72-
fn bearer_auth(self, token: String) -> Self {
73-
self.bearer_auth(token)
74-
}
7568
}
7669

7770
#[cfg(feature = "dist-client")]

src/dist/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ mod path_transform {
9292
}
9393
}
9494

95-
#[derive(Debug, Default)]
95+
#[derive(Debug)]
9696
pub struct PathTransformer {
9797
dist_to_local_path: HashMap<String, PathBuf>,
9898
}
@@ -189,7 +189,7 @@ mod path_transform {
189189

190190
#[test]
191191
fn test_basic() {
192-
let mut pt = PathTransformer::default();
192+
let mut pt = PathTransformer::new();
193193
assert_eq!(pt.as_dist(Path::new("C:/a")).unwrap(), "/prefix/disk-C/a");
194194
assert_eq!(
195195
pt.as_dist(Path::new(r#"C:\a\b.c"#)).unwrap(),
@@ -221,15 +221,15 @@ mod path_transform {
221221

222222
#[test]
223223
fn test_relative_paths() {
224-
let mut pt = PathTransformer::default();
224+
let mut pt = PathTransformer::new();
225225
assert_eq!(pt.as_dist(Path::new("a/b")).unwrap(), "a/b");
226226
assert_eq!(pt.as_dist(Path::new(r#"a\b"#)).unwrap(), "a/b");
227227
assert_eq!(pt.to_local("a/b").unwrap(), Path::new("a/b"));
228228
}
229229

230230
#[test]
231231
fn test_verbatim_disks() {
232-
let mut pt = PathTransformer::default();
232+
let mut pt = PathTransformer::new();
233233
assert_eq!(
234234
pt.as_dist(Path::new("X:/other.c")).unwrap(),
235235
"/prefix/disk-X/other.c"
@@ -256,7 +256,7 @@ mod path_transform {
256256

257257
#[test]
258258
fn test_slash_directions() {
259-
let mut pt = PathTransformer::default();
259+
let mut pt = PathTransformer::new();
260260
assert_eq!(pt.as_dist(Path::new("C:/a")).unwrap(), "/prefix/disk-C/a");
261261
assert_eq!(pt.as_dist(Path::new("C:\\a")).unwrap(), "/prefix/disk-C/a");
262262
assert_eq!(pt.to_local("/prefix/disk-C/a").unwrap(), Path::new("C:/a"));
@@ -269,10 +269,13 @@ mod path_transform {
269269
use std::iter;
270270
use std::path::{Path, PathBuf};
271271

272-
#[derive(Debug, Default)]
272+
#[derive(Debug)]
273273
pub struct PathTransformer;
274274

275275
impl PathTransformer {
276+
pub fn new() -> Self {
277+
PathTransformer
278+
}
276279
pub fn as_dist_abs(&mut self, p: &Path) -> Option<String> {
277280
if !p.is_absolute() {
278281
return None;

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
// limitations under the License.
1414

1515
#![deny(rust_2018_idioms)]
16-
#![allow(clippy::type_complexity, clippy::new_without_default)]
16+
#![allow(
17+
clippy::type_complexity,
18+
clippy::new_without_default,
19+
clippy::blocks_in_conditions
20+
)]
1721
#![recursion_limit = "256"]
1822

1923
#[macro_use]

0 commit comments

Comments
 (0)