Skip to content

Commit 44be718

Browse files
authored
Merge pull request #2744 from hi-rustin/rustin-patch-clippy
Make clippy happy
2 parents 7a051f7 + fb88c80 commit 44be718

File tree

10 files changed

+42
-53
lines changed

10 files changed

+42
-53
lines changed

src/bin/rustup-init.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,7 @@ fn run_rustup_inner() -> Result<utils::ExitCode> {
9494
}
9595
}
9696
Some(n) => {
97-
if TOOLS
98-
.iter()
99-
.chain(DUP_TOOLS.iter())
100-
.find(|&&name| name == n)
101-
.is_some()
102-
{
97+
if TOOLS.iter().chain(DUP_TOOLS.iter()).any(|&name| name == n) {
10398
proxy_mode::main()
10499
} else {
105100
Err(anyhow!(format!(

src/cli/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ pub fn set_globals(verbose: bool, quiet: bool) -> Result<Cfg> {
164164
..Default::default()
165165
});
166166

167-
Ok(Cfg::from_env(Arc::new(move |n: Notification<'_>| {
167+
Cfg::from_env(Arc::new(move |n: Notification<'_>| {
168168
if download_tracker.borrow_mut().handle_notification(&n) {
169169
return;
170170
}
171171
console_notifier.borrow_mut().handle(n);
172-
}))?)
172+
}))
173173
}
174174

175175
pub fn show_channel_update(cfg: &Cfg, name: &str, updated: Result<UpdateStatus>) -> Result<()> {

src/cli/proxy_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ fn direct_proxy(
6060
None => cfg.create_command_for_dir(&utils::current_dir()?, arg0)?,
6161
Some(tc) => cfg.create_command_for_toolchain(tc, false, arg0)?,
6262
};
63-
Ok(run_command_for_dir(cmd, arg0, args)?)
63+
run_command_for_dir(cmd, arg0, args)
6464
}

src/cli/rustup_mode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ fn default_(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
863863
} else {
864864
let default_toolchain: Result<String> = cfg
865865
.get_default()?
866-
.ok_or(anyhow!("no default toolchain configured"));
866+
.ok_or_else(|| anyhow!("no default toolchain configured"));
867867
writeln!(process().stdout(), "{} (default)", default_toolchain?)?;
868868
}
869869

@@ -1116,7 +1116,7 @@ fn show(cfg: &Cfg) -> Result<utils::ExitCode> {
11161116
}
11171117
let default_name: Result<String> = cfg
11181118
.get_default()?
1119-
.ok_or(anyhow!("no default toolchain configured"));
1119+
.ok_or_else(|| anyhow!("no default toolchain configured"));
11201120
let default_name = default_name?;
11211121
for it in installed_toolchains {
11221122
if default_name == it {

src/config.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ use crate::toolchain::{DistributableToolchain, Toolchain, UpdateStatus};
2525
use crate::utils::utils;
2626

2727
#[derive(Debug, ThisError)]
28-
enum ConfigError {
28+
enum OverrideFileConfigError {
2929
#[error("empty toolchain override file detected. Please remove it, or else specify the desired toolchain properties in the file")]
30-
EmptyOverrideFile,
30+
Empty,
3131
#[error("missing toolchain properties in toolchain override file")]
32-
InvalidOverrideFile,
32+
Invalid,
3333
#[error("error parsing override file")]
34-
ParsingOverrideFile,
34+
Parsing,
3535
}
3636

3737
#[derive(Debug, Default, Deserialize, PartialEq, Eq)]
@@ -677,22 +677,22 @@ impl Cfg {
677677
let contents = contents.as_ref();
678678

679679
match (contents.lines().count(), parse_mode) {
680-
(0, _) => Err(anyhow!(ConfigError::EmptyOverrideFile)),
680+
(0, _) => Err(anyhow!(OverrideFileConfigError::Empty)),
681681
(1, ParseMode::Both) => {
682682
let channel = contents.trim();
683683

684684
if channel.is_empty() {
685-
Err(anyhow!(ConfigError::EmptyOverrideFile))
685+
Err(anyhow!(OverrideFileConfigError::Empty))
686686
} else {
687687
Ok(channel.into())
688688
}
689689
}
690690
_ => {
691691
let override_file = toml::from_str::<OverrideFile>(contents)
692-
.context(ConfigError::ParsingOverrideFile)?;
692+
.context(OverrideFileConfigError::Parsing)?;
693693

694694
if override_file.is_empty() {
695-
Err(anyhow!(ConfigError::InvalidOverrideFile))
695+
Err(anyhow!(OverrideFileConfigError::Invalid))
696696
} else {
697697
Ok(override_file)
698698
}
@@ -1162,8 +1162,8 @@ components = [ "rustfmt" ]
11621162

11631163
let result = Cfg::parse_override_file(contents, ParseMode::Both);
11641164
assert!(matches!(
1165-
result.unwrap_err().downcast::<ConfigError>(),
1166-
Ok(ConfigError::InvalidOverrideFile)
1165+
result.unwrap_err().downcast::<OverrideFileConfigError>(),
1166+
Ok(OverrideFileConfigError::Invalid)
11671167
));
11681168
}
11691169

@@ -1173,8 +1173,8 @@ components = [ "rustfmt" ]
11731173

11741174
let result = Cfg::parse_override_file(contents, ParseMode::Both);
11751175
assert!(matches!(
1176-
result.unwrap_err().downcast::<ConfigError>(),
1177-
Ok(ConfigError::EmptyOverrideFile)
1176+
result.unwrap_err().downcast::<OverrideFileConfigError>(),
1177+
Ok(OverrideFileConfigError::Empty)
11781178
));
11791179
}
11801180

@@ -1184,8 +1184,8 @@ components = [ "rustfmt" ]
11841184

11851185
let result = Cfg::parse_override_file(contents, ParseMode::Both);
11861186
assert!(matches!(
1187-
result.unwrap_err().downcast::<ConfigError>(),
1188-
Ok(ConfigError::EmptyOverrideFile)
1187+
result.unwrap_err().downcast::<OverrideFileConfigError>(),
1188+
Ok(OverrideFileConfigError::Empty)
11891189
));
11901190
}
11911191

@@ -1197,8 +1197,8 @@ channel = nightly
11971197

11981198
let result = Cfg::parse_override_file(contents, ParseMode::Both);
11991199
assert!(matches!(
1200-
result.unwrap_err().downcast::<ConfigError>(),
1201-
Ok(ConfigError::ParsingOverrideFile)
1200+
result.unwrap_err().downcast::<OverrideFileConfigError>(),
1201+
Ok(OverrideFileConfigError::Parsing)
12021202
));
12031203
}
12041204
}

src/diskio/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn test_incremental_file(io_threads: &str) -> Result<()> {
5959
break;
6060
}
6161
}
62-
assert_eq!(true, file_finished);
62+
assert!(file_finished);
6363
for _ in io_executor.join().collect::<Vec<_>>() {
6464
// no more work should be outstanding
6565
unreachable!();

src/dist/dist.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -914,10 +914,11 @@ fn try_update_from_dist_<'a>(
914914
let mut download_not_exists = false;
915915
match &result {
916916
Ok(_) => (),
917-
Err(e) => match e.downcast_ref::<RustupError>() {
918-
Some(RustupError::DownloadNotExists { .. }) => download_not_exists = true,
919-
_ => (),
920-
},
917+
Err(e) => {
918+
if let Some(RustupError::DownloadNotExists { .. }) = e.downcast_ref::<RustupError>() {
919+
download_not_exists = true
920+
}
921+
}
921922
}
922923
if download_not_exists {
923924
result.with_context(|| {
@@ -951,14 +952,9 @@ pub fn dl_v2_manifest<'a>(
951952
Ok(Some((manifest, manifest_hash)))
952953
}
953954
Err(any) => {
954-
match any.downcast_ref::<RustupError>() {
955-
Some(e) => {
956-
// Checksum failed - issue warning to try again later
957-
if let RustupError::ChecksumFailed { .. } = e {
958-
(download.notify_handler)(Notification::ManifestChecksumFailedHack);
959-
}
960-
}
961-
None => (),
955+
if let Some(RustupError::ChecksumFailed { .. }) = any.downcast_ref::<RustupError>() {
956+
// Checksum failed - issue warning to try again later
957+
(download.notify_handler)(Notification::ManifestChecksumFailedHack);
962958
}
963959
Err(any)
964960
}

src/utils/utils.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,14 @@ pub fn filter_file<F: FnMut(&str) -> bool>(
112112
dest: &Path,
113113
filter: F,
114114
) -> Result<usize> {
115-
raw::filter_file(src, dest, filter)
116-
.with_context(|| {
117-
format!(
118-
"could not copy {} file from '{}' to '{}'",
119-
name,
120-
src.display(),
121-
dest.display()
122-
)
123-
})
124-
.into()
115+
raw::filter_file(src, dest, filter).with_context(|| {
116+
format!(
117+
"could not copy {} file from '{}' to '{}'",
118+
name,
119+
src.display(),
120+
dest.display()
121+
)
122+
})
125123
}
126124

127125
pub fn canonicalize_path<'a, N>(path: &'a Path, notify_handler: &dyn Fn(N)) -> PathBuf
@@ -366,7 +364,7 @@ where
366364
{
367365
notify_handler(Notification::RemovingDirectory(name, path).into());
368366
raw::remove_dir(path).with_context(|| RustupError::RemovingDirectory {
369-
name: name,
367+
name,
370368
path: PathBuf::from(path),
371369
})
372370
}

tests/dist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ fn make_manifest_url(dist_server: &Url, toolchain: &ToolchainDesc) -> Result<Url
478478
dist_server, toolchain.channel
479479
);
480480

481-
Ok(Url::parse(&url).map_err(|e| anyhow!(format!("{:?}", e)))?)
481+
Url::parse(&url).map_err(|e| anyhow!(format!("{:?}", e)))
482482
}
483483

484484
fn uninstall(

tests/dist_manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn parse_smoke_test() {
2626
let rust_target_pkg = rust_pkg
2727
.get_target(Some(&x86_64_unknown_linux_gnu))
2828
.unwrap();
29-
assert_eq!(rust_target_pkg.available(), true);
29+
assert!(rust_target_pkg.available());
3030
assert_eq!(rust_target_pkg.bins[0].1.url, "example.com");
3131
assert_eq!(rust_target_pkg.bins[0].1.hash, "...");
3232

0 commit comments

Comments
 (0)