diff options
| author | onur-ozkan <work@onurozkan.dev> | 2025-05-27 18:53:20 +0300 |
|---|---|---|
| committer | onur-ozkan <work@onurozkan.dev> | 2025-05-30 21:04:33 +0300 |
| commit | a577bcc07738dbf41b718ec3dde208b8c80a27cb (patch) | |
| tree | 07292f9acec835da651763d3f0753fc686351bc0 /src | |
| parent | d2a6990122ed4eccc4c2914fab4ba62df1a245d7 (diff) | |
| download | rust-a577bcc07738dbf41b718ec3dde208b8c80a27cb.tar.gz rust-a577bcc07738dbf41b718ec3dde208b8c80a27cb.zip | |
fix clippy warnings
Signed-off-by: onur-ozkan <work@onurozkan.dev>
Diffstat (limited to 'src')
| -rw-r--r-- | src/bootstrap/src/bin/rustc.rs | 57 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/compile.rs | 33 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/dist.rs | 21 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/format.rs | 8 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/llvm.rs | 87 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/perf.rs | 8 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/setup.rs | 24 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/test.rs | 8 | ||||
| -rw-r--r-- | src/bootstrap/src/core/builder/cargo.rs | 29 | ||||
| -rw-r--r-- | src/bootstrap/src/core/config/config.rs | 91 | ||||
| -rw-r--r-- | src/bootstrap/src/core/download.rs | 8 | ||||
| -rw-r--r-- | src/bootstrap/src/lib.rs | 83 | ||||
| -rw-r--r-- | src/bootstrap/src/utils/change_tracker.rs | 8 |
13 files changed, 230 insertions, 235 deletions
diff --git a/src/bootstrap/src/bin/rustc.rs b/src/bootstrap/src/bin/rustc.rs index 374884d8a9a..0671a8467e8 100644 --- a/src/bootstrap/src/bin/rustc.rs +++ b/src/bootstrap/src/bin/rustc.rs @@ -120,14 +120,12 @@ fn main() { }; cmd.args(&args).env(dylib_path_var(), env::join_paths(&dylib_path).unwrap()); - if let Some(crate_name) = crate_name { - if let Some(target) = env::var_os("RUSTC_TIME") { - if target == "all" - || target.into_string().unwrap().split(',').any(|c| c.trim() == crate_name) - { - cmd.arg("-Ztime-passes"); - } - } + if let Some(crate_name) = crate_name + && let Some(target) = env::var_os("RUSTC_TIME") + && (target == "all" + || target.into_string().unwrap().split(',').any(|c| c.trim() == crate_name)) + { + cmd.arg("-Ztime-passes"); } // Print backtrace in case of ICE @@ -242,10 +240,10 @@ fn main() { } } - if env::var_os("RUSTC_BOLT_LINK_FLAGS").is_some() { - if let Some("rustc_driver") = crate_name { - cmd.arg("-Clink-args=-Wl,-q"); - } + if env::var_os("RUSTC_BOLT_LINK_FLAGS").is_some() + && let Some("rustc_driver") = crate_name + { + cmd.arg("-Clink-args=-Wl,-q"); } let is_test = args.iter().any(|a| a == "--test"); @@ -282,25 +280,24 @@ fn main() { (child, status) }; - if env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some() - || env::var_os("RUSTC_PRINT_STEP_RUSAGE").is_some() + if (env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some() + || env::var_os("RUSTC_PRINT_STEP_RUSAGE").is_some()) + && let Some(crate_name) = crate_name { - if let Some(crate_name) = crate_name { - let dur = start.elapsed(); - // If the user requested resource usage data, then - // include that in addition to the timing output. - let rusage_data = - env::var_os("RUSTC_PRINT_STEP_RUSAGE").and_then(|_| format_rusage_data(child)); - eprintln!( - "[RUSTC-TIMING] {} test:{} {}.{:03}{}{}", - crate_name, - is_test, - dur.as_secs(), - dur.subsec_millis(), - if rusage_data.is_some() { " " } else { "" }, - rusage_data.unwrap_or_default(), - ); - } + let dur = start.elapsed(); + // If the user requested resource usage data, then + // include that in addition to the timing output. + let rusage_data = + env::var_os("RUSTC_PRINT_STEP_RUSAGE").and_then(|_| format_rusage_data(child)); + eprintln!( + "[RUSTC-TIMING] {} test:{} {}.{:03}{}{}", + crate_name, + is_test, + dur.as_secs(), + dur.subsec_millis(), + if rusage_data.is_some() { " " } else { "" }, + rusage_data.unwrap_or_default(), + ); } if status.success() { diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index f1e0717e39c..0c18ebedb37 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -626,18 +626,18 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car // Help the libc crate compile by assisting it in finding various // sysroot native libraries. - if target.contains("musl") { - if let Some(p) = builder.musl_libdir(target) { - let root = format!("native={}", p.to_str().unwrap()); - cargo.rustflag("-L").rustflag(&root); - } + if target.contains("musl") + && let Some(p) = builder.musl_libdir(target) + { + let root = format!("native={}", p.to_str().unwrap()); + cargo.rustflag("-L").rustflag(&root); } - if target.contains("-wasi") { - if let Some(dir) = builder.wasi_libdir(target) { - let root = format!("native={}", dir.to_str().unwrap()); - cargo.rustflag("-L").rustflag(&root); - } + if target.contains("-wasi") + && let Some(dir) = builder.wasi_libdir(target) + { + let root = format!("native={}", dir.to_str().unwrap()); + cargo.rustflag("-L").rustflag(&root); } } @@ -1391,12 +1391,13 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect // found. This is to avoid the linker errors about undefined references to // `__llvm_profile_instrument_memop` when linking `rustc_driver`. let mut llvm_linker_flags = String::new(); - if builder.config.llvm_profile_generate && target.is_msvc() { - if let Some(ref clang_cl_path) = builder.config.llvm_clang_cl { - // Add clang's runtime library directory to the search path - let clang_rt_dir = get_clang_cl_resource_dir(builder, clang_cl_path); - llvm_linker_flags.push_str(&format!("-L{}", clang_rt_dir.display())); - } + if builder.config.llvm_profile_generate + && target.is_msvc() + && let Some(ref clang_cl_path) = builder.config.llvm_clang_cl + { + // Add clang's runtime library directory to the search path + let clang_rt_dir = get_clang_cl_resource_dir(builder, clang_cl_path); + llvm_linker_flags.push_str(&format!("-L{}", clang_rt_dir.display())); } // The config can also specify its own llvm linker flags. diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index 50dc8e5ac9b..587fca80374 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -2276,11 +2276,12 @@ impl Step for LlvmTools { let target = self.target; // Run only if a custom llvm-config is not used - if let Some(config) = builder.config.target_config.get(&target) { - if !builder.config.llvm_from_ci && config.llvm_config.is_some() { - builder.info(&format!("Skipping LlvmTools ({target}): external LLVM")); - return None; - } + if let Some(config) = builder.config.target_config.get(&target) + && !builder.config.llvm_from_ci + && config.llvm_config.is_some() + { + builder.info(&format!("Skipping LlvmTools ({target}): external LLVM")); + return None; } if !builder.config.dry_run() { @@ -2398,11 +2399,11 @@ impl Step for RustDev { let target = self.target; /* run only if llvm-config isn't used */ - if let Some(config) = builder.config.target_config.get(&target) { - if let Some(ref _s) = config.llvm_config { - builder.info(&format!("Skipping RustDev ({target}): external LLVM")); - return None; - } + if let Some(config) = builder.config.target_config.get(&target) + && let Some(ref _s) = config.llvm_config + { + builder.info(&format!("Skipping RustDev ({target}): external LLVM")); + return None; } if !builder.config.dry_run() { diff --git a/src/bootstrap/src/core/build_steps/format.rs b/src/bootstrap/src/core/build_steps/format.rs index 1c317ce4b86..61268df7336 100644 --- a/src/bootstrap/src/core/build_steps/format.rs +++ b/src/bootstrap/src/core/build_steps/format.rs @@ -318,10 +318,10 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) { // `into_path` produces an absolute path. Try to strip `cwd` to get a shorter // relative path. let mut path = entry.clone().into_path(); - if let Ok(cwd) = cwd { - if let Ok(path2) = path.strip_prefix(cwd) { - path = path2.to_path_buf(); - } + if let Ok(cwd) = cwd + && let Ok(path2) = path.strip_prefix(cwd) + { + path = path2.to_path_buf(); } path.display().to_string() }); diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 5e4a1c7d9f0..9ce3abbcf2c 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -107,18 +107,18 @@ pub fn prebuilt_llvm_config( // If we're using a custom LLVM bail out here, but we can only use a // custom LLVM for the build triple. - if let Some(config) = builder.config.target_config.get(&target) { - if let Some(ref s) = config.llvm_config { - check_llvm_version(builder, s); - let llvm_config = s.to_path_buf(); - let mut llvm_cmake_dir = llvm_config.clone(); - llvm_cmake_dir.pop(); - llvm_cmake_dir.pop(); - llvm_cmake_dir.push("lib"); - llvm_cmake_dir.push("cmake"); - llvm_cmake_dir.push("llvm"); - return LlvmBuildStatus::AlreadyBuilt(LlvmResult { llvm_config, llvm_cmake_dir }); - } + if let Some(config) = builder.config.target_config.get(&target) + && let Some(ref s) = config.llvm_config + { + check_llvm_version(builder, s); + let llvm_config = s.to_path_buf(); + let mut llvm_cmake_dir = llvm_config.clone(); + llvm_cmake_dir.pop(); + llvm_cmake_dir.pop(); + llvm_cmake_dir.push("lib"); + llvm_cmake_dir.push("cmake"); + llvm_cmake_dir.push("llvm"); + return LlvmBuildStatus::AlreadyBuilt(LlvmResult { llvm_config, llvm_cmake_dir }); } if handle_submodule_when_needed { @@ -467,10 +467,10 @@ impl Step for Llvm { cfg.define("LLVM_ENABLE_RUNTIMES", enabled_llvm_runtimes.join(";")); } - if let Some(num_linkers) = builder.config.llvm_link_jobs { - if num_linkers > 0 { - cfg.define("LLVM_PARALLEL_LINK_JOBS", num_linkers.to_string()); - } + if let Some(num_linkers) = builder.config.llvm_link_jobs + && num_linkers > 0 + { + cfg.define("LLVM_PARALLEL_LINK_JOBS", num_linkers.to_string()); } // https://llvm.org/docs/HowToCrossCompileLLVM.html @@ -596,10 +596,10 @@ fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) { let version = get_llvm_version(builder, llvm_config); let mut parts = version.split('.').take(2).filter_map(|s| s.parse::<u32>().ok()); - if let (Some(major), Some(_minor)) = (parts.next(), parts.next()) { - if major >= 19 { - return; - } + if let (Some(major), Some(_minor)) = (parts.next(), parts.next()) + && major >= 19 + { + return; } panic!("\n\nbad LLVM version: {version}, need >=19\n\n") } @@ -729,11 +729,9 @@ fn configure_cmake( // If ccache is configured we inform the build a little differently how // to invoke ccache while also invoking our compilers. - if use_compiler_launcher { - if let Some(ref ccache) = builder.config.ccache { - cfg.define("CMAKE_C_COMPILER_LAUNCHER", ccache) - .define("CMAKE_CXX_COMPILER_LAUNCHER", ccache); - } + if use_compiler_launcher && let Some(ref ccache) = builder.config.ccache { + cfg.define("CMAKE_C_COMPILER_LAUNCHER", ccache) + .define("CMAKE_CXX_COMPILER_LAUNCHER", ccache); } cfg.define("CMAKE_C_COMPILER", sanitize_cc(&cc)) .define("CMAKE_CXX_COMPILER", sanitize_cc(&cxx)) @@ -791,20 +789,20 @@ fn configure_cmake( cxxflags.push(format!(" --target={target}")); } cfg.define("CMAKE_CXX_FLAGS", cxxflags); - if let Some(ar) = builder.ar(target) { - if ar.is_absolute() { - // LLVM build breaks if `CMAKE_AR` is a relative path, for some reason it - // tries to resolve this path in the LLVM build directory. - cfg.define("CMAKE_AR", sanitize_cc(&ar)); - } + if let Some(ar) = builder.ar(target) + && ar.is_absolute() + { + // LLVM build breaks if `CMAKE_AR` is a relative path, for some reason it + // tries to resolve this path in the LLVM build directory. + cfg.define("CMAKE_AR", sanitize_cc(&ar)); } - if let Some(ranlib) = builder.ranlib(target) { - if ranlib.is_absolute() { - // LLVM build breaks if `CMAKE_RANLIB` is a relative path, for some reason it - // tries to resolve this path in the LLVM build directory. - cfg.define("CMAKE_RANLIB", sanitize_cc(&ranlib)); - } + if let Some(ranlib) = builder.ranlib(target) + && ranlib.is_absolute() + { + // LLVM build breaks if `CMAKE_RANLIB` is a relative path, for some reason it + // tries to resolve this path in the LLVM build directory. + cfg.define("CMAKE_RANLIB", sanitize_cc(&ranlib)); } if let Some(ref flags) = builder.config.llvm_ldflags { @@ -1037,13 +1035,14 @@ impl Step for Lld { // when doing PGO on CI, cmake or clang-cl don't automatically link clang's // profiler runtime in. In that case, we need to manually ask cmake to do it, to avoid // linking errors, much like LLVM's cmake setup does in that situation. - if builder.config.llvm_profile_generate && target.is_msvc() { - if let Some(clang_cl_path) = builder.config.llvm_clang_cl.as_ref() { - // Find clang's runtime library directory and push that as a search path to the - // cmake linker flags. - let clang_rt_dir = get_clang_cl_resource_dir(builder, clang_cl_path); - ldflags.push_all(format!("/libpath:{}", clang_rt_dir.display())); - } + if builder.config.llvm_profile_generate + && target.is_msvc() + && let Some(clang_cl_path) = builder.config.llvm_clang_cl.as_ref() + { + // Find clang's runtime library directory and push that as a search path to the + // cmake linker flags. + let clang_rt_dir = get_clang_cl_resource_dir(builder, clang_cl_path); + ldflags.push_all(format!("/libpath:{}", clang_rt_dir.display())); } // LLD is built as an LLVM tool, but is distributed outside of the `llvm-tools` component, diff --git a/src/bootstrap/src/core/build_steps/perf.rs b/src/bootstrap/src/core/build_steps/perf.rs index 71cdb665ed4..14c7b7cf5e9 100644 --- a/src/bootstrap/src/core/build_steps/perf.rs +++ b/src/bootstrap/src/core/build_steps/perf.rs @@ -154,10 +154,10 @@ Consider setting `rust.debuginfo-level = 1` in `bootstrap.toml`."#); let compiler = builder.compiler(builder.top_stage, builder.config.build); builder.ensure(Std::new(compiler, builder.config.build)); - if let Some(opts) = args.cmd.shared_opts() { - if opts.profiles.contains(&Profile::Doc) { - builder.ensure(Rustdoc { compiler }); - } + if let Some(opts) = args.cmd.shared_opts() + && opts.profiles.contains(&Profile::Doc) + { + builder.ensure(Rustdoc { compiler }); } let sysroot = builder.ensure(Sysroot::new(compiler)); diff --git a/src/bootstrap/src/core/build_steps/setup.rs b/src/bootstrap/src/core/build_steps/setup.rs index 5e22c2d1acb..25adfdf1601 100644 --- a/src/bootstrap/src/core/build_steps/setup.rs +++ b/src/bootstrap/src/core/build_steps/setup.rs @@ -241,10 +241,10 @@ impl Step for Link { if run.builder.config.dry_run() { return; } - if let [cmd] = &run.paths[..] { - if cmd.assert_single_path().path.as_path().as_os_str() == "link" { - run.builder.ensure(Link); - } + if let [cmd] = &run.paths[..] + && cmd.assert_single_path().path.as_path().as_os_str() == "link" + { + run.builder.ensure(Link); } } fn run(self, builder: &Builder<'_>) -> Self::Output { @@ -457,10 +457,10 @@ impl Step for Hook { } fn make_run(run: RunConfig<'_>) { - if let [cmd] = &run.paths[..] { - if cmd.assert_single_path().path.as_path().as_os_str() == "hook" { - run.builder.ensure(Hook); - } + if let [cmd] = &run.paths[..] + && cmd.assert_single_path().path.as_path().as_os_str() == "hook" + { + run.builder.ensure(Hook); } } @@ -672,10 +672,10 @@ impl Step for Editor { if run.builder.config.dry_run() { return; } - if let [cmd] = &run.paths[..] { - if cmd.assert_single_path().path.as_path().as_os_str() == "editor" { - run.builder.ensure(Editor); - } + if let [cmd] = &run.paths[..] + && cmd.assert_single_path().path.as_path().as_os_str() == "editor" + { + run.builder.ensure(Editor); } } diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 1392f2c576c..b0eee8765ef 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -2417,10 +2417,10 @@ impl Step for ErrorIndex { } fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool { - if let Ok(contents) = fs::read_to_string(markdown) { - if !contents.contains("```") { - return true; - } + if let Ok(contents) = fs::read_to_string(markdown) + && !contents.contains("```") + { + return true; } builder.verbose(|| println!("doc tests for: {}", markdown.display())); diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs index e41f6f16b02..bac1288fb7f 100644 --- a/src/bootstrap/src/core/builder/cargo.rs +++ b/src/bootstrap/src/core/builder/cargo.rs @@ -988,15 +988,15 @@ impl Builder<'_> { // requirement, but the `-L` library path is not propagated across // separate Cargo projects. We can add LLVM's library path to the // rustc args as a workaround. - if mode == Mode::ToolRustc || mode == Mode::Codegen { - if let Some(llvm_config) = self.llvm_config(target) { - let llvm_libdir = - command(llvm_config).arg("--libdir").run_capture_stdout(self).stdout(); - if target.is_msvc() { - rustflags.arg(&format!("-Clink-arg=-LIBPATH:{llvm_libdir}")); - } else { - rustflags.arg(&format!("-Clink-arg=-L{llvm_libdir}")); - } + if (mode == Mode::ToolRustc || mode == Mode::Codegen) + && let Some(llvm_config) = self.llvm_config(target) + { + let llvm_libdir = + command(llvm_config).arg("--libdir").run_capture_stdout(self).stdout(); + if target.is_msvc() { + rustflags.arg(&format!("-Clink-arg=-LIBPATH:{llvm_libdir}")); + } else { + rustflags.arg(&format!("-Clink-arg=-L{llvm_libdir}")); } } @@ -1226,12 +1226,11 @@ impl Builder<'_> { _ => None, }; - if let Some(limit) = limit { - if stage == 0 - || self.config.default_codegen_backend(target).unwrap_or_default() == "llvm" - { - rustflags.arg(&format!("-Cllvm-args=-import-instr-limit={limit}")); - } + if let Some(limit) = limit + && (stage == 0 + || self.config.default_codegen_backend(target).unwrap_or_default() == "llvm") + { + rustflags.arg(&format!("-Cllvm-args=-import-instr-limit={limit}")); } } diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 4c8862dc709..899ffde8adf 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -1700,20 +1700,20 @@ impl Config { }; // We want to be able to set string values without quotes, // like in `configure.py`. Try adding quotes around the right hand side - if let Some((key, value)) = option.split_once('=') { - if !value.contains('"') { - match get_table(&format!(r#"{key}="{value}""#)) { - Ok(v) => { - override_toml.merge( - None, - &mut Default::default(), - v, - ReplaceOpt::ErrorOnDuplicate, - ); - continue; - } - Err(e) => err = e, + if let Some((key, value)) = option.split_once('=') + && !value.contains('"') + { + match get_table(&format!(r#"{key}="{value}""#)) { + Ok(v) => { + override_toml.merge( + None, + &mut Default::default(), + v, + ReplaceOpt::ErrorOnDuplicate, + ); + continue; } + Err(e) => err = e, } } eprintln!("failed to parse override `{option}`: `{err}"); @@ -2057,16 +2057,15 @@ impl Config { || (matches!(debug_toml, Some(true)) && !matches!(rustc_debug_assertions_toml, Some(false))); - if debug_assertions_requested { - if let Some(ref opt) = download_rustc { - if opt.is_string_or_true() { - eprintln!( - "WARN: currently no CI rustc builds have rustc debug assertions \ + if debug_assertions_requested + && let Some(ref opt) = download_rustc + && opt.is_string_or_true() + { + eprintln!( + "WARN: currently no CI rustc builds have rustc debug assertions \ enabled. Please either set `rust.debug-assertions` to `false` if you \ want to use download CI rustc or set `rust.download-rustc` to `false`." - ); - } - } + ); } config.download_rustc_commit = config.download_ci_rustc_commit( @@ -2177,19 +2176,17 @@ impl Config { // We need to override `rust.channel` if it's manually specified when using the CI rustc. // This is because if the compiler uses a different channel than the one specified in bootstrap.toml, // tests may fail due to using a different channel than the one used by the compiler during tests. - if let Some(commit) = &config.download_rustc_commit { - if is_user_configured_rust_channel { - println!( - "WARNING: `rust.download-rustc` is enabled. The `rust.channel` option will be overridden by the CI rustc's channel." - ); + if let Some(commit) = &config.download_rustc_commit + && is_user_configured_rust_channel + { + println!( + "WARNING: `rust.download-rustc` is enabled. The `rust.channel` option will be overridden by the CI rustc's channel." + ); - let channel = config - .read_file_by_commit(Path::new("src/ci/channel"), commit) - .trim() - .to_owned(); + let channel = + config.read_file_by_commit(Path::new("src/ci/channel"), commit).trim().to_owned(); - config.channel = channel; - } + config.channel = channel; } if let Some(llvm) = toml.llvm { @@ -2699,10 +2696,10 @@ impl Config { let bindir = &self.bindir; if bindir.is_absolute() { // Try to make it relative to the prefix. - if let Some(prefix) = &self.prefix { - if let Ok(stripped) = bindir.strip_prefix(prefix) { - return stripped; - } + if let Some(prefix) = &self.prefix + && let Ok(stripped) = bindir.strip_prefix(prefix) + { + return stripped; } } bindir @@ -3480,19 +3477,19 @@ fn check_incompatible_options_for_ci_rustc( // We always build the in-tree compiler on cross targets, so we only care // about the host target here. let host_str = host.to_string(); - if let Some(current_cfg) = current_config_toml.target.as_ref().and_then(|c| c.get(&host_str)) { - if current_cfg.profiler.is_some() { - let ci_target_toml = ci_config_toml.target.as_ref().and_then(|c| c.get(&host_str)); - let ci_cfg = ci_target_toml.ok_or(format!( - "Target specific config for '{host_str}' is not present for CI-rustc" - ))?; + if let Some(current_cfg) = current_config_toml.target.as_ref().and_then(|c| c.get(&host_str)) + && current_cfg.profiler.is_some() + { + let ci_target_toml = ci_config_toml.target.as_ref().and_then(|c| c.get(&host_str)); + let ci_cfg = ci_target_toml.ok_or(format!( + "Target specific config for '{host_str}' is not present for CI-rustc" + ))?; - let profiler = &ci_cfg.profiler; - err!(current_cfg.profiler, profiler, "build"); + let profiler = &ci_cfg.profiler; + err!(current_cfg.profiler, profiler, "build"); - let optimized_compiler_builtins = &ci_cfg.optimized_compiler_builtins; - err!(current_cfg.optimized_compiler_builtins, optimized_compiler_builtins, "build"); - } + let optimized_compiler_builtins = &ci_cfg.optimized_compiler_builtins; + err!(current_cfg.optimized_compiler_builtins, optimized_compiler_builtins, "build"); } let (Some(current_rust_config), Some(ci_rust_config)) = diff --git a/src/bootstrap/src/core/download.rs b/src/bootstrap/src/core/download.rs index 92062544c0f..d942334d1c3 100644 --- a/src/bootstrap/src/core/download.rs +++ b/src/bootstrap/src/core/download.rs @@ -709,10 +709,10 @@ download-rustc = false "; } self.download_file(&format!("{base_url}/{url}"), &tarball, help_on_error); - if let Some(sha256) = checksum { - if !self.verify(&tarball, sha256) { - panic!("failed to verify {}", tarball.display()); - } + if let Some(sha256) = checksum + && !self.verify(&tarball, sha256) + { + panic!("failed to verify {}", tarball.display()); } self.unpack(&tarball, &bin_root, prefix); diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 7cce14841eb..e4643653d97 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -1451,23 +1451,23 @@ Executed at: {executed_at}"#, // Look for Wasmtime, and for its default options be sure to disable // its caching system since we're executing quite a lot of tests and // ideally shouldn't pollute the cache too much. - if let Some(path) = finder.maybe_have("wasmtime") { - if let Ok(mut path) = path.into_os_string().into_string() { - path.push_str(" run -C cache=n --dir ."); - // Make sure that tests have access to RUSTC_BOOTSTRAP. This (for example) is - // required for libtest to work on beta/stable channels. - // - // NB: with Wasmtime 20 this can change to `-S inherit-env` to - // inherit the entire environment rather than just this single - // environment variable. - path.push_str(" --env RUSTC_BOOTSTRAP"); - - if target.contains("wasip2") { - path.push_str(" --wasi inherit-network --wasi allow-ip-name-lookup"); - } - - return Some(path); + if let Some(path) = finder.maybe_have("wasmtime") + && let Ok(mut path) = path.into_os_string().into_string() + { + path.push_str(" run -C cache=n --dir ."); + // Make sure that tests have access to RUSTC_BOOTSTRAP. This (for example) is + // required for libtest to work on beta/stable channels. + // + // NB: with Wasmtime 20 this can change to `-S inherit-env` to + // inherit the entire environment rather than just this single + // environment variable. + path.push_str(" --env RUSTC_BOOTSTRAP"); + + if target.contains("wasip2") { + path.push_str(" --wasi inherit-network --wasi allow-ip-name-lookup"); } + + return Some(path); } None @@ -1637,12 +1637,12 @@ Executed at: {executed_at}"#, /// sha, version, etc. fn rust_version(&self) -> String { let mut version = self.rust_info().version(self, &self.version); - if let Some(ref s) = self.config.description { - if !s.is_empty() { - version.push_str(" ("); - version.push_str(s); - version.push(')'); - } + if let Some(ref s) = self.config.description + && !s.is_empty() + { + version.push_str(" ("); + version.push_str(s); + version.push(')'); } version } @@ -1760,14 +1760,14 @@ Executed at: {executed_at}"#, pub fn copy_link(&self, src: &Path, dst: &Path, file_type: FileType) { self.copy_link_internal(src, dst, false); - if file_type.could_have_split_debuginfo() { - if let Some(dbg_file) = split_debuginfo(src) { - self.copy_link_internal( - &dbg_file, - &dst.with_extension(dbg_file.extension().unwrap()), - false, - ); - } + if file_type.could_have_split_debuginfo() + && let Some(dbg_file) = split_debuginfo(src) + { + self.copy_link_internal( + &dbg_file, + &dst.with_extension(dbg_file.extension().unwrap()), + false, + ); } } @@ -1779,13 +1779,14 @@ Executed at: {executed_at}"#, if src == dst { return; } - if let Err(e) = fs::remove_file(dst) { - if cfg!(windows) && e.kind() != io::ErrorKind::NotFound { - // workaround for https://github.com/rust-lang/rust/issues/127126 - // if removing the file fails, attempt to rename it instead. - let now = t!(SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)); - let _ = fs::rename(dst, format!("{}-{}", dst.display(), now.as_nanos())); - } + if let Err(e) = fs::remove_file(dst) + && cfg!(windows) + && e.kind() != io::ErrorKind::NotFound + { + // workaround for https://github.com/rust-lang/rust/issues/127126 + // if removing the file fails, attempt to rename it instead. + let now = t!(SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)); + let _ = fs::rename(dst, format!("{}-{}", dst.display(), now.as_nanos())); } let metadata = t!(src.symlink_metadata(), format!("src = {}", src.display())); let mut src = src.to_path_buf(); @@ -1894,10 +1895,10 @@ Executed at: {executed_at}"#, chmod(&dst, file_type.perms()); // If this file can have debuginfo, look for split debuginfo and install it too. - if file_type.could_have_split_debuginfo() { - if let Some(dbg_file) = split_debuginfo(src) { - self.install(&dbg_file, dstdir, FileType::Regular); - } + if file_type.could_have_split_debuginfo() + && let Some(dbg_file) = split_debuginfo(src) + { + self.install(&dbg_file, dstdir, FileType::Regular); } } diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index 393359512fc..459a34d14cc 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -46,10 +46,10 @@ pub fn find_recent_config_change_ids(current_id: usize) -> &'static [ChangeInfo] // an empty list (it may be due to switching from a recent branch to an // older one); otherwise, return the full list (assuming the user provided // the incorrect change-id by accident). - if let Some(config) = CONFIG_CHANGE_HISTORY.iter().max_by_key(|config| config.change_id) { - if current_id > config.change_id { - return &[]; - } + if let Some(config) = CONFIG_CHANGE_HISTORY.iter().max_by_key(|config| config.change_id) + && current_id > config.change_id + { + return &[]; } CONFIG_CHANGE_HISTORY |
