Skip to content

Commit

Permalink
Merge pull request #2744 from hi-rustin/rustin-patch-clippy
Browse files Browse the repository at this point in the history
Make clippy happy
  • Loading branch information
rbtcollins authored May 1, 2021
2 parents 7a051f7 + fb88c80 commit 44be718
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 53 deletions.
7 changes: 1 addition & 6 deletions src/bin/rustup-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,7 @@ fn run_rustup_inner() -> Result<utils::ExitCode> {
}
}
Some(n) => {
if TOOLS
.iter()
.chain(DUP_TOOLS.iter())
.find(|&&name| name == n)
.is_some()
{
if TOOLS.iter().chain(DUP_TOOLS.iter()).any(|&name| name == n) {
proxy_mode::main()
} else {
Err(anyhow!(format!(
Expand Down
4 changes: 2 additions & 2 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ pub fn set_globals(verbose: bool, quiet: bool) -> Result<Cfg> {
..Default::default()
});

Ok(Cfg::from_env(Arc::new(move |n: Notification<'_>| {
Cfg::from_env(Arc::new(move |n: Notification<'_>| {
if download_tracker.borrow_mut().handle_notification(&n) {
return;
}
console_notifier.borrow_mut().handle(n);
}))?)
}))
}

pub fn show_channel_update(cfg: &Cfg, name: &str, updated: Result<UpdateStatus>) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/proxy_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ fn direct_proxy(
None => cfg.create_command_for_dir(&utils::current_dir()?, arg0)?,
Some(tc) => cfg.create_command_for_toolchain(tc, false, arg0)?,
};
Ok(run_command_for_dir(cmd, arg0, args)?)
run_command_for_dir(cmd, arg0, args)
}
4 changes: 2 additions & 2 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ fn default_(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
} else {
let default_toolchain: Result<String> = cfg
.get_default()?
.ok_or(anyhow!("no default toolchain configured"));
.ok_or_else(|| anyhow!("no default toolchain configured"));
writeln!(process().stdout(), "{} (default)", default_toolchain?)?;
}

Expand Down Expand Up @@ -1116,7 +1116,7 @@ fn show(cfg: &Cfg) -> Result<utils::ExitCode> {
}
let default_name: Result<String> = cfg
.get_default()?
.ok_or(anyhow!("no default toolchain configured"));
.ok_or_else(|| anyhow!("no default toolchain configured"));
let default_name = default_name?;
for it in installed_toolchains {
if default_name == it {
Expand Down
32 changes: 16 additions & 16 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ use crate::toolchain::{DistributableToolchain, Toolchain, UpdateStatus};
use crate::utils::utils;

#[derive(Debug, ThisError)]
enum ConfigError {
enum OverrideFileConfigError {
#[error("empty toolchain override file detected. Please remove it, or else specify the desired toolchain properties in the file")]
EmptyOverrideFile,
Empty,
#[error("missing toolchain properties in toolchain override file")]
InvalidOverrideFile,
Invalid,
#[error("error parsing override file")]
ParsingOverrideFile,
Parsing,
}

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

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

if channel.is_empty() {
Err(anyhow!(ConfigError::EmptyOverrideFile))
Err(anyhow!(OverrideFileConfigError::Empty))
} else {
Ok(channel.into())
}
}
_ => {
let override_file = toml::from_str::<OverrideFile>(contents)
.context(ConfigError::ParsingOverrideFile)?;
.context(OverrideFileConfigError::Parsing)?;

if override_file.is_empty() {
Err(anyhow!(ConfigError::InvalidOverrideFile))
Err(anyhow!(OverrideFileConfigError::Invalid))
} else {
Ok(override_file)
}
Expand Down Expand Up @@ -1162,8 +1162,8 @@ components = [ "rustfmt" ]

let result = Cfg::parse_override_file(contents, ParseMode::Both);
assert!(matches!(
result.unwrap_err().downcast::<ConfigError>(),
Ok(ConfigError::InvalidOverrideFile)
result.unwrap_err().downcast::<OverrideFileConfigError>(),
Ok(OverrideFileConfigError::Invalid)
));
}

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

let result = Cfg::parse_override_file(contents, ParseMode::Both);
assert!(matches!(
result.unwrap_err().downcast::<ConfigError>(),
Ok(ConfigError::EmptyOverrideFile)
result.unwrap_err().downcast::<OverrideFileConfigError>(),
Ok(OverrideFileConfigError::Empty)
));
}

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

let result = Cfg::parse_override_file(contents, ParseMode::Both);
assert!(matches!(
result.unwrap_err().downcast::<ConfigError>(),
Ok(ConfigError::EmptyOverrideFile)
result.unwrap_err().downcast::<OverrideFileConfigError>(),
Ok(OverrideFileConfigError::Empty)
));
}

Expand All @@ -1197,8 +1197,8 @@ channel = nightly

let result = Cfg::parse_override_file(contents, ParseMode::Both);
assert!(matches!(
result.unwrap_err().downcast::<ConfigError>(),
Ok(ConfigError::ParsingOverrideFile)
result.unwrap_err().downcast::<OverrideFileConfigError>(),
Ok(OverrideFileConfigError::Parsing)
));
}
}
2 changes: 1 addition & 1 deletion src/diskio/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn test_incremental_file(io_threads: &str) -> Result<()> {
break;
}
}
assert_eq!(true, file_finished);
assert!(file_finished);
for _ in io_executor.join().collect::<Vec<_>>() {
// no more work should be outstanding
unreachable!();
Expand Down
20 changes: 8 additions & 12 deletions src/dist/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,10 +914,11 @@ fn try_update_from_dist_<'a>(
let mut download_not_exists = false;
match &result {
Ok(_) => (),
Err(e) => match e.downcast_ref::<RustupError>() {
Some(RustupError::DownloadNotExists { .. }) => download_not_exists = true,
_ => (),
},
Err(e) => {
if let Some(RustupError::DownloadNotExists { .. }) = e.downcast_ref::<RustupError>() {
download_not_exists = true
}
}
}
if download_not_exists {
result.with_context(|| {
Expand Down Expand Up @@ -951,14 +952,9 @@ pub fn dl_v2_manifest<'a>(
Ok(Some((manifest, manifest_hash)))
}
Err(any) => {
match any.downcast_ref::<RustupError>() {
Some(e) => {
// Checksum failed - issue warning to try again later
if let RustupError::ChecksumFailed { .. } = e {
(download.notify_handler)(Notification::ManifestChecksumFailedHack);
}
}
None => (),
if let Some(RustupError::ChecksumFailed { .. }) = any.downcast_ref::<RustupError>() {
// Checksum failed - issue warning to try again later
(download.notify_handler)(Notification::ManifestChecksumFailedHack);
}
Err(any)
}
Expand Down
20 changes: 9 additions & 11 deletions src/utils/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,14 @@ pub fn filter_file<F: FnMut(&str) -> bool>(
dest: &Path,
filter: F,
) -> Result<usize> {
raw::filter_file(src, dest, filter)
.with_context(|| {
format!(
"could not copy {} file from '{}' to '{}'",
name,
src.display(),
dest.display()
)
})
.into()
raw::filter_file(src, dest, filter).with_context(|| {
format!(
"could not copy {} file from '{}' to '{}'",
name,
src.display(),
dest.display()
)
})
}

pub fn canonicalize_path<'a, N>(path: &'a Path, notify_handler: &dyn Fn(N)) -> PathBuf
Expand Down Expand Up @@ -366,7 +364,7 @@ where
{
notify_handler(Notification::RemovingDirectory(name, path).into());
raw::remove_dir(path).with_context(|| RustupError::RemovingDirectory {
name: name,
name,
path: PathBuf::from(path),
})
}
Expand Down
2 changes: 1 addition & 1 deletion tests/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ fn make_manifest_url(dist_server: &Url, toolchain: &ToolchainDesc) -> Result<Url
dist_server, toolchain.channel
);

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

fn uninstall(
Expand Down
2 changes: 1 addition & 1 deletion tests/dist_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn parse_smoke_test() {
let rust_target_pkg = rust_pkg
.get_target(Some(&x86_64_unknown_linux_gnu))
.unwrap();
assert_eq!(rust_target_pkg.available(), true);
assert!(rust_target_pkg.available());
assert_eq!(rust_target_pkg.bins[0].1.url, "example.com");
assert_eq!(rust_target_pkg.bins[0].1.hash, "...");

Expand Down

0 comments on commit 44be718

Please sign in to comment.