Skip to content

Commit f7885af

Browse files
Fix clippy lints
1 parent 04b2b91 commit f7885af

File tree

12 files changed

+130
-144
lines changed

12 files changed

+130
-144
lines changed

build_system/src/build.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl BuildArg {
3333
}
3434
arg => {
3535
if !build_arg.config_info.parse_argument(arg, &mut args)? {
36-
return Err(format!("Unknown argument `{}`", arg));
36+
return Err(format!("Unknown argument `{arg}`"));
3737
}
3838
}
3939
}
@@ -105,14 +105,14 @@ pub fn create_build_sysroot_content(start_dir: &Path) -> Result<(), String> {
105105
if !start_dir.is_dir() {
106106
create_dir(start_dir)?;
107107
}
108-
copy_file("build_system/build_sysroot/Cargo.toml", &start_dir.join("Cargo.toml"))?;
109-
copy_file("build_system/build_sysroot/Cargo.lock", &start_dir.join("Cargo.lock"))?;
108+
copy_file("build_system/build_sysroot/Cargo.toml", start_dir.join("Cargo.toml"))?;
109+
copy_file("build_system/build_sysroot/Cargo.lock", start_dir.join("Cargo.lock"))?;
110110

111111
let src_dir = start_dir.join("src");
112112
if !src_dir.is_dir() {
113113
create_dir(&src_dir)?;
114114
}
115-
copy_file("build_system/build_sysroot/lib.rs", &start_dir.join("src/lib.rs"))
115+
copy_file("build_system/build_sysroot/lib.rs", start_dir.join("src/lib.rs"))
116116
}
117117

