Skip to content

Commit 0722f87

Browse files
authored
Merge pull request #2625 from kinnison/cleanups
Cleanups
2 parents ecd6cb3 + 088c886 commit 0722f87

File tree

10 files changed

+353
-455
lines changed

10 files changed

+353
-455
lines changed

Cargo.lock

Lines changed: 312 additions & 409 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ xz2 = "0.1.3"
6666

6767
[dependencies.retry]
6868
default-features = false
69+
features = ["random"]
6970
version = "1"
7071

7172
[dependencies.rs_tracing]

src/cli/rustup_mode.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ pub fn main() -> Result<utils::ExitCode> {
9797
return Ok(utils::ExitCode(0));
9898
}
9999

100-
Err(e) => match &e {
101-
clap::Error { kind, message, .. } => {
100+
Err(e) => {
101+
{
102+
let clap::Error { kind, message, .. } = &e;
102103
if [
103104
InvalidSubcommand,
104105
UnknownArgument,
@@ -109,9 +110,9 @@ pub fn main() -> Result<utils::ExitCode> {
109110
writeln!(process().stdout().lock(), "{}", message)?;
110111
return Ok(utils::ExitCode(1));
111112
}
112-
Err(e)
113113
}
114-
},
114+
Err(e)
115+
}
115116
}?;
116117
let verbose = matches.is_present("verbose");
117118
let quiet = matches.is_present("quiet");
@@ -898,7 +899,7 @@ fn check_updates(cfg: &Cfg) -> Result<utils::ExitCode> {
898899
let available_version = get_available_rustup_version()?;
899900

900901
let _ = t.attr(term2::Attr::Bold);
901-
write!(t, "{} - ", "rustup")?;
902+
write!(t, "rustup - ")?;
902903

903904
if current_version != available_version {
904905
let _ = t.fg(term2::color::YELLOW);
@@ -935,21 +936,18 @@ fn update(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
935936

936937
if toolchain_has_triple {
937938
let host_arch = TargetTriple::from_host_or_build();
938-
match ToolchainDesc::from_str(name) {
939-
Ok(toolchain_desc) => {
940-
let target_triple = toolchain_desc.target;
941-
if host_arch.ne(&target_triple) {
942-
warn!(
943-
"toolchain '{}' may not be able to run on this system.",
944-
name
945-
);
946-
warn!(
947-
"If you meant to build software to target that platform, perhaps try `rustup target add {}` instead?",
948-
target_triple.to_string()
949-
);
950-
}
939+
if let Ok(toolchain_desc) = ToolchainDesc::from_str(name) {
940+
let target_triple = toolchain_desc.target;
941+
if host_arch.ne(&target_triple) {
942+
warn!(
943+
"toolchain '{}' may not be able to run on this system.",
944+
name
945+
);
946+
warn!(
947+
"If you meant to build software to target that platform, perhaps try `rustup target add {}` instead?",
948+
target_triple.to_string()
949+
);
951950
}
952-
_ => (),
953951
}
954952
}
955953

src/dist/component/package.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use std::collections::{HashMap, HashSet};
66
use std::fmt;
77
use std::io::{self, ErrorKind as IOErrorKind, Read};
8-
use std::iter::FromIterator;
98
use std::mem;
109
use std::path::{Path, PathBuf};
1110

@@ -273,7 +272,7 @@ fn trigger_children(
273272
.or_insert_with(|| unreachable!());
274273
result += pending.len();
275274
for pending_item in pending.into_iter() {
276-
for mut item in Vec::from_iter(io_executor.execute(pending_item)) {
275+
for mut item in io_executor.execute(pending_item).collect::<Vec<_>>() {
277276
// TODO capture metrics
278277
budget.reclaim(&item);
279278
filter_result(&mut item).chain_err(|| ErrorKind::ExtractingPackage)?;
@@ -319,11 +318,11 @@ fn unpack_without_first_dir<'a, R: Read>(
319318
// drain completed results to keep memory pressure low and respond
320319
// rapidly to completed events even if we couldn't submit work (because
321320
// our unpacked item is pending dequeue)
322-
for mut item in Vec::from_iter(io_executor.completed()) {
321+
for mut item in io_executor.completed().collect::<Vec<_>>() {
323322
// TODO capture metrics
324323
budget.reclaim(&item);
325324
filter_result(&mut item).chain_err(|| ErrorKind::ExtractingPackage)?;
326-
trigger_children(&mut *io_executor, &mut directories, &mut budget, item)?;
325+
trigger_children(&*io_executor, &mut directories, &mut budget, item)?;
327326
}
328327

329328
let mut entry = entry.chain_err(|| ErrorKind::ExtractingPackage)?;
@@ -369,7 +368,7 @@ fn unpack_without_first_dir<'a, R: Read>(
369368
io_executor: &dyn Executor,
370369
mut directories: &mut HashMap<PathBuf, DirStatus>,
371370
) -> Result<()> {
372-
for mut item in Vec::from_iter(io_executor.completed()) {
371+
for mut item in io_executor.completed().collect::<Vec<_>>() {
373372
// TODO capture metrics
374373
budget.reclaim(&item);
375374
filter_result(&mut item).chain_err(|| ErrorKind::ExtractingPackage)?;
@@ -457,22 +456,22 @@ fn unpack_without_first_dir<'a, R: Read>(
457456
}
458457
};
459458

460-
for mut item in Vec::from_iter(io_executor.execute(item)) {
459+
for mut item in io_executor.execute(item).collect::<Vec<_>>() {
461460
// TODO capture metrics
462461
budget.reclaim(&item);
463462
filter_result(&mut item).chain_err(|| ErrorKind::ExtractingPackage)?;
464-
trigger_children(&mut *io_executor, &mut directories, &mut budget, item)?;
463+
trigger_children(&*io_executor, &mut directories, &mut budget, item)?;
465464
}
466465
}
467466

468467
loop {
469468
let mut triggered = 0;
470-
for mut item in Vec::from_iter(io_executor.join()) {
469+
for mut item in io_executor.join().collect::<Vec<_>>() {
471470
// handle final IOs
472471
// TODO capture metrics
473472
budget.reclaim(&item);
474473
filter_result(&mut item).chain_err(|| ErrorKind::ExtractingPackage)?;
475-
triggered += trigger_children(&mut *io_executor, &mut directories, &mut budget, item)?;
474+
triggered += trigger_children(&*io_executor, &mut directories, &mut budget, item)?;
476475
}
477476
if triggered == 0 {
478477
// None of the IO submitted before the prior join triggered any new

src/dist/dist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl FromStr for ParsedToolchainDesc {
107107

108108
let d = TOOLCHAIN_CHANNEL_RE.captures(desc).map(|c| {
109109
fn fn_map(s: &str) -> Option<String> {
110-
if s == "" {
110+
if s.is_empty() {
111111
None
112112
} else {
113113
Some(s.to_owned())
@@ -858,7 +858,7 @@ pub fn dl_v2_manifest<'a>(
858858
}
859859
}
860860

861-
fn dl_v1_manifest<'a>(download: DownloadCfg<'a>, toolchain: &ToolchainDesc) -> Result<Vec<String>> {
861+
fn dl_v1_manifest(download: DownloadCfg<'_>, toolchain: &ToolchainDesc) -> Result<Vec<String>> {
862862
let root_url = toolchain.package_dir(download.dist_root);
863863

864864
if !["nightly", "beta", "stable"].contains(&&*toolchain.channel) {

src/dist/notifications.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'a> Display for Notification<'a> {
186186
if component.target.as_ref() != Some(&toolchain.target) {
187187
component.name(manifest)
188188
} else {
189-
component.short_name(manifest).to_owned()
189+
component.short_name(manifest)
190190
}
191191
})
192192
.collect::<Vec<_>>()

src/dist/triple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl PartialTargetTriple {
7777
}
7878
RE.captures(&name).map(|c| {
7979
fn fn_map(s: &str) -> Option<String> {
80-
if s == "" {
80+
if s.is_empty() {
8181
None
8282
} else {
8383
Some(s.to_owned())

src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,9 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: &
423423
let mut buf = vec![];
424424

425425
if cs.len() == 1 {
426-
let _ = write!(
426+
let _ = writeln!(
427427
buf,
428-
"component {} is unavailable for download for channel '{}'\n",
428+
"component {} is unavailable for download for channel '{}'",
429429
&cs[0].description(manifest),
430430
toolchain,
431431
);

src/utils/units.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ mod tests {
8383

8484
// Test Bytes
8585
assert_eq!(
86-
format!("{}", Size::new(1 as usize, Unit::B, UnitMode::Norm)),
86+
format!("{}", Size::new(1, Unit::B, UnitMode::Norm)),
8787
" 1 B"
8888
);
8989
assert_eq!(
90-
format!("{}", Size::new(1024 as usize, Unit::B, UnitMode::Norm)),
90+
format!("{}", Size::new(1024, Unit::B, UnitMode::Norm)),
9191
" 1.0 KiB"
9292
);
9393
assert_eq!(
@@ -101,11 +101,11 @@ mod tests {
101101

102102
// Test Bytes at given rate
103103
assert_eq!(
104-
format!("{}", Size::new(1 as usize, Unit::B, UnitMode::Rate)),
104+
format!("{}", Size::new(1, Unit::B, UnitMode::Rate)),
105105
" 1 B/s"
106106
);
107107
assert_eq!(
108-
format!("{}", Size::new(1024 as usize, Unit::B, UnitMode::Rate)),
108+
format!("{}", Size::new(1024, Unit::B, UnitMode::Rate)),
109109
" 1.0 KiB/s"
110110
);
111111
assert_eq!(
@@ -119,11 +119,11 @@ mod tests {
119119

120120
//Test I/O Operations
121121
assert_eq!(
122-
format!("{}", Size::new(1 as usize, Unit::IO, UnitMode::Norm)),
122+
format!("{}", Size::new(1, Unit::IO, UnitMode::Norm)),
123123
" 1 IO-ops"
124124
);
125125
assert_eq!(
126-
format!("{}", Size::new(1000 as usize, Unit::IO, UnitMode::Norm)),
126+
format!("{}", Size::new(1000, Unit::IO, UnitMode::Norm)),
127127
" 1.0 kilo-IO-ops"
128128
);
129129
assert_eq!(
@@ -137,11 +137,11 @@ mod tests {
137137

138138
//Test I/O Operations at given rate
139139
assert_eq!(
140-
format!("{}", Size::new(1 as usize, Unit::IO, UnitMode::Rate)),
140+
format!("{}", Size::new(1, Unit::IO, UnitMode::Rate)),
141141
" 1 IOPS"
142142
);
143143
assert_eq!(
144-
format!("{}", Size::new(1000 as usize, Unit::IO, UnitMode::Rate)),
144+
format!("{}", Size::new(1000, Unit::IO, UnitMode::Rate)),
145145
" 1.0 kilo-IOPS"
146146
);
147147
assert_eq!(

tests/cli-paths.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ export PATH="$HOME/apple/bin"
5353
let mut rcs = files.iter();
5454
let env = rcs.next().unwrap();
5555
let envfile = fs::read_to_string(&env).unwrap();
56-
let (_, envfile_export) = envfile.split_at(match envfile.find("export PATH") {
57-
Some(idx) => idx,
58-
None => 0,
59-
});
56+
let (_, envfile_export) = envfile.split_at(envfile.find("export PATH").unwrap_or(0));
6057
assert_eq!(&envfile_export[..DEFAULT_EXPORT.len()], DEFAULT_EXPORT);
6158

6259
for rc in rcs {

0 commit comments

Comments
 (0)