Skip to content

Commit 2a4e930

Browse files
committed
fix clippy warnings
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent 2e36e0e commit 2a4e930

File tree

13 files changed

+230
-235
lines changed

13 files changed

+230
-235
lines changed

src/bootstrap/src/bin/rustc.rs

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,12 @@ fn main() {
120120
};
121121
cmd.args(&args).env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
122122

123-
if let Some(crate_name) = crate_name {
124-
if let Some(target) = env::var_os("RUSTC_TIME") {
125-
if target == "all"
126-
|| target.into_string().unwrap().split(',').any(|c| c.trim() == crate_name)
127-
{
128-
cmd.arg("-Ztime-passes");
129-
}
130-
}
123+
if let Some(crate_name) = crate_name
124+
&& let Some(target) = env::var_os("RUSTC_TIME")
125+
&& (target == "all"
126+
|| target.into_string().unwrap().split(',').any(|c| c.trim() == crate_name))
127+
{
128+
cmd.arg("-Ztime-passes");
131129
}
132130

133131
// Print backtrace in case of ICE
@@ -242,10 +240,10 @@ fn main() {
242240
}
243241
}
244242

245-
if env::var_os("RUSTC_BOLT_LINK_FLAGS").is_some() {
246-
if let Some("rustc_driver") = crate_name {
247-
cmd.arg("-Clink-args=-Wl,-q");
248-
}
243+
if env::var_os("RUSTC_BOLT_LINK_FLAGS").is_some()
244+
&& let Some("rustc_driver") = crate_name
245+
{
246+
cmd.arg("-Clink-args=-Wl,-q");
249247
}
250248

251249
let is_test = args.iter().any(|a| a == "--test");
@@ -282,25 +280,24 @@ fn main() {
282280
(child, status)
283281
};
284282

285-
if env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some()
286-
|| env::var_os("RUSTC_PRINT_STEP_RUSAGE").is_some()
283+
if (env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some()
284+
|| env::var_os("RUSTC_PRINT_STEP_RUSAGE").is_some())
285+
&& let Some(crate_name) = crate_name
287286
{
288-
if let Some(crate_name) = crate_name {
289-
let dur = start.elapsed();
290-
// If the user requested resource usage data, then
291-
// include that in addition to the timing output.
292-
let rusage_data =
293-
env::var_os("RUSTC_PRINT_STEP_RUSAGE").and_then(|_| format_rusage_data(child));
294-
eprintln!(
295-
"[RUSTC-TIMING] {} test:{} {}.{:03}{}{}",
296-
crate_name,
297-
is_test,
298-
dur.as_secs(),
299-
dur.subsec_millis(),
300-
if rusage_data.is_some() { " " } else { "" },
301-
rusage_data.unwrap_or_default(),
302-
);
303-
}
287+
let dur = start.elapsed();
288+
// If the user requested resource usage data, then
289+
// include that in addition to the timing output.
290+
let rusage_data =
291+
env::var_os("RUSTC_PRINT_STEP_RUSAGE").and_then(|_| format_rusage_data(child));
292+
eprintln!(
293+
"[RUSTC-TIMING] {} test:{} {}.{:03}{}{}",
294+
crate_name,
295+
is_test,
296+
dur.as_secs(),
297+
dur.subsec_millis(),
298+
if rusage_data.is_some() { " " } else { "" },
299+
rusage_data.unwrap_or_default(),
300+
);
304301
}
305302

306303
if status.success() {

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -626,18 +626,18 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
626626

627627
// Help the libc crate compile by assisting it in finding various
628628
// sysroot native libraries.
629-
if target.contains("musl") {
630-
if let Some(p) = builder.musl_libdir(target) {
631-
let root = format!("native={}", p.to_str().unwrap());
632-
cargo.rustflag("-L").rustflag(&root);
633-
}
629+
if target.contains("musl")
630+
&& let Some(p) = builder.musl_libdir(target)
631+
{
632+
let root = format!("native={}", p.to_str().unwrap());
633+
cargo.rustflag("-L").rustflag(&root);
634634
}
635635

636-
if target.contains("-wasi") {
637-
if let Some(dir) = builder.wasi_libdir(target) {
638-
let root = format!("native={}", dir.to_str().unwrap());
639-
cargo.rustflag("-L").rustflag(&root);
640-
}
636+
if target.contains("-wasi")
637+
&& let Some(dir) = builder.wasi_libdir(target)
638+
{
639+
let root = format!("native={}", dir.to_str().unwrap());
640+
cargo.rustflag("-L").rustflag(&root);
641641
}
642642
}
643643

@@ -1391,12 +1391,13 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
13911391
// found. This is to avoid the linker errors about undefined references to
13921392
// `__llvm_profile_instrument_memop` when linking `rustc_driver`.
13931393
let mut llvm_linker_flags = String::new();
1394-
if builder.config.llvm_profile_generate && target.is_msvc() {
1395-
if let Some(ref clang_cl_path) = builder.config.llvm_clang_cl {
1396-
// Add clang's runtime library directory to the search path
1397-
let clang_rt_dir = get_clang_cl_resource_dir(builder, clang_cl_path);
1398-
llvm_linker_flags.push_str(&format!("-L{}", clang_rt_dir.display()));
1399-
}
1394+
if builder.config.llvm_profile_generate
1395+
&& target.is_msvc()
1396+
&& let Some(ref clang_cl_path) = builder.config.llvm_clang_cl
1397+
{
1398+
// Add clang's runtime library directory to the search path
1399+
let clang_rt_dir = get_clang_cl_resource_dir(builder, clang_cl_path);
1400+
llvm_linker_flags.push_str(&format!("-L{}", clang_rt_dir.display()));
14001401
}
14011402

14021403
// The config can also specify its own llvm linker flags.

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,11 +2275,12 @@ impl Step for LlvmTools {
22752275
let target = self.target;
22762276

22772277
// Run only if a custom llvm-config is not used
2278-
if let Some(config) = builder.config.target_config.get(&target) {
2279-
if !builder.config.llvm_from_ci && config.llvm_config.is_some() {
2280-
builder.info(&format!("Skipping LlvmTools ({target}): external LLVM"));
2281-
return None;
2282-
}
2278+
if let Some(config) = builder.config.target_config.get(&target)
2279+
&& !builder.config.llvm_from_ci
2280+
&& config.llvm_config.is_some()
2281+
{
2282+
builder.info(&format!("Skipping LlvmTools ({target}): external LLVM"));
2283+
return None;
22832284
}
22842285

22852286
builder.ensure(crate::core::build_steps::llvm::Llvm { target });
@@ -2393,11 +2394,11 @@ impl Step for RustDev {
23932394
let target = self.target;
23942395

23952396
/* run only if llvm-config isn't used */
2396-
if let Some(config) = builder.config.target_config.get(&target) {
2397-
if let Some(ref _s) = config.llvm_config {
2398-
builder.info(&format!("Skipping RustDev ({target}): external LLVM"));
2399-
return None;
2400-
}
2397+
if let Some(config) = builder.config.target_config.get(&target)
2398+
&& let Some(ref _s) = config.llvm_config
2399+
{
2400+
builder.info(&format!("Skipping RustDev ({target}): external LLVM"));
2401+
return None;
24012402
}
24022403

24032404
let mut tarball = Tarball::new(builder, "rust-dev", &target.triple);

src/bootstrap/src/core/build_steps/format.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,10 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
318318
// `into_path` produces an absolute path. Try to strip `cwd` to get a shorter
319319
// relative path.
320320
let mut path = entry.clone().into_path();
321-
if let Ok(cwd) = cwd {
322-
if let Ok(path2) = path.strip_prefix(cwd) {
323-
path = path2.to_path_buf();
324-
}
321+
if let Ok(cwd) = cwd
322+
&& let Ok(path2) = path.strip_prefix(cwd)
323+
{
324+
path = path2.to_path_buf();
325325
}
326326
path.display().to_string()
327327
});

src/bootstrap/src/core/build_steps/llvm.rs

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,18 @@ pub fn prebuilt_llvm_config(
107107

108108
// If we're using a custom LLVM bail out here, but we can only use a
109109
// custom LLVM for the build triple.
110-
if let Some(config) = builder.config.target_config.get(&target) {
111-
if let Some(ref s) = config.llvm_config {
112-
check_llvm_version(builder, s);
113-
let llvm_config = s.to_path_buf();
114-
let mut llvm_cmake_dir = llvm_config.clone();
115-
llvm_cmake_dir.pop();
116-
llvm_cmake_dir.pop();
117-
llvm_cmake_dir.push("lib");
118-
llvm_cmake_dir.push("cmake");
119-
llvm_cmake_dir.push("llvm");
120-
return LlvmBuildStatus::AlreadyBuilt(LlvmResult { llvm_config, llvm_cmake_dir });
121-
}
110+
if let Some(config) = builder.config.target_config.get(&target)
111+
&& let Some(ref s) = config.llvm_config
112+
{
113+
check_llvm_version(builder, s);
114+
let llvm_config = s.to_path_buf();
115+
let mut llvm_cmake_dir = llvm_config.clone();
116+
llvm_cmake_dir.pop();
117+
llvm_cmake_dir.pop();
118+
llvm_cmake_dir.push("lib");
119+
llvm_cmake_dir.push("cmake");
120+
llvm_cmake_dir.push("llvm");
121+
return LlvmBuildStatus::AlreadyBuilt(LlvmResult { llvm_config, llvm_cmake_dir });
122122
}
123123

124124
if handle_submodule_when_needed {
@@ -467,10 +467,10 @@ impl Step for Llvm {
467467
cfg.define("LLVM_ENABLE_RUNTIMES", enabled_llvm_runtimes.join(";"));
468468
}
469469

470-
if let Some(num_linkers) = builder.config.llvm_link_jobs {
471-
if num_linkers > 0 {
472-
cfg.define("LLVM_PARALLEL_LINK_JOBS", num_linkers.to_string());
473-
}
470+
if let Some(num_linkers) = builder.config.llvm_link_jobs
471+
&& num_linkers > 0
472+
{
473+
cfg.define("LLVM_PARALLEL_LINK_JOBS", num_linkers.to_string());
474474
}
475475

476476
// https://llvm.org/docs/HowToCrossCompileLLVM.html
@@ -596,10 +596,10 @@ fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) {
596596

597597
let version = get_llvm_version(builder, llvm_config);
598598
let mut parts = version.split('.').take(2).filter_map(|s| s.parse::<u32>().ok());
599-
if let (Some(major), Some(_minor)) = (parts.next(), parts.next()) {
600-
if major >= 19 {
601-
return;
602-
}
599+
if let (Some(major), Some(_minor)) = (parts.next(), parts.next())
600+
&& major >= 19
601+
{
602+
return;
603603
}
604604
panic!("\n\nbad LLVM version: {version}, need >=19\n\n")
605605
}
@@ -729,11 +729,9 @@ fn configure_cmake(
729729

730730
// If ccache is configured we inform the build a little differently how
731731
// to invoke ccache while also invoking our compilers.
732-
if use_compiler_launcher {
733-
if let Some(ref ccache) = builder.config.ccache {
734-
cfg.define("CMAKE_C_COMPILER_LAUNCHER", ccache)
735-
.define("CMAKE_CXX_COMPILER_LAUNCHER", ccache);
736-
}
732+
if use_compiler_launcher && let Some(ref ccache) = builder.config.ccache {
733+
cfg.define("CMAKE_C_COMPILER_LAUNCHER", ccache)
734+
.define("CMAKE_CXX_COMPILER_LAUNCHER", ccache);
737735
}
738736
cfg.define("CMAKE_C_COMPILER", sanitize_cc(&cc))
739737
.define("CMAKE_CXX_COMPILER", sanitize_cc(&cxx))
@@ -791,20 +789,20 @@ fn configure_cmake(
791789
cxxflags.push(format!(" --target={target}"));
792790
}
793791
cfg.define("CMAKE_CXX_FLAGS", cxxflags);
794-
if let Some(ar) = builder.ar(target) {
795-
if ar.is_absolute() {
796-
// LLVM build breaks if `CMAKE_AR` is a relative path, for some reason it
797-
// tries to resolve this path in the LLVM build directory.
798-
cfg.define("CMAKE_AR", sanitize_cc(&ar));
799-
}
792+
if let Some(ar) = builder.ar(target)
793+
&& ar.is_absolute()
794+
{
795+
// LLVM build breaks if `CMAKE_AR` is a relative path, for some reason it
796+
// tries to resolve this path in the LLVM build directory.
797+
cfg.define("CMAKE_AR", sanitize_cc(&ar));
800798
}
801799

802-
if let Some(ranlib) = builder.ranlib(target) {
803-
if ranlib.is_absolute() {
804-
// LLVM build breaks if `CMAKE_RANLIB` is a relative path, for some reason it
805-
// tries to resolve this path in the LLVM build directory.
806-
cfg.define("CMAKE_RANLIB", sanitize_cc(&ranlib));
807-
}
800+
if let Some(ranlib) = builder.ranlib(target)
801+
&& ranlib.is_absolute()
802+
{
803+
// LLVM build breaks if `CMAKE_RANLIB` is a relative path, for some reason it
804+
// tries to resolve this path in the LLVM build directory.
805+
cfg.define("CMAKE_RANLIB", sanitize_cc(&ranlib));
808806
}
809807

810808
if let Some(ref flags) = builder.config.llvm_ldflags {
@@ -1037,13 +1035,14 @@ impl Step for Lld {
10371035
// when doing PGO on CI, cmake or clang-cl don't automatically link clang's
10381036
// profiler runtime in. In that case, we need to manually ask cmake to do it, to avoid
10391037
// linking errors, much like LLVM's cmake setup does in that situation.
1040-
if builder.config.llvm_profile_generate && target.is_msvc() {
1041-
if let Some(clang_cl_path) = builder.config.llvm_clang_cl.as_ref() {
1042-
// Find clang's runtime library directory and push that as a search path to the
1043-
// cmake linker flags.
1044-
let clang_rt_dir = get_clang_cl_resource_dir(builder, clang_cl_path);
1045-
ldflags.push_all(format!("/libpath:{}", clang_rt_dir.display()));
1046-
}
1038+
if builder.config.llvm_profile_generate
1039+
&& target.is_msvc()
1040+
&& let Some(clang_cl_path) = builder.config.llvm_clang_cl.as_ref()
1041+
{
1042+
// Find clang's runtime library directory and push that as a search path to the
1043+
// cmake linker flags.
1044+
let clang_rt_dir = get_clang_cl_resource_dir(builder, clang_cl_path);
1045+
ldflags.push_all(format!("/libpath:{}", clang_rt_dir.display()));
10471046
}
10481047

10491048
// LLD is built as an LLVM tool, but is distributed outside of the `llvm-tools` component,

src/bootstrap/src/core/build_steps/perf.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ Consider setting `rust.debuginfo-level = 1` in `bootstrap.toml`."#);
154154
let compiler = builder.compiler(builder.top_stage, builder.config.build);
155155
builder.ensure(Std::new(compiler, builder.config.build));
156156

157-
if let Some(opts) = args.cmd.shared_opts() {
158-
if opts.profiles.contains(&Profile::Doc) {
159-
builder.ensure(Rustdoc { compiler });
160-
}
157+
if let Some(opts) = args.cmd.shared_opts()
158+
&& opts.profiles.contains(&Profile::Doc)
159+
{
160+
builder.ensure(Rustdoc { compiler });
161161
}
162162

163163
let sysroot = builder.ensure(Sysroot::new(compiler));

src/bootstrap/src/core/build_steps/setup.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ impl Step for Link {
241241
if run.builder.config.dry_run() {
242242
return;
243243
}
244-
if let [cmd] = &run.paths[..] {
245-
if cmd.assert_single_path().path.as_path().as_os_str() == "link" {
246-
run.builder.ensure(Link);
247-
}
244+
if let [cmd] = &run.paths[..]
245+
&& cmd.assert_single_path().path.as_path().as_os_str() == "link"
246+
{
247+
run.builder.ensure(Link);
248248
}
249249
}
250250
fn run(self, builder: &Builder<'_>) -> Self::Output {
@@ -457,10 +457,10 @@ impl Step for Hook {
457457
}
458458

459459
fn make_run(run: RunConfig<'_>) {
460-
if let [cmd] = &run.paths[..] {
461-
if cmd.assert_single_path().path.as_path().as_os_str() == "hook" {
462-
run.builder.ensure(Hook);
463-
}
460+
if let [cmd] = &run.paths[..]
461+
&& cmd.assert_single_path().path.as_path().as_os_str() == "hook"
462+
{
463+
run.builder.ensure(Hook);
464464
}
465465
}
466466

@@ -672,10 +672,10 @@ impl Step for Editor {
672672
if run.builder.config.dry_run() {
673673
return;
674674
}
675-
if let [cmd] = &run.paths[..] {
676-
if cmd.assert_single_path().path.as_path().as_os_str() == "editor" {
677-
run.builder.ensure(Editor);
678-
}
675+
if let [cmd] = &run.paths[..]
676+
&& cmd.assert_single_path().path.as_path().as_os_str() == "editor"
677+
{
678+
run.builder.ensure(Editor);
679679
}
680680
}
681681

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,10 +2417,10 @@ impl Step for ErrorIndex {
24172417
}
24182418

24192419
fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) -> bool {
2420-
if let Ok(contents) = fs::read_to_string(markdown) {
2421-
if !contents.contains("```") {
2422-
return true;
2423-
}
2420+
if let Ok(contents) = fs::read_to_string(markdown)
2421+
&& !contents.contains("```")
2422+
{
2423+
return true;
24242424
}
24252425

24262426
builder.verbose(|| println!("doc tests for: {}", markdown.display()));

0 commit comments

Comments
 (0)