118118
pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Result<(), String> {
@@ -169,7 +169,7 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
169169
run_command(&[&"cp", &"-r", &dir_to_copy, &sysroot_path], None).map(|_| ())
170170
};
171171
walk_dir(
172-
start_dir.join(&format!("target/{}/{}/deps", config.target_triple, channel)),
172+
start_dir.join(format!("target/{}/{}/deps", config.target_triple, channel)),
173173
&mut copier.clone(),
174174
&mut copier,
175175
false,

build_system/src/clean.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ enum CleanArg {
1717
impl CleanArg {
1818
fn new() -> Result<Self, String> {
1919
// We skip the binary and the "clean" option.
20-
for arg in std::env::args().skip(2) {
20+
if let Some(arg) = std::env::args().nth(2) {
2121
return match arg.as_str() {
2222
"all" => Ok(Self::All),
2323
"ui-tests" => Ok(Self::UiTests),
2424
"--help" => Ok(Self::Help),
25-
a => Err(format!("Unknown argument `{}`", a)),
25+
a => Err(format!("Unknown argument `{a}`")),
2626
};
2727
}
2828
Ok(Self::default())

build_system/src/clone_gcc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl Args {
4343
}
4444
arg => {
4545
if !command_args.config_info.parse_argument(arg, &mut args)? {
46-
return Err(format!("Unknown option {}", arg));
46+
return Err(format!("Unknown option {arg}"));
4747
}
4848
}
4949
}
@@ -52,7 +52,7 @@ impl Args {
5252
Some(p) => p.into(),
5353
None => PathBuf::from("./gcc"),
5454
};
55-
return Ok(Some(command_args));
55+
Ok(Some(command_args))
5656
}
5757
}
5858

@@ -64,7 +64,7 @@ pub fn run() -> Result<(), String> {
6464
let result = git_clone("https://github.com/rust-lang/gcc", Some(&args.out_path), false)?;
6565
if result.ran_clone {
6666
let gcc_commit = args.config_info.get_gcc_commit()?;
67-
println!("Checking out GCC commit `{}`...", gcc_commit);
67+
println!("Checking out GCC commit `{gcc_commit}`...");
6868
run_command_with_output(
6969
&[&"git", &"checkout", &gcc_commit],
7070
Some(Path::new(&result.repo_dir)),

build_system/src/config.rs

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl ConfigFile {
6666
"Expected a boolean for `download-gccjit`",
6767
);
6868
}
69-
_ => return failed_config_parsing(config_file, &format!("Unknown key `{}`", key)),
69+
_ => return failed_config_parsing(config_file, &format!("Unknown key `{key}`")),
7070
}
7171
}
7272
match (config.gcc_path.as_mut(), config.download_gccjit) {
@@ -86,9 +86,7 @@ impl ConfigFile {
8686
let path = Path::new(gcc_path);
8787
*gcc_path = path
8888
.canonicalize()
89-
.map_err(|err| {
90-
format!("Failed to get absolute path of `{}`: {:?}", gcc_path, err)
91-
})?
89+
.map_err(|err| format!("Failed to get absolute path of `{gcc_path}`: {err:?}"))?
9290
.display()
9391
.to_string();
9492
}
@@ -175,7 +173,7 @@ impl ConfigInfo {
175173
"--sysroot-panic-abort" => self.sysroot_panic_abort = true,
176174
"--gcc-path" => match args.next() {
177175
Some(arg) if !arg.is_empty() => {
178-
self.gcc_path = Some(arg.into());
176+
self.gcc_path = Some(arg);
179177
}
180178
_ => {
181179
return Err("Expected a value after `--gcc-path`, found nothing".to_string());
@@ -244,7 +242,7 @@ impl ConfigInfo {
244242
let libgccjit_so = output_dir.join(libgccjit_so_name);
245243
if !libgccjit_so.is_file() && !self.no_download {
246244
// Download time!
247-
let tempfile_name = format!("{}.download", libgccjit_so_name);
245+
let tempfile_name = format!("{libgccjit_so_name}.download");
248246
let tempfile = output_dir.join(&tempfile_name);
249247
let is_in_ci = std::env::var("GITHUB_ACTIONS").is_ok();
250248

@@ -262,14 +260,14 @@ impl ConfigInfo {
262260
)
263261
})?;
264262

265-
println!("Downloaded libgccjit.so version {} successfully!", commit);
263+
println!("Downloaded libgccjit.so version {commit} successfully!");
266264
// We need to create a link named `libgccjit.so.0` because that's what the linker is
267265
// looking for.
268-
create_symlink(&libgccjit_so, output_dir.join(&format!("{}.0", libgccjit_so_name)))?;
266+
create_symlink(&libgccjit_so, output_dir.join(format!("{libgccjit_so_name}.0")))?;
269267
}
270268

271269
let gcc_path = output_dir.display().to_string();
272-
println!("Using `{}` as path for libgccjit", gcc_path);
270+
println!("Using `{gcc_path}` as path for libgccjit");
273271
self.gcc_path = Some(gcc_path);
274272
Ok(())
275273
}
@@ -286,8 +284,7 @@ impl ConfigInfo {
286284
// since we already have everything we need.
287285
if let Some(gcc_path) = &self.gcc_path {
288286
println!(
289-
"`--gcc-path` was provided, ignoring config file. Using `{}` as path for libgccjit",
290-
gcc_path
287+
"`--gcc-path` was provided, ignoring config file. Using `{gcc_path}` as path for libgccjit"
291288
);
292289
return Ok(());
293290
}
@@ -343,7 +340,7 @@ impl ConfigInfo {
343340
self.dylib_ext = match os_name.as_str() {
344341
"Linux" => "so",
345342
"Darwin" => "dylib",
346-
os => return Err(format!("unsupported OS `{}`", os)),
343+
os => return Err(format!("unsupported OS `{os}`")),
347344
}
348345
.to_string();
349346
let rustc = match env.get("RUSTC") {
@@ -355,10 +352,10 @@ impl ConfigInfo {
355352
None => return Err("no host found".to_string()),
356353
};
357354

358-
if self.target_triple.is_empty() {
359-
if let Some(overwrite) = env.get("OVERWRITE_TARGET_TRIPLE") {
360-
self.target_triple = overwrite.clone();
361-
}
355+
if self.target_triple.is_empty()
356+
&& let Some(overwrite) = env.get("OVERWRITE_TARGET_TRIPLE")
357+
{
358+
self.target_triple = overwrite.clone();
362359
}
363360
if self.target_triple.is_empty() {
364361
self.target_triple = self.host_triple.clone();
@@ -378,7 +375,7 @@ impl ConfigInfo {
378375
}
379376

380377
let current_dir =
381-
std_env::current_dir().map_err(|error| format!("`current_dir` failed: {:?}", error))?;
378+
std_env::current_dir().map_err(|error| format!("`current_dir` failed: {error:?}"))?;
382379
let channel = if self.channel == Channel::Release {
383380
"release"
384381
} else if let Some(channel) = env.get("CHANNEL") {
@@ -391,15 +388,15 @@ impl ConfigInfo {
391388
self.cg_backend_path = current_dir
392389
.join("target")
393390
.join(channel)
394-
.join(&format!("librustc_codegen_gcc.{}", self.dylib_ext))
391+
.join(format!("librustc_codegen_gcc.{}", self.dylib_ext))
395392
.display()
396393
.to_string();
397394
self.sysroot_path =
398-
current_dir.join(&get_sysroot_dir()).join("sysroot").display().to_string();
395+
current_dir.join(get_sysroot_dir()).join("sysroot").display().to_string();
399396
if let Some(backend) = &self.backend {
400397
// This option is only used in the rust compiler testsuite. The sysroot is handled
401398
// by its build system directly so no need to set it ourselves.
402-
rustflags.push(format!("-Zcodegen-backend={}", backend));
399+
rustflags.push(format!("-Zcodegen-backend={backend}"));
403400
} else {
404401
rustflags.extend_from_slice(&[
405402
"--sysroot".to_string(),
@@ -412,10 +409,10 @@ impl ConfigInfo {
412409
// We have a different environment variable than RUSTFLAGS to make sure those flags are
413410
// only sent to rustc_codegen_gcc and not the LLVM backend.
414411
if let Some(cg_rustflags) = env.get("CG_RUSTFLAGS") {
415-
rustflags.extend_from_slice(&split_args(&cg_rustflags)?);
412+
rustflags.extend_from_slice(&split_args(cg_rustflags)?);
416413
}
417414
if let Some(test_flags) = env.get("TEST_FLAGS") {
418-
rustflags.extend_from_slice(&split_args(&test_flags)?);
415+
rustflags.extend_from_slice(&split_args(test_flags)?);
419416
}
420417

421418
if let Some(linker) = linker {
@@ -438,8 +435,8 @@ impl ConfigInfo {
438435
env.insert("RUSTC_LOG".to_string(), "warn".to_string());
439436

440437
let sysroot = current_dir
441-
.join(&get_sysroot_dir())
442-
.join(&format!("sysroot/lib/rustlib/{}/lib", self.target_triple));
438+
.join(get_sysroot_dir())
439+
.join(format!("sysroot/lib/rustlib/{}/lib", self.target_triple));
443440
let ld_library_path = format!(
444441
"{target}:{sysroot}:{gcc_path}",
445442
target = self.cargo_target_dir,
@@ -505,7 +502,7 @@ fn download_gccjit(
505502
with_progress_bar: bool,
506503
) -> Result<(), String> {
507504
let url = if std::env::consts::OS == "linux" && std::env::consts::ARCH == "x86_64" {
508-
format!("https://github.com/rust-lang/gcc/releases/download/master-{}/libgccjit.so", commit)
505+
format!("https://github.com/rust-lang/gcc/releases/download/master-{commit}/libgccjit.so")
509506
} else {
510507
eprintln!(
511508
"\
@@ -518,7 +515,7 @@ to `download-gccjit = false` and set `gcc-path` to the appropriate directory."
518515
));
519516
};
520517

521-
println!("Downloading `{}`...", url);
518+
println!("Downloading `{url}`...");
522519

523520
// Try curl. If that fails and we are on windows, fallback to PowerShell.
524521
let mut ret = run_command_with_output(
@@ -538,7 +535,7 @@ to `download-gccjit = false` and set `gcc-path` to the appropriate directory."
538535
if with_progress_bar { &"--progress-bar" } else { &"-s" },
539536
&url.as_str(),
540537
],
541-
Some(&output_dir),
538+
Some(output_dir),
542539
);
543540
if ret.is_err() && cfg!(windows) {
544541
eprintln!("Fallback to PowerShell");
@@ -549,12 +546,11 @@ to `download-gccjit = false` and set `gcc-path` to the appropriate directory."
549546
&"-Command",
550547
&"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;",
551548
&format!(
552-
"(New-Object System.Net.WebClient).DownloadFile('{}', '{}')",
553-
url, tempfile_name,
549+
"(New-Object System.Net.WebClient).DownloadFile('{url}', '{tempfile_name}')",
554550
)
555551
.as_str(),
556552
],
557-
Some(&output_dir),
553+
Some(output_dir),
558554
);
559555
}
560556
ret

build_system/src/fmt.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ fn show_usage() {
1616
pub fn run() -> Result<(), String> {
1717
let mut check = false;
1818
// We skip binary name and the `info` command.
19-
let mut args = std::env::args().skip(2);
20-
while let Some(arg) = args.next() {
19+
let args = std::env::args().skip(2);
20+
for arg in args {
2121
match arg.as_str() {
2222
"--help" => {
2323
show_usage();
2424
return Ok(());
2525
}
2626
"--check" => check = true,
27-
_ => return Err(format!("Unknown option {}", arg)),
27+
_ => return Err(format!("Unknown option {arg}")),
2828
}
2929
}
3030

3131
let cmd: &[&dyn AsRef<OsStr>] =
3232
if check { &[&"cargo", &"fmt", &"--check"] } else { &[&"cargo", &"fmt"] };
3333

34-
run_command_with_output(cmd, Some(&Path::new(".")))?;
35-
run_command_with_output(cmd, Some(&Path::new("build_system")))
34+
run_command_with_output(cmd, Some(Path::new(".")))?;
35+
run_command_with_output(cmd, Some(Path::new("build_system")))
3636
}

build_system/src/fuzz.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn run() -> Result<(), String> {
5656
)
5757
.map_err(|err| (format!("Fuzz thread count not a number {err:?}!")))?;
5858
}
59-
_ => return Err(format!("Unknown option {}", arg)),
59+
_ => return Err(format!("Unknown option {arg}")),
6060
}
6161
}
6262

@@ -70,11 +70,11 @@ pub fn run() -> Result<(), String> {
7070

7171
// Ensure that we are on the newest rustlantis commit.
7272
let cmd: &[&dyn AsRef<OsStr>] = &[&"git", &"pull", &"origin"];
73-
run_command_with_output(cmd, Some(&Path::new("clones/rustlantis")))?;
73+
run_command_with_output(cmd, Some(Path::new("clones/rustlantis")))?;
7474

7575
// Build the release version of rustlantis
7676
let cmd: &[&dyn AsRef<OsStr>] = &[&"cargo", &"build", &"--release"];
77-
run_command_with_output(cmd, Some(&Path::new("clones/rustlantis")))?;
77+
run_command_with_output(cmd, Some(Path::new("clones/rustlantis")))?;
7878
// Fuzz a given range
7979
fuzz_range(start, start + count, threads);
8080
Ok(())
@@ -104,13 +104,13 @@ fn fuzz_range(start: u64, end: u64, threads: usize) {
104104
match test(next, false) {
105105
Err(err) => {
106106
// If the test failed at compile-time...
107-
println!("test({}) failed because {err:?}", next);
107+
println!("test({next}) failed because {err:?}");
108108
// ... copy that file to the directory `target/fuzz/compiletime_error`...
109109
let mut out_path: std::path::PathBuf =
110110
"target/fuzz/compiletime_error".into();
111111
std::fs::create_dir_all(&out_path).unwrap();
112112
// .. into a file named `fuzz{seed}.rs`.
113-
out_path.push(&format!("fuzz{next}.rs"));
113+
out_path.push(format!("fuzz{next}.rs"));
114114
std::fs::copy(err, out_path).unwrap();
115115
}
116116
Ok(Err(err)) => {
@@ -122,12 +122,12 @@ fn fuzz_range(start: u64, end: u64, threads: usize) {
122122
let Ok(Err(tmp_print_err)) = test(next, true) else {
123123
// ... if that file does not reproduce the issue...
124124
// ... save the original sample in a file named `fuzz{seed}.rs`...
125-
out_path.push(&format!("fuzz{next}.rs"));
125+
out_path.push(format!("fuzz{next}.rs"));
126126
std::fs::copy(err, &out_path).unwrap();
127127
continue;
128128
};
129129
// ... if that new file still produces the issue, copy it to `fuzz{seed}.rs`..
130-
out_path.push(&format!("fuzz{next}.rs"));
130+
out_path.push(format!("fuzz{next}.rs"));
131131
std::fs::copy(tmp_print_err, &out_path).unwrap();
132132
// ... and start reducing it, using some properties of `rustlantis` to speed up the process.
133133
reduce::reduce(&out_path);
@@ -240,10 +240,10 @@ fn test_cached(
240240
cache: &mut ResultCache,
241241
) -> Result<Result<(), std::path::PathBuf>, String> {
242242
// Test `source_file` with release GCC ...
243-
let gcc_res = release_gcc(&source_file)?;
243+
let gcc_res = release_gcc(source_file)?;
244244
if cache.is_none() {
245245
// ...test `source_file` with debug LLVM ...
246-
*cache = Some((debug_llvm(&source_file)?, gcc_res.clone()));
246+
*cache = Some((debug_llvm(source_file)?, gcc_res.clone()));
247247
}
248248
let (llvm_res, old_gcc) = cache.as_ref().unwrap();
249249
// ... compare the results ...
@@ -269,12 +269,12 @@ fn test_file(
269269
fn generate(seed: u64, print_tmp_vars: bool) -> Result<std::path::PathBuf, String> {
270270
use std::io::Write;
271271
let mut out_path = std::env::temp_dir();
272-
out_path.push(&format!("fuzz{seed}.rs"));
272+
out_path.push(format!("fuzz{seed}.rs"));
273273
// We need to get the command output here.
274274
let mut generate = std::process::Command::new("cargo");
275275
generate
276276
.args(["run", "--release", "--bin", "generate"])
277-
.arg(&format!("{seed}"))
277+
.arg(format!("{seed}"))
278278
.current_dir("clones/rustlantis");
279279
if print_tmp_vars {
280280
generate.arg("--debug");

0 commit comments

Comments
 (0)