Skip to content

Commit 8e3ff89

Browse files
authored
Merge pull request #151 from kraktus/trivial_refractoring
various small refactoring
2 parents f480f5f + bdf8e03 commit 8e3ff89

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

src/main.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ impl Config {
445445
}
446446

447447
let target = args.target.clone().unwrap_or_else(|| args.host.clone());
448-
let mut args = args;
449448

450449
let mut toolchains_path = home::rustup_home()?;
451450

@@ -521,35 +520,33 @@ impl Config {
521520
fn check_bounds(start: &Option<Bound>, end: &Option<Bound>) -> Result<(), Error> {
522521
// current UTC date
523522
let current = Utc::now().date();
524-
match (&start, &end) {
523+
match start.as_ref().zip(end.as_ref()) {
525524
// start date is after end date
526-
(Some(Bound::Date(start)), Some(Bound::Date(end))) if end < start => {
525+
Some((Bound::Date(start), Bound::Date(end))) if end < &start => {
527526
bail!(
528527
"end should be after start, got start: {} and end {}",
529528
start,
530529
end
531530
);
532531
}
533532
// start date is after current date
534-
(Some(Bound::Date(start)), Some(Bound::Date(_end))) if start > &current => {
533+
Some((Bound::Date(start), _)) if start > &current => {
535534
bail!(
536535
"start date should be on or before current date, got start date request: {} and current date is {}",
537536
start,
538537
current
539538
);
540539
}
541540
// end date is after current date
542-
(Some(Bound::Date(_start)), Some(Bound::Date(end))) if end > &current => {
541+
Some((_, Bound::Date(end))) if end > &current => {
543542
bail!(
544543
"end date should be on or before current date, got start date request: {} and current date is {}",
545544
end,
546545
current
547546
);
548547
}
549-
_ => {}
548+
_ => Ok(()),
550549
}
551-
552-
Ok(())
553550
}
554551

555552
// Application entry point

src/toolchains.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,7 @@ impl Toolchain {
281281
.map_err(InstallError::Download)?;
282282
}
283283

284-
fs::rename(tmpdir.into_path(), dest).map_err(InstallError::Move)?;
285-
286-
Ok(())
284+
fs::rename(tmpdir.into_path(), dest).map_err(InstallError::Move)
287285
}
288286

289287
pub(crate) fn remove(&self, dl_params: &DownloadParams) -> Result<(), Error> {
@@ -305,7 +303,6 @@ impl Toolchain {
305303

306304
let dir = dl_params.install_dir.join(rustup_name);
307305
fs::remove_dir_all(&dir)?;
308-
309306
Ok(())
310307
}
311308

@@ -363,14 +360,12 @@ impl Toolchain {
363360
let must_capture_output = cfg.regress_on().must_process_stderr();
364361
let emit_output = cfg.args.emit_cargo_output() || cfg.args.prompt;
365362

366-
let default_stdio = || {
367-
if must_capture_output {
368-
Stdio::piped()
369-
} else if emit_output {
370-
Stdio::inherit()
371-
} else {
372-
Stdio::null()
373-
}
363+
let default_stdio = if must_capture_output {
364+
Stdio::piped
365+
} else if emit_output {
366+
Stdio::inherit
367+
} else {
368+
Stdio::null
374369
};
375370

376371
cmd.stdout(default_stdio());
@@ -553,8 +548,7 @@ pub(crate) fn download_tar_xz(
553548
let (response, mut bar) = download_progress(client, name, url)?;
554549
let response = TeeReader::new(response, &mut bar);
555550
let response = XzDecoder::new(response);
556-
unarchive(response, strip_prefix, dest).map_err(DownloadError::Archive)?;
557-
Ok(())
551+
unarchive(response, strip_prefix, dest).map_err(DownloadError::Archive)
558552
}
559553

560554
pub(crate) fn download_tar_gz(
@@ -567,8 +561,7 @@ pub(crate) fn download_tar_gz(
567561
let (response, mut bar) = download_progress(client, name, url)?;
568562
let response = TeeReader::new(response, &mut bar);
569563
let response = GzDecoder::new(response);
570-
unarchive(response, strip_prefix, dest).map_err(DownloadError::Archive)?;
571-
Ok(())
564+
unarchive(response, strip_prefix, dest).map_err(DownloadError::Archive)
572565
}
573566

574567
pub(crate) fn unarchive<R: Read>(

0 commit comments

Comments
 (0